3 #include "gdcmCommon.h"
4 #include "gdcmDictEntry.h"
6 #include "gdcmDictSet.h"
7 #include "gdcmElValue.h"
8 #include "gdcmElValSet.h"
10 #include "gdcmHeader.h"
14 // Utility functions on strings for removing leading and trailing spaces
15 void EatLeadingAndTrailingSpaces(string & s) {
16 while ( s.length() && (s[0] == ' ') )
18 while ( s.length() && (s[s.length()-1] == ' ') )
19 s.erase(s.length()-1, 1);
22 typedef unsigned short guint16;
23 typedef unsigned int guint32;
25 ////////////////////////////////////////////////////////////////////////////
26 // Global variables get exported to cvar in Python
28 extern gdcmGlobal gdcmGlob;
31 ////////////////////////////////////////////////////////////////////////////
32 %typemap(out) std::list<std::string> * {
33 PyObject* NewItem = (PyObject*)0;
34 PyObject* NewList = PyList_New(0); // The result of this typemap
35 for (list<string>::iterator NewString = ($1)->begin();
36 NewString != ($1)->end(); ++NewString) {
37 NewItem = PyString_FromString(NewString->c_str());
38 PyList_Append( NewList, NewItem);
43 ////////////////////////////////////////////////////////////////////////////
44 // Convert a c++ hash table in a python native dictionary
45 %typemap(out) std::map<std::string, std::list<std::string> > * {
46 PyObject* NewDict = PyDict_New(); // The result of this typemap
47 PyObject* NewKey = (PyObject*)0;
48 PyObject* NewVal = (PyObject*)0;
50 for (map<string, list<string> >::iterator tag = ($1)->begin();
51 tag != ($1)->end(); ++tag) {
52 string first = tag->first;
53 // Do not publish entries whose keys is made of spaces
54 if (first.length() == 0)
56 NewKey = PyString_FromString(first.c_str());
57 PyObject* NewList = PyList_New(0);
58 for (list<string>::iterator Item = tag->second.begin();
59 Item != tag->second.end(); ++Item) {
60 NewVal = PyString_FromString(Item->c_str());
61 PyList_Append( NewList, NewVal);
63 PyDict_SetItem( NewDict, NewKey, NewList);
68 ////////////////////////////////////////////////////////////////////////////
69 // Convert a c++ hash table in a python native dictionary
70 %typemap(out) TagElValueHT & {
71 PyObject* NewDict = PyDict_New(); // The result of this typemap
72 string RawName; // Element name as gotten from gdcm
73 PyObject* NewKey = (PyObject*)0; // Associated name as python object
74 string RawValue; // Element value as gotten from gdcm
75 PyObject* NewVal = (PyObject*)0; // Associated value as python object
77 for (TagElValueHT::iterator tag = $1->begin(); tag != $1->end(); ++tag) {
79 // The element name shall be the key:
80 RawName = tag->second->GetName();
81 // gdcm unrecognized (including not loaded because their size exceeds
82 // the user specified treshold) elements are exported with their
84 if (RawName == "Unknown")
85 RawName = tag->second->GetKey();
86 NewKey = PyString_FromString(RawName.c_str());
88 // Element values are striped from leading/trailing spaces
89 RawValue = tag->second->GetValue();
90 EatLeadingAndTrailingSpaces(RawValue);
91 NewVal = PyString_FromString(RawValue.c_str());
93 PyDict_SetItem( NewDict, NewKey, NewVal);
98 ////////////////////////////////////////////////////////////////////////////
99 // Deals with function returning a C++ string.
100 %typemap(out) string {
101 $result = PyString_FromString(($1).c_str());
103 %typemap(out) std::string {
104 $result = PyString_FromString(($1).c_str());
107 ////////////////////////////////////////////////////////////////////////////
108 %include "gdcmCommon.h"
109 %include "gdcmDictEntry.h"
110 %include "gdcmDict.h"
111 %include "gdcmDictSet.h"
112 %include "gdcmElValue.h"
113 %include "gdcmElValSet.h"
114 %include "gdcmUtil.h"
115 %include "gdcmHeader.h"
116 %include "gdcmFile.h"