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 * \ingroup gdcmDicomDirElement
25 * \brief Class for the chained lists from the file 'Dicts/DicomDir.dic'
28 //-----------------------------------------------------------------------------
29 // Constructor / Destructor
32 * \ingroup gdcmDicomDirElement
33 * \brief constructor : populates the chained lists
34 * from the file 'Dicts/DicomDir.dic'
36 gdcmDicomDirElement::gdcmDicomDirElement(void) {
37 std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_ELEM);
38 std::ifstream from(filename.c_str());
39 dbg.Error(!from, "gdcmDicomDirElement::gdcmDicomDirElement: can't open dictionary",filename.c_str());
47 from.getline(buff, 1024, ' ');
50 if( (type=="metaElem") || (type=="patientElem") ||
51 (type=="studyElem") || (type=="serieElem") ||
54 from >> std::hex >> elem.group >> elem.elem;
57 from.getline(buff, 1024, '"');
59 from.getline(buff, 1024, '"');
63 DicomDirMetaList.push_back(elem);
64 else if(type=="patientElem")
65 DicomDirPatientList.push_back(elem);
66 else if(type=="studyElem")
67 DicomDirStudyList.push_back(elem);
68 else if(type=="serieElem")
69 DicomDirSerieList.push_back(elem);
70 else if(type=="imageElem")
71 DicomDirImageList.push_back(elem);
73 from.getline(buff, 1024, '\n');
79 * \ingroup gdcmDicomDirElement
80 * \brief canonical destructor
82 gdcmDicomDirElement::~gdcmDicomDirElement() {
83 DicomDirMetaList.clear();
84 DicomDirPatientList.clear();
85 DicomDirStudyList.clear();
86 DicomDirSerieList.clear();
87 DicomDirImageList.clear();
90 //-----------------------------------------------------------------------------
93 * \ingroup gdcmDicomDirElement
95 * \todo add a 'Print Level' check
96 * @param os The output stream to be written to.
98 void gdcmDicomDirElement::Print(std::ostream &os) {
100 std::list<gdcmElement>::iterator it;
101 char greltag[10]; //group element tag
103 s << "Meta Elements :"<<std::endl;
104 for (it = DicomDirMetaList.begin();it!=DicomDirMetaList.end();++it)
106 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
107 s << " ("<<greltag<<") = "<< it->value<<std::endl;
110 s << "Patient Elements :"<<std::endl;
111 for (it = DicomDirPatientList.begin();it!=DicomDirPatientList.end();++it)
113 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
114 s << " ("<<greltag<<") = "<< it->value<<std::endl;
117 s << "Study Elements :"<<std::endl;
118 for (it = DicomDirStudyList.begin();it!=DicomDirStudyList.end();++it)
120 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
121 s << " ("<<greltag<<") = "<< it->value<<std::endl;
124 s << "Serie Elements :"<<std::endl;
125 for (it = DicomDirSerieList.begin();it!=DicomDirSerieList.end();++it)
127 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
128 s << " ("<<greltag<<") = "<< it->value<<std::endl;
131 s << "Image Elements :"<<std::endl;
132 for (it = DicomDirImageList.begin();it!=DicomDirImageList.end();++it)
134 sprintf(greltag,"%04x|%04x ",it->group,it->elem);
135 s << " ("<<greltag<<") = "<< it->value<<std::endl;
141 //-----------------------------------------------------------------------------
144 //-----------------------------------------------------------------------------
147 //-----------------------------------------------------------------------------
150 //-----------------------------------------------------------------------------