3 #include "gdcmCommon.h"
4 #include "gdcmDictEntry.h"
6 #include "gdcmDictSet.h"
7 #include "gdcmElValue.h"
8 #include "gdcmElValSet.h"
9 #include "gdcmHeader.h"
12 // Utility functions on strings for removing leading and trailing spaces
13 void EatLeadingAndTrailingSpaces(string & s) {
14 while ( s.length() && (s[0] == ' ') )
16 while ( s.length() && (s[s.length()-1] == ' ') )
17 s.erase(s.length()-1, 1);
20 typedef unsigned short guint16;
21 typedef unsigned int guint32;
23 ////////////////////////////////////////////////////////////////////////////
24 %typemap(out) list<string> * {
25 PyObject* NewItem = (PyObject*)0;
26 PyObject* NewList = PyList_New(0); // The result of this typemap
27 for (list<string>::iterator NewString = ($1)->begin();
28 NewString != ($1)->end(); ++NewString) {
29 NewItem = PyString_FromString(NewString->c_str());
30 PyList_Append( NewList, NewItem);
35 ////////////////////////////////////////////////////////////////////////////
36 // Convert a c++ hash table in a python native dictionary
37 %typemap(out) map<string, list<string> > * {
38 PyObject* NewDict = PyDict_New(); // The result of this typemap
39 PyObject* NewKey = (PyObject*)0;
40 PyObject* NewVal = (PyObject*)0;
42 for (map<string, list<string> >::iterator tag = ($1)->begin();
43 tag != ($1)->end(); ++tag) {
44 string first = tag->first;
45 // Do not publish entries whose keys is made of spaces
46 if (first.length() == 0)
48 NewKey = PyString_FromString(first.c_str());
49 PyObject* NewList = PyList_New(0);
50 for (list<string>::iterator Item = tag->second.begin();
51 Item != tag->second.end(); ++Item) {
52 NewVal = PyString_FromString(Item->c_str());
53 PyList_Append( NewList, NewVal);
55 PyDict_SetItem( NewDict, NewKey, NewList);
60 ////////////////////////////////////////////////////////////////////////////
61 // Convert a c++ hash table in a python native dictionary
62 %typemap(out) TagElValueHT & {
63 PyObject* NewDict = PyDict_New(); // The result of this typemap
64 string RawName; // Element name as gotten from gdcm
65 PyObject* NewKey = (PyObject*)0; // Associated name as python object
66 string RawValue; // Element value as gotten from gdcm
67 PyObject* NewVal = (PyObject*)0; // Associated value as python object
69 for (TagElValueHT::iterator tag = $1->begin(); tag != $1->end(); ++tag) {
71 // The element name shall be the key:
72 RawName = tag->second->GetName();
73 // gdcm unrecognized (including not loaded because their size exceeds
74 // the user specified treshold) elements are exported with their
76 if (RawName == "Unknown")
77 RawName = tag->second->GetKey();
78 NewKey = PyString_FromString(RawName.c_str());
80 // Element values are striped from leading/trailing spaces
81 RawValue = tag->second->GetValue();
82 EatLeadingAndTrailingSpaces(RawValue);
83 NewVal = PyString_FromString(RawValue.c_str());
85 PyDict_SetItem( NewDict, NewKey, NewVal);
90 ////////////////////////////////////////////////////////////////////////////
91 // Deals with function returning a C++ string.
92 %typemap(out) string {
93 $result = PyString_FromString(($1).c_str());
96 ////////////////////////////////////////////////////////////////////////////
97 %include "gdcmCommon.h"
98 %include "gdcmDictEntry.h"
100 %include "gdcmDictSet.h"
101 %include "gdcmElValue.h"
102 %include "gdcmElValSet.h"
103 %include "gdcmHeader.h"
104 %include "gdcmFile.h"