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
29 gdcmDicomDirElement::gdcmDicomDirElement(void) {
30 std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_ELEM);
31 std::ifstream from(filename.c_str());
32 dbg.Error(!from, "gdcmDicomDirElement::gdcmDicomDirElement: can't open dictionary",filename.c_str());
40 from.getline(buff, 1024, ' ');
43 if( (type=="metaElem") || (type=="patientElem") ||
44 (type=="studyElem") || (type=="serieElem") ||
47 from >> std::hex >> elem.group >> elem.elem;
50 from.getline(buff, 1024, '"');
52 from.getline(buff, 1024, '"');
56 DicomDirMetaList.push_back(elem);
57 else if(type=="patientElem")
58 DicomDirPatientList.push_back(elem);
59 else if(type=="studyElem")
60 DicomDirStudyList.push_back(elem);
61 else if(type=="serieElem")
62 DicomDirSerieList.push_back(elem);
63 else if(type=="imageElem")
64 DicomDirImageList.push_back(elem);
66 from.getline(buff, 1024, '\n');
72 * \ingroup gdcmDicomDirElement
75 gdcmDicomDirElement::~gdcmDicomDirElement() {
76 DicomDirMetaList.clear();
77 DicomDirPatientList.clear();
78 DicomDirStudyList.clear();
79 DicomDirSerieList.clear();
80 DicomDirImageList.clear();
83 //-----------------------------------------------------------------------------
86 * \ingroup gdcmDicomDirElement
88 * \todo add a 'Print Level' check
89 * @param os The output stream to be written to.
91 void gdcmDicomDirElement::Print(std::ostream &os) {
93 std::list<gdcmElement>::iterator it;
94 char greltag[10]; //group element tag
96 s << "Meta Elements :"<<std::endl;
97 for (it = DicomDirMetaList.begin();it!=DicomDirMetaList.end();++it)
99 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
100 s << " ("<<greltag<<") = "<< it->value<<std::endl;
103 s << "Patient Elements :"<<std::endl;
104 for (it = DicomDirPatientList.begin();it!=DicomDirPatientList.end();++it)
106 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
107 s << " ("<<greltag<<") = "<< it->value<<std::endl;
110 s << "Study Elements :"<<std::endl;
111 for (it = DicomDirStudyList.begin();it!=DicomDirStudyList.end();++it)
113 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
114 s << " ("<<greltag<<") = "<< it->value<<std::endl;
117 s << "Serie Elements :"<<std::endl;
118 for (it = DicomDirSerieList.begin();it!=DicomDirSerieList.end();++it)
120 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
121 s << " ("<<greltag<<") = "<< it->value<<std::endl;
124 s << "Image Elements :"<<std::endl;
125 for (it = DicomDirImageList.begin();it!=DicomDirImageList.end();++it)
127 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
128 s << " ("<<greltag<<") = "<< it->value<<std::endl;
134 //-----------------------------------------------------------------------------
137 //-----------------------------------------------------------------------------
140 //-----------------------------------------------------------------------------
143 //-----------------------------------------------------------------------------