1 // gdcmDicomDirElement.cxx
2 //-----------------------------------------------------------------------------
4 #include <stdio.h> // For sprintf
7 #include "gdcmDicomDirElement.h"
10 #include "gdcmDictSet.h"
14 * \ingroup gdcmDicomDirElement
15 * \brief Class for the chained lists from the file 'Dicts/DicomDir.dic'
18 //-----------------------------------------------------------------------------
19 // Constructor / Destructor
22 * \ingroup gdcmDicomDirElement
23 * \brief constructor : populates the chained lists
24 * from the file 'Dicts/DicomDir.dic'
26 gdcmDicomDirElement::gdcmDicomDirElement(void) {
27 std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_ELEM);
28 std::ifstream from(filename.c_str());
29 dbg.Error(!from, "gdcmDicomDirElement::gdcmDicomDirElement: can't open dictionary",filename.c_str());
37 from.getline(buff, 1024, ' ');
40 if( (type=="metaElem") || (type=="patientElem") ||
41 (type=="studyElem") || (type=="serieElem") ||
44 from >> std::hex >> elem.group >> elem.elem;
47 from.getline(buff, 1024, '"');
49 from.getline(buff, 1024, '"');
53 DicomDirMetaList.push_back(elem);
54 else if(type=="patientElem")
55 DicomDirPatientList.push_back(elem);
56 else if(type=="studyElem")
57 DicomDirStudyList.push_back(elem);
58 else if(type=="serieElem")
59 DicomDirSerieList.push_back(elem);
60 else if(type=="imageElem")
61 DicomDirImageList.push_back(elem);
63 from.getline(buff, 1024, '\n');
69 * \ingroup gdcmDicomDirElement
70 * \brief canonical destructor
72 gdcmDicomDirElement::~gdcmDicomDirElement() {
73 DicomDirMetaList.clear();
74 DicomDirPatientList.clear();
75 DicomDirStudyList.clear();
76 DicomDirSerieList.clear();
77 DicomDirImageList.clear();
80 //-----------------------------------------------------------------------------
83 * \ingroup gdcmDicomDirElement
85 * \todo add a 'Print Level' check
86 * @param os The output stream to be written to.
88 void gdcmDicomDirElement::Print(std::ostream &os) {
90 std::list<gdcmElement>::iterator it;
91 char greltag[10]; //group element tag
93 s << "Meta Elements :"<<std::endl;
94 for (it = DicomDirMetaList.begin();it!=DicomDirMetaList.end();++it)
96 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
97 s << " ("<<greltag<<") = "<< it->value<<std::endl;
100 s << "Patient Elements :"<<std::endl;
101 for (it = DicomDirPatientList.begin();it!=DicomDirPatientList.end();++it)
103 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
104 s << " ("<<greltag<<") = "<< it->value<<std::endl;
107 s << "Study Elements :"<<std::endl;
108 for (it = DicomDirStudyList.begin();it!=DicomDirStudyList.end();++it)
110 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
111 s << " ("<<greltag<<") = "<< it->value<<std::endl;
114 s << "Serie Elements :"<<std::endl;
115 for (it = DicomDirSerieList.begin();it!=DicomDirSerieList.end();++it)
117 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
118 s << " ("<<greltag<<") = "<< it->value<<std::endl;
121 s << "Image Elements :"<<std::endl;
122 for (it = DicomDirImageList.begin();it!=DicomDirImageList.end();++it)
124 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
125 s << " ("<<greltag<<") = "<< it->value<<std::endl;
131 //-----------------------------------------------------------------------------
134 //-----------------------------------------------------------------------------
137 //-----------------------------------------------------------------------------
140 //-----------------------------------------------------------------------------