1 // gdcmDicomDirElement.cxx
2 //-----------------------------------------------------------------------------
4 #include <stdio.h> // For sprintf
6 #include "gdcmDicomDirElement.h"
10 # define PUB_DICT_PATH "../Dicts/"
12 #define DICT_ELEM "DicomDir.dic"
15 #ifdef GDCM_NO_ANSI_STRING_STREAM
17 # define ostringstream ostrstream
22 //-----------------------------------------------------------------------------
23 // Constructor / Destructor
26 * \ingroup gdcmDicomDirElement
27 * \brief constructor : populates the chained lists
28 * from the file 'Dicts/DicomDir.dic'
30 gdcmDicomDirElement::gdcmDicomDirElement(void) {
31 std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_ELEM);
32 std::ifstream from(filename.c_str());
33 dbg.Error(!from, "gdcmDicomDirElement::gdcmDicomDirElement: can't open dictionary",filename.c_str());
41 from.getline(buff, 1024, ' ');
44 if( (type=="metaElem") || (type=="patientElem") ||
45 (type=="studyElem") || (type=="serieElem") ||
48 from >> std::hex >> elem.group >> elem.elem;
51 from.getline(buff, 1024, '"');
53 from.getline(buff, 1024, '"');
57 DicomDirMetaList.push_back(elem);
58 else if(type=="patientElem")
59 DicomDirPatientList.push_back(elem);
60 else if(type=="studyElem")
61 DicomDirStudyList.push_back(elem);
62 else if(type=="serieElem")
63 DicomDirSerieList.push_back(elem);
64 else if(type=="imageElem")
65 DicomDirImageList.push_back(elem);
67 from.getline(buff, 1024, '\n');
73 * \ingroup gdcmDicomDirElement
76 gdcmDicomDirElement::~gdcmDicomDirElement() {
77 DicomDirMetaList.clear();
78 DicomDirPatientList.clear();
79 DicomDirStudyList.clear();
80 DicomDirSerieList.clear();
81 DicomDirImageList.clear();
84 //-----------------------------------------------------------------------------
87 * \ingroup gdcmDicomDirElement
89 * \todo add a 'Print Level' check
90 * @param os The output stream to be written to.
92 void gdcmDicomDirElement::Print(std::ostream &os) {
94 std::list<gdcmElement>::iterator it;
95 char greltag[10]; //group element tag
97 s << "Meta Elements :"<<std::endl;
98 for (it = DicomDirMetaList.begin();it!=DicomDirMetaList.end();++it)
100 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
101 s << " ("<<greltag<<") = "<< it->value<<std::endl;
104 s << "Patient Elements :"<<std::endl;
105 for (it = DicomDirPatientList.begin();it!=DicomDirPatientList.end();++it)
107 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
108 s << " ("<<greltag<<") = "<< it->value<<std::endl;
111 s << "Study Elements :"<<std::endl;
112 for (it = DicomDirStudyList.begin();it!=DicomDirStudyList.end();++it)
114 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
115 s << " ("<<greltag<<") = "<< it->value<<std::endl;
118 s << "Serie Elements :"<<std::endl;
119 for (it = DicomDirSerieList.begin();it!=DicomDirSerieList.end();++it)
121 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
122 s << " ("<<greltag<<") = "<< it->value<<std::endl;
125 s << "Image Elements :"<<std::endl;
126 for (it = DicomDirImageList.begin();it!=DicomDirImageList.end();++it)
128 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
129 s << " ("<<greltag<<") = "<< it->value<<std::endl;
135 //-----------------------------------------------------------------------------
138 //-----------------------------------------------------------------------------
141 //-----------------------------------------------------------------------------
144 //-----------------------------------------------------------------------------