3 #include "gdcmCommon.h"
4 #include "gdcmDictEntry.h"
6 #include "gdcmDictSet.h"
7 #include "gdcmElValue.h"
8 #include "gdcmElValSet.h"
9 #include "gdcmHeader.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 %typemap(out) list<string> * {
28 PyObject* NewItem = (PyObject*)0;
29 PyObject* NewList = PyList_New(0); // The result of this typemap
30 for (list<string>::iterator NewString = ($1)->begin();
31 NewString != ($1)->end(); ++NewString) {
32 NewItem = PyString_FromString(NewString->c_str());
33 PyList_Append( NewList, NewItem);
38 ////////////////////////////////////////////////////////////////////////////
39 // Convert a c++ hash table in a python native dictionary
40 %typemap(out) map<string, list<string> > * {
41 PyObject* NewDict = PyDict_New(); // The result of this typemap
42 PyObject* NewKey = (PyObject*)0;
43 PyObject* NewVal = (PyObject*)0;
45 for (map<string, list<string> >::iterator tag = ($1)->begin();
46 tag != ($1)->end(); ++tag) {
47 string first = tag->first;
48 // Do not publish entries whose keys is made of spaces
49 if (first.length() == 0)
51 NewKey = PyString_FromString(first.c_str());
52 PyObject* NewList = PyList_New(0);
53 for (list<string>::iterator Item = tag->second.begin();
54 Item != tag->second.end(); ++Item) {
55 NewVal = PyString_FromString(Item->c_str());
56 PyList_Append( NewList, NewVal);
58 PyDict_SetItem( NewDict, NewKey, NewList);
63 ////////////////////////////////////////////////////////////////////////////
64 // Convert a c++ hash table in a python native dictionary
65 %typemap(out) TagElValueHT & {
66 PyObject* NewDict = PyDict_New(); // The result of this typemap
67 string RawName; // Element name as gotten from gdcm
68 PyObject* NewKey = (PyObject*)0; // Associated name as python object
69 string RawValue; // Element value as gotten from gdcm
70 PyObject* NewVal = (PyObject*)0; // Associated value as python object
72 for (TagElValueHT::iterator tag = $1->begin(); tag != $1->end(); ++tag) {
74 // The element name shall be the key:
75 RawName = tag->second->GetName();
76 // gdcm unrecognized (including not loaded because their size exceeds
77 // the user specified treshold) elements are exported with their
79 if (RawName == "Unknown")
80 RawName = tag->second->GetKey();
81 NewKey = PyString_FromString(RawName.c_str());
83 // Element values are striped from leading/trailing spaces
84 RawValue = tag->second->GetValue();
85 EatLeadingAndTrailingSpaces(RawValue);
86 NewVal = PyString_FromString(RawValue.c_str());
88 PyDict_SetItem( NewDict, NewKey, NewVal);
93 ////////////////////////////////////////////////////////////////////////////
94 // Deals with function returning a C++ string.
95 %typemap(out) string {
96 $result = PyString_FromString(($1).c_str());
98 %typemap(out) std::string {
99 $result = PyString_FromString(($1).c_str());
101 //////%apply int { std::int };
103 ////////////////////////////////////////////////////////////////////////////
104 %include "gdcmCommon.h"
105 %include "gdcmDictEntry.h"
106 %include "gdcmDict.h"
107 %include "gdcmDictSet.h"
108 %include "gdcmElValue.h"
109 %include "gdcmElValSet.h"
110 %include "gdcmHeader.h"
111 %include "gdcmFile.h"