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