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 %typemap(out) list<string> * {
24 PyObject* NewItem = (PyObject*)0;
25 PyObject* NewList = PyList_New(0); // The result of this typemap
26 for (list<string>::iterator NewString = ($1)->begin();
27 NewString != ($1)->end(); ++NewString) {
28 NewItem = PyString_FromString(NewString->c_str());
29 PyList_Append( NewList, NewItem);
34 // Convert a c++ hash table in a python native dictionary
35 %typemap(out) map<string, list<string> > * {
36 PyObject* NewDict = PyDict_New(); // The result of this typemap
37 PyObject* NewKey = (PyObject*)0;
38 PyObject* NewVal = (PyObject*)0;
40 for (map<string, list<string> >::iterator tag = ($1)->begin();
41 tag != ($1)->end(); ++tag) {
42 string first = tag->first;
43 // Do not publish entries whose keys is made of spaces
44 if (first.length() == 0)
46 NewKey = PyString_FromString(first.c_str());
47 PyObject* NewList = PyList_New(0);
48 for (list<string>::iterator Item = tag->second.begin();
49 Item != tag->second.end(); ++Item) {
50 NewVal = PyString_FromString(Item->c_str());
51 PyList_Append( NewList, NewVal);
53 PyDict_SetItem( NewDict, NewKey, NewList);
58 // Convert a c++ hash table in a python native dictionary
59 %typemap(out) TagElValueHT & {
60 PyObject* NewDict = PyDict_New(); // The result of this typemap
61 string RawName; // Element name as gotten from gdcm
62 PyObject* NewKey = (PyObject*)0; // Associated name as python object
63 string RawValue; // Element value as gotten from gdcm
64 PyObject* NewVal = (PyObject*)0; // Associated value as python object
66 for (TagElValueHT::iterator tag = $1->begin(); tag != $1->end(); ++tag) {
68 // The element name shall be the key:
69 RawName = tag->second->GetName();
70 // gdcm unrecognized (including not loaded because their size exceeds
71 // the user specified treshold) elements are exported with their
73 if (RawName == "Unknown")
74 RawName = tag->second->GetKey();
75 NewKey = PyString_FromString(RawName.c_str());
77 // Element values are striped from leading/trailing spaces
78 RawValue = tag->second->GetValue();
79 EatLeadingAndTrailingSpaces(RawValue);
80 NewVal = PyString_FromString(RawValue.c_str());
82 PyDict_SetItem( NewDict, NewKey, NewVal);
87 %include "gdcmCommon.h"
88 %include "gdcmDictEntry.h"
90 %include "gdcmDictSet.h"
91 %include "gdcmElValue.h"
92 %include "gdcmElValSet.h"
93 %include "gdcmHeader.h"