]> Creatis software - gdcm.git/blob - src/gdcmVR.cxx
ENH: Adding 'gdcm' namespace. Be nice with me this was a ~13000 lines patch. Also...
[gdcm.git] / src / gdcmVR.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmVR.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/10/12 04:35:48 $
7   Version:   $Revision: 1.19 $
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.html 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 "gdcmVR.h"
20 #include "gdcmUtil.h"
21 #include "gdcmDictSet.h"
22 #include "gdcmDebug.h"
23
24 #include <fstream>
25 #include <iostream>
26
27 namespace gdcm 
28 {
29
30 //-----------------------------------------------------------------------------
31 /**
32  * \brief Constructor
33  */
34 VR::VR() 
35 {
36    std::string filename=DictSet::BuildDictPath() + std::string(DICT_VR);
37    std::ifstream from(filename.c_str());
38    dbg.Error(!from, "VR::VR: can't open dictionary",filename.c_str());
39
40    char buff[1024];
41    std::string key;
42    std::string name;
43
44    while (!from.eof()) 
45    {
46       from >> std::ws; // used to be eatwhite(from);
47       from.getline(buff, 1024, ' ');
48       key = buff;
49       from >> std::ws; // used to be eatwhite(from);
50       from.getline(buff, 1024, ';');
51       name = buff;
52
53       from >> std::ws; // used to be eatwhite(from);
54       from.getline(buff, 1024, '\n');
55
56       if(key!="")
57       {
58          vr[key]=name;
59       }
60    }
61    from.close();
62 }
63
64 //-----------------------------------------------------------------------------
65 /**
66  * \brief Destructor
67  */
68 VR::~VR()
69 {
70    vr.clear();
71 }
72
73 //-----------------------------------------------------------------------------
74 // Print
75 /**
76  * \brief   Print all 
77  * @param   os The output stream to be written to.
78  */
79 void VR::Print(std::ostream &os) 
80 {
81    std::ostringstream s;
82
83    for (VRHT::iterator it = vr.begin(); it != vr.end(); ++it)
84    {
85       s << "VR : "<<it->first<<" = "<<it->second<<std::endl;
86    }
87    os << s.str();
88 }
89
90 //-----------------------------------------------------------------------------
91 // Public
92 /**
93  * \brief   Get the count for an element
94  * @param   key key to count
95  */
96 int VR::Count(VRKey key) 
97 {
98    return vr.count(key);
99 }
100
101 //-----------------------------------------------------------------------------
102 /**
103  * \brief   Simple predicate that checks wether the given argument
104  *          corresponds to the Value Representation of a \ref BinEntry .
105  *          This predicate is the negation of
106  *          \ref VR::IsVROfGdcmStringRepresentable .
107  * @param   tested value representation to check for.
108  */
109 bool VR::IsVROfGdcmBinaryRepresentable(VRKey tested)
110 {
111    //std::cout << "VR::IsVROfGdcmBinaryRepresentable===================="
112    //   << tested << std::endl;
113
114    if ( tested == "unkn")
115       return true;
116
117    if ( ! Count(tested) )
118    {
119       dbg.Verbose(0, "VR::IsVROfGdcmBinaryRepresentable: tested not a VR!");
120       return false;
121    }
122
123    if ( IsVROfGdcmStringRepresentable(tested) )
124    {
125       dbg.Verbose(0, "VR::IsVROfGdcmBinaryRepresentable: binary VR !");
126       return false;
127    }
128
129    return true;
130 }
131
132 //-----------------------------------------------------------------------------
133 /**
134  * \brief   Simple predicate that checks wether the given argument
135  *          corresponds to the Value Representation of a \ref ValEntry
136  *          but NOT a \ref BinEntry.
137  * @param   tested value representation to check for.
138  */
139 bool VR::IsVROfGdcmStringRepresentable(VRKey tested)
140 {
141
142    if ( ! Count(tested) )
143    {
144       dbg.Verbose(0, "VR::IsVROfGdcmStringRepresentable: tested not a VR!");
145       return false;
146    }
147
148    if (tested == "AE" || tested == "AS" || tested == "DA" || tested == "PN" ||
149        tested == "UI" || tested == "TM" || tested == "SH" || tested == "LO" ||
150        tested == "CS" || tested == "IS" || tested == "LO" || tested == "LT" ||
151        tested == "SH" || tested == "ST" || tested == "DS" || tested == "SL" ||
152        tested == "SS" || tested == "UL" || tested == "US" || tested == "UN")
153    {
154       return true;
155    }
156    return false;
157 }
158
159 //-----------------------------------------------------------------------------
160 // Protected
161
162 //-----------------------------------------------------------------------------
163 // Private
164
165 //-----------------------------------------------------------------------------
166
167 } // end namespace gdcm