1 // gdcmDicomDirElement.cxx
2 //-----------------------------------------------------------------------------
4 #include <stdio.h> // For sprintf
6 #ifdef GDCM_NO_ANSI_STRING_STREAM
8 # define ostringstream ostrstream
13 #include "gdcmDicomDirElement.h"
15 #include "gdcmDebug.h"
16 #include "gdcmDictSet.h"
19 # define PUB_DICT_PATH "../Dicts/"
21 #define DICT_ELEM "DicomDir.dic"
24 //-----------------------------------------------------------------------------
25 // Constructor / Destructor
28 * \ingroup gdcmDicomDirElement
29 * \brief constructor : populates the chained lists
30 * from the file 'Dicts/DicomDir.dic'
32 gdcmDicomDirElement::gdcmDicomDirElement(void) {
33 std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_ELEM);
34 std::ifstream from(filename.c_str());
35 dbg.Error(!from, "gdcmDicomDirElement::gdcmDicomDirElement: can't open dictionary",filename.c_str());
43 from.getline(buff, 1024, ' ');
46 if( (type=="metaElem") || (type=="patientElem") ||
47 (type=="studyElem") || (type=="serieElem") ||
50 from >> std::hex >> elem.group >> elem.elem;
53 from.getline(buff, 1024, '"');
55 from.getline(buff, 1024, '"');
59 DicomDirMetaList.push_back(elem);
60 else if(type=="patientElem")
61 DicomDirPatientList.push_back(elem);
62 else if(type=="studyElem")
63 DicomDirStudyList.push_back(elem);
64 else if(type=="serieElem")
65 DicomDirSerieList.push_back(elem);
66 else if(type=="imageElem")
67 DicomDirImageList.push_back(elem);
69 from.getline(buff, 1024, '\n');
75 * \ingroup gdcmDicomDirElement
76 * \brief canonical destructor
78 gdcmDicomDirElement::~gdcmDicomDirElement() {
79 DicomDirMetaList.clear();
80 DicomDirPatientList.clear();
81 DicomDirStudyList.clear();
82 DicomDirSerieList.clear();
83 DicomDirImageList.clear();
86 //-----------------------------------------------------------------------------
89 * \ingroup gdcmDicomDirElement
91 * \todo add a 'Print Level' check
92 * @param os The output stream to be written to.
94 void gdcmDicomDirElement::Print(std::ostream &os) {
96 std::list<gdcmElement>::iterator it;
97 char greltag[10]; //group element tag
99 s << "Meta Elements :"<<std::endl;
100 for (it = DicomDirMetaList.begin();it!=DicomDirMetaList.end();++it)
102 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
103 s << " ("<<greltag<<") = "<< it->value<<std::endl;
106 s << "Patient Elements :"<<std::endl;
107 for (it = DicomDirPatientList.begin();it!=DicomDirPatientList.end();++it)
109 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
110 s << " ("<<greltag<<") = "<< it->value<<std::endl;
113 s << "Study Elements :"<<std::endl;
114 for (it = DicomDirStudyList.begin();it!=DicomDirStudyList.end();++it)
116 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
117 s << " ("<<greltag<<") = "<< it->value<<std::endl;
120 s << "Serie Elements :"<<std::endl;
121 for (it = DicomDirSerieList.begin();it!=DicomDirSerieList.end();++it)
123 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
124 s << " ("<<greltag<<") = "<< it->value<<std::endl;
127 s << "Image Elements :"<<std::endl;
128 for (it = DicomDirImageList.begin();it!=DicomDirImageList.end();++it)
130 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
131 s << " ("<<greltag<<") = "<< it->value<<std::endl;
137 //-----------------------------------------------------------------------------
140 //-----------------------------------------------------------------------------
143 //-----------------------------------------------------------------------------
146 //-----------------------------------------------------------------------------