]> Creatis software - gdcm.git/blob - src/gdcmDicomDirElement.cxx
STYLE: Cleanup outside API, there is still too much offered to user
[gdcm.git] / src / gdcmDicomDirElement.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirElement.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/06/23 03:36:24 $
7   Version:   $Revision: 1.13 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.htm for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19 #include <fstream>
20 #include <stdio.h>    // For sprintf
21 #include <iostream>
22
23 #include "gdcmDicomDirElement.h"
24 #include "gdcmUtil.h"
25 #include "gdcmDebug.h"
26 #include "gdcmDictSet.h"
27
28
29 //-----------------------------------------------------------------------------
30 // Constructor / Destructor
31
32 /**
33  * \brief   constructor : populates the chained lists 
34  *          from the file 'Dicts/DicomDir.dic'
35  */
36 gdcmDicomDirElement::gdcmDicomDirElement() {
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());
40
41    char buff[1024];
42    std::string type;
43    gdcmElement elem;
44
45    while (!from.eof()) {
46       eatwhite(from);
47       from.getline(buff, 1024, ' ');
48       type = buff;
49
50       if( (type=="metaElem")  || (type=="patientElem") || 
51           (type=="studyElem") || (type=="serieElem")   || 
52           (type=="imageElem") )
53       {
54          from >> std::hex >> elem.group >> elem.elem;
55
56          eatwhite(from);
57          from.getline(buff, 1024, '"');
58          eatwhite(from);
59          from.getline(buff, 1024, '"');
60          elem.value = buff;
61
62          if(type=="metaElem")
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);
72       }
73       from.getline(buff, 1024, '\n');
74    }
75    from.close();
76 }
77
78 /**
79  * \ingroup gdcmDicomDirElement
80  * \brief   canonical destructor 
81  */
82 gdcmDicomDirElement::~gdcmDicomDirElement() {
83    DicomDirMetaList.clear();
84    DicomDirPatientList.clear();
85    DicomDirStudyList.clear();
86    DicomDirSerieList.clear();
87    DicomDirImageList.clear();
88 }
89
90 //-----------------------------------------------------------------------------
91 // Print
92 /**
93  * \ingroup gdcmDicomDirElement
94  * \brief   Print all
95  * \todo add a 'Print Level' check 
96  * @param   os The output stream to be written to.
97  */
98 void gdcmDicomDirElement::Print(std::ostream &os) {
99    std::ostringstream s;
100    std::list<gdcmElement>::iterator it;
101    char greltag[10];  //group element tag
102
103    s << "Meta Elements :"<<std::endl;
104    for (it = DicomDirMetaList.begin();it!=DicomDirMetaList.end();++it)
105    {
106       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
107       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
108    }
109
110    s << "Patient Elements :"<<std::endl;
111    for (it = DicomDirPatientList.begin();it!=DicomDirPatientList.end();++it)
112    {
113       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
114       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
115    }
116
117    s << "Study Elements :"<<std::endl;
118    for (it = DicomDirStudyList.begin();it!=DicomDirStudyList.end();++it)
119    {
120       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
121       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
122    }
123
124    s << "Serie Elements :"<<std::endl;
125    for (it = DicomDirSerieList.begin();it!=DicomDirSerieList.end();++it)
126    {
127       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
128       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
129    }
130
131    s << "Image Elements :"<<std::endl;
132    for (it = DicomDirImageList.begin();it!=DicomDirImageList.end();++it)
133    {
134       sprintf(greltag,"%04x|%04x ",it->group,it->elem);
135       s << "   ("<<greltag<<") = "<< it->value<<std::endl;
136    }
137
138    os << s.str();
139 }
140
141 //-----------------------------------------------------------------------------
142 // Public
143
144 //-----------------------------------------------------------------------------
145 // Protected
146
147 //-----------------------------------------------------------------------------
148 // Private
149
150 //-----------------------------------------------------------------------------