]> Creatis software - gdcm.git/blob - src/gdcmDicomDirElement.cxx
#include missing
[gdcm.git] / src / gdcmDicomDirElement.cxx
1 // gdcmDicomDirElement.cxx
2 //-----------------------------------------------------------------------------
3 #include <fstream>
4 #include <stdio.h>    // For sprintf
5
6 #include "gdcmDicomDirElement.h"
7 #include "gdcmUtil.h"
8
9 #ifndef PUB_DICT_PATH
10 #  define PUB_DICT_PATH     "../Dicts/"
11 #endif
12 #define DICT_ELEM "DicomDir.dic"
13
14 #include <iostream>
15 #ifdef GDCM_NO_ANSI_STRING_STREAM
16 #  include <strstream>
17 #  define  ostringstream ostrstream
18 # else
19 #  include <sstream>
20 #endif
21
22 //-----------------------------------------------------------------------------
23 // Constructor / Destructor
24 gdcmDicomDirElement::gdcmDicomDirElement(void) 
25 {
26    std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_ELEM);
27    std::ifstream from(filename.c_str());
28    dbg.Error(!from, "gdcmDicomDirElement::gdcmDicomDirElement: can't open dictionary",filename.c_str());
29
30    char buff[1024];
31    std::string type;
32    gdcmElement elem;
33
34    while (!from.eof()) {
35       eatwhite(from);
36       from.getline(buff, 1024, ' ');
37       type = buff;
38
39       if( (type=="metaElem") || (type=="patientElem") || 
40           (type=="studyElem") || (type=="serieElem") || 
41           (type=="imageElem") )
42       {
43          from >> std::hex >> elem.group >> elem.elem;
44
45          eatwhite(from);
46          from.getline(buff, 1024, '"');
47          eatwhite(from);
48          from.getline(buff, 1024, '"');
49          elem.value = buff;
50
51          if(type=="metaElem")
52             MetaList.push_back(elem);
53          else if(type=="patientElem")
54             PatientList.push_back(elem);
55          else if(type=="studyElem")
56             StudyList.push_back(elem);
57          else if(type=="serieElem")
58             SerieList.push_back(elem);
59          else if(type=="imageElem")
60             ImageList.push_back(elem);
61       }
62
63       from.getline(buff, 1024, '\n');
64    }
65    from.close();
66 }
67
68 gdcmDicomDirElement::~gdcmDicomDirElement() 
69 {
70    MetaList.clear();
71    PatientList.clear();
72    StudyList.clear();
73    SerieList.clear();
74    ImageList.clear();
75 }
76
77 //-----------------------------------------------------------------------------
78 // Print
79 /**
80  * \ingroup gdcmVR
81  * \brief   Print all 
82  * @param   os The output stream to be written to.
83  */
84 void gdcmDicomDirElement::Print(std::ostream &os) 
85 {
86    std::ostringstream s;
87    std::list<gdcmElement>::iterator it;
88    char greltag[10];  //group element tag
89
90    s << "Meta Elements :"<<std::endl;
91    for (it = MetaList.begin();it!=MetaList.end();++it)
92    {
93       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
94       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
95    }
96
97    s << "Patient Elements :"<<std::endl;
98    for (it = PatientList.begin();it!=PatientList.end();++it)
99    {
100       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
101       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
102    }
103
104    s << "Study Elements :"<<std::endl;
105    for (it = StudyList.begin();it!=StudyList.end();++it)
106    {
107       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
108       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
109    }
110
111    s << "Serie Elements :"<<std::endl;
112    for (it = SerieList.begin();it!=SerieList.end();++it)
113    {
114       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
115       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
116    }
117
118    s << "Image Elements :"<<std::endl;
119    for (it = ImageList.begin();it!=ImageList.end();++it)
120    {
121       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
122       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
123    }
124
125    os << s.str();
126 }
127
128 //-----------------------------------------------------------------------------
129 // Public
130
131 //-----------------------------------------------------------------------------
132 // Protected
133
134 //-----------------------------------------------------------------------------
135 // Private
136
137 //-----------------------------------------------------------------------------