]> Creatis software - gdcm.git/blob - src/gdcmDicomDirElement.cxx
ENH: Remove redundancie about GDCM_DICT stuff, now we only need to modify
[gdcm.git] / src / gdcmDicomDirElement.cxx
1 // gdcmDicomDirElement.cxx
2 //-----------------------------------------------------------------------------
3 #include <fstream>
4 #include <stdio.h>    // For sprintf
5 #include <iostream>
6
7 #include "gdcmDicomDirElement.h"
8 #include "gdcmUtil.h"
9 #include "gdcmDebug.h"
10 #include "gdcmDictSet.h"
11
12
13 /**
14  * \ingroup gdcmDicomDirElement
15  * \brief   Class for the chained lists from the file 'Dicts/DicomDir.dic'
16  */
17  
18 //-----------------------------------------------------------------------------
19 // Constructor / Destructor
20
21 /**
22  * \ingroup gdcmDicomDirElement
23  * \brief   constructor : populates the chained lists 
24  *          from the file 'Dicts/DicomDir.dic'
25  */
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());
30
31    char buff[1024];
32    std::string type;
33    gdcmElement elem;
34
35    while (!from.eof()) {
36       eatwhite(from);
37       from.getline(buff, 1024, ' ');
38       type = buff;
39
40       if( (type=="metaElem")  || (type=="patientElem") || 
41           (type=="studyElem") || (type=="serieElem")   || 
42           (type=="imageElem") )
43       {
44          from >> std::hex >> elem.group >> elem.elem;
45
46          eatwhite(from);
47          from.getline(buff, 1024, '"');
48          eatwhite(from);
49          from.getline(buff, 1024, '"');
50          elem.value = buff;
51
52          if(type=="metaElem")
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);
62       }
63       from.getline(buff, 1024, '\n');
64    }
65    from.close();
66 }
67
68 /**
69  * \ingroup gdcmDicomDirElement
70  * \brief   canonical destructor 
71  */
72  gdcmDicomDirElement::~gdcmDicomDirElement() {
73    DicomDirMetaList.clear();
74    DicomDirPatientList.clear();
75    DicomDirStudyList.clear();
76    DicomDirSerieList.clear();
77    DicomDirImageList.clear();
78 }
79
80 //-----------------------------------------------------------------------------
81 // Print
82 /**
83  * \ingroup gdcmDicomDirElement
84  * \brief   Print all
85  * \todo add a 'Print Level' check 
86  * @param   os The output stream to be written to.
87  */
88 void gdcmDicomDirElement::Print(std::ostream &os) {
89    std::ostringstream s;
90    std::list<gdcmElement>::iterator it;
91    char greltag[10];  //group element tag
92
93    s << "Meta Elements :"<<std::endl;
94    for (it = DicomDirMetaList.begin();it!=DicomDirMetaList.end();++it)
95    {
96       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
97       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
98    }
99
100    s << "Patient Elements :"<<std::endl;
101    for (it = DicomDirPatientList.begin();it!=DicomDirPatientList.end();++it)
102    {
103       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
104       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
105    }
106
107    s << "Study Elements :"<<std::endl;
108    for (it = DicomDirStudyList.begin();it!=DicomDirStudyList.end();++it)
109    {
110       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
111       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
112    }
113
114    s << "Serie Elements :"<<std::endl;
115    for (it = DicomDirSerieList.begin();it!=DicomDirSerieList.end();++it)
116    {
117       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
118       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
119    }
120
121    s << "Image Elements :"<<std::endl;
122    for (it = DicomDirImageList.begin();it!=DicomDirImageList.end();++it)
123    {
124       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
125       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
126    }
127
128    os << s.str();
129 }
130
131 //-----------------------------------------------------------------------------
132 // Public
133
134 //-----------------------------------------------------------------------------
135 // Protected
136
137 //-----------------------------------------------------------------------------
138 // Private
139
140 //-----------------------------------------------------------------------------