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"
18 # define PUB_DICT_PATH "../Dicts/"
20 #define DICT_ELEM "DicomDir.dic"
23 //-----------------------------------------------------------------------------
24 // Constructor / Destructor
27 * \ingroup gdcmDicomDirElement
28 * \brief constructor : populates the chained lists
29 * from the file 'Dicts/DicomDir.dic'
31 gdcmDicomDirElement::gdcmDicomDirElement(void) {
32 std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_ELEM);
33 std::ifstream from(filename.c_str());
34 dbg.Error(!from, "gdcmDicomDirElement::gdcmDicomDirElement: can't open dictionary",filename.c_str());
42 from.getline(buff, 1024, ' ');
45 if( (type=="metaElem") || (type=="patientElem") ||
46 (type=="studyElem") || (type=="serieElem") ||
49 from >> std::hex >> elem.group >> elem.elem;
52 from.getline(buff, 1024, '"');
54 from.getline(buff, 1024, '"');
58 DicomDirMetaList.push_back(elem);
59 else if(type=="patientElem")
60 DicomDirPatientList.push_back(elem);
61 else if(type=="studyElem")
62 DicomDirStudyList.push_back(elem);
63 else if(type=="serieElem")
64 DicomDirSerieList.push_back(elem);
65 else if(type=="imageElem")
66 DicomDirImageList.push_back(elem);
68 from.getline(buff, 1024, '\n');
74 * \ingroup gdcmDicomDirElement
75 * \brief canonical destructor
77 gdcmDicomDirElement::~gdcmDicomDirElement() {
78 DicomDirMetaList.clear();
79 DicomDirPatientList.clear();
80 DicomDirStudyList.clear();
81 DicomDirSerieList.clear();
82 DicomDirImageList.clear();
85 //-----------------------------------------------------------------------------
88 * \ingroup gdcmDicomDirElement
90 * \todo add a 'Print Level' check
91 * @param os The output stream to be written to.
93 void gdcmDicomDirElement::Print(std::ostream &os) {
95 std::list<gdcmElement>::iterator it;
96 char greltag[10]; //group element tag
98 s << "Meta Elements :"<<std::endl;
99 for (it = DicomDirMetaList.begin();it!=DicomDirMetaList.end();++it)
101 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
102 s << " ("<<greltag<<") = "<< it->value<<std::endl;
105 s << "Patient Elements :"<<std::endl;
106 for (it = DicomDirPatientList.begin();it!=DicomDirPatientList.end();++it)
108 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
109 s << " ("<<greltag<<") = "<< it->value<<std::endl;
112 s << "Study Elements :"<<std::endl;
113 for (it = DicomDirStudyList.begin();it!=DicomDirStudyList.end();++it)
115 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
116 s << " ("<<greltag<<") = "<< it->value<<std::endl;
119 s << "Serie Elements :"<<std::endl;
120 for (it = DicomDirSerieList.begin();it!=DicomDirSerieList.end();++it)
122 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
123 s << " ("<<greltag<<") = "<< it->value<<std::endl;
126 s << "Image Elements :"<<std::endl;
127 for (it = DicomDirImageList.begin();it!=DicomDirImageList.end();++it)
129 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
130 s << " ("<<greltag<<") = "<< it->value<<std::endl;
136 //-----------------------------------------------------------------------------
139 //-----------------------------------------------------------------------------
142 //-----------------------------------------------------------------------------
145 //-----------------------------------------------------------------------------