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