]> Creatis software - gdcm.git/blob - src/gdcmVR.cxx
Typo, comments, doxygenation
[gdcm.git] / src / gdcmVR.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmVR.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/02/11 15:22:19 $
7   Version:   $Revision: 1.36 $
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 /// \brief auto generated function, to fill up the 'Value Representation'
31 ///        Dictionnary, if relevant file is not found on user's disk
32 void FillDefaultVRDict(VRHT &vr);
33
34 //-----------------------------------------------------------------------------
35 // Constructor / Destructor
36 /**
37  * \brief Constructor
38  */
39 VR::VR() 
40 {
41    std::string filename = DictSet::BuildDictPath() + DICT_VR;
42    std::ifstream from(filename.c_str());
43    if(!from)
44    {
45       gdcmWarningMacro("Can't open dictionary" << filename.c_str());
46       FillDefaultVRDict(vr);
47    }
48    else
49    {
50       char buff[1024];
51       VRKey key;
52       VRAtr name;
53    
54       while (!from.eof()) 
55       {
56          from >> std::ws;
57          from.getline(buff, 1024, ' ');
58          key = buff;
59          from >> std::ws;
60          from.getline(buff, 1024, ';');
61          name = buff;
62    
63          from >> std::ws;
64          from.getline(buff, 1024, '\n');
65    
66          if(key != "")
67          {
68             vr[key] = name;
69          }
70       }
71       from.close();
72    }
73 }
74
75 /**
76  * \brief Destructor
77  */
78 VR::~VR()
79 {
80    vr.clear();
81 }
82
83 //-----------------------------------------------------------------------------
84 // Public
85 /**
86  * \brief   Get the count for an element
87  * @param   key key to count
88  */
89 int VR::Count(VRKey const &key) 
90 {
91    return vr.count(key);
92 }
93
94 /**
95  * \brief   Simple predicate that checks whether the given argument
96  *          corresponds to the Value Representation of a \ref BinEntry .
97  * @param   tested value representation to check for.
98  */
99 bool VR::IsVROfBinaryRepresentable(VRKey const &tested)
100 {
101    if ( tested == GDCM_UNKNOWN)
102       return true;
103
104    if ( IsVROfStringRepresentable(tested) )
105       return false;
106
107    if ( IsVROfSequence(tested) )
108       return false;
109
110    return true;
111 }
112
113 /**
114  * \brief   Simple predicate that checks whether the given argument
115  *          corresponds to the Value Representation of a \ref ValEntry
116  *          but NOT a \ref BinEntry.
117  * @param   tested value representation to be checked.
118  */
119 bool VR::IsVROfStringRepresentable(VRKey const &tested)
120 {
121    return tested == "AE" ||
122           tested == "AS" ||
123           tested == "CS" ||
124           tested == "DA" ||
125           tested == "DS" ||
126           tested == "IS" || 
127           tested == "LO" ||
128           tested == "LT" ||
129           tested == "PN" ||
130           tested == "SH" ||
131           tested == "SL" ||
132           tested == "SS" ||
133           tested == "ST" ||
134           tested == "TM" ||
135           tested == "UI" ||
136           tested == "UL" ||
137           tested == "UN" ||
138           tested == "US";
139 }
140
141 /**
142  * \brief   Simple predicate that checks whether the given argument
143  *          corresponds to the Value Representation of a \ref SeqEntry
144  * @param   tested value representation to check for.
145  */
146 bool VR::IsVROfSequence(VRKey const &tested)
147 {
148    return tested == "SQ";
149 }
150
151 bool VR::IsValidVR(VRKey const &key)
152 {
153    return vr.find(key) != vr.end();
154 }
155
156 //-----------------------------------------------------------------------------
157 // Protected
158
159 //-----------------------------------------------------------------------------
160 // Private
161
162 //-----------------------------------------------------------------------------
163 // Print
164 /**
165  * \brief   Print all 
166  * @param   os The output stream to be written to.
167  */
168 void VR::Print(std::ostream &os) 
169 {
170    std::ostringstream s;
171
172    for (VRHT::iterator it = vr.begin(); it != vr.end(); ++it)
173    {
174       s << "VR : " << it->first << " = " << it->second << std::endl;
175    }
176    os << s.str();
177 }
178
179 //-----------------------------------------------------------------------------
180 } // end namespace gdcm