]> Creatis software - gdcm.git/blob - src/gdcmVR.cxx
* Fix some compilation warnings
[gdcm.git] / src / gdcmVR.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmVR.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/10/20 08:58:18 $
7   Version:   $Revision: 1.42 $
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 /**
87  * \brief   Simple predicate that checks whether the given argument
88  *          corresponds to the Value Representation of a \ref DataEntry .
89  * @param   tested value representation to check for.
90  */
91 bool VR::IsVROfBinaryRepresentable(VRKey const &tested)
92 {
93    //if ( tested == GDCM_UNKNOWN)
94    //{
95    //std::cout << "---------- never used --------------" << tested 
96    //          << std::endl;
97    //   return true;
98    //}
99
100    if ( IsVROfStringRepresentable(tested) )
101       return false;
102
103    if ( IsVROfSequence(tested) )
104       return false;
105
106    return true;
107 }
108
109 /**
110  * \brief   Simple predicate that checks whether the given argument
111  *          corresponds to the Value Representation of a representable
112  *          string.
113  * @param   tested value representation to be checked.
114  */
115 bool VR::IsVROfStringRepresentable(VRKey const &tested)
116 {
117    return tested == "AE" ||
118           tested == "AS" ||
119           tested == "CS" ||
120           tested == "DA" ||
121           tested == "DS" ||
122           tested == "IS" || 
123           tested == "LO" ||
124           tested == "LT" ||
125           tested == "PN" ||
126           tested == "SH" ||
127           tested == "SL" ||
128           tested == "SS" ||
129           tested == "ST" ||
130           tested == "TM" ||
131           tested == "UI" ||
132           tested == "UL" ||
133           tested == "US" ||
134           tested == "UT";
135
136    // Should be quicker --> But it doesn't work : revert to old code
137 /*
138    return tested != "FL" &&
139           tested != "FD" &&
140           tested != "OB" &&
141           tested != "OW" &&
142           tested != "AT" && // Attribute Tag ?!?
143           tested != "SQ" ;
144 */
145 }
146
147 unsigned short VR::GetAtomicElementLength(VRKey const &tested)
148 {
149    // Unsigned & signed short
150    if( tested == "US" || tested == "SS" )
151       return 2;
152    // Unsigned & signed long
153    if( tested == "UL" || tested == "SL" )
154       return 4;
155    // Float
156    if( tested == "FL" )
157       return 4;
158    // Double
159    if( tested == "FD" )
160       return 8;
161    // Word string
162    if( tested == "OW" )
163       return 2;
164    return 1;
165 }
166
167 //-----------------------------------------------------------------------------
168 // Protected
169
170 //-----------------------------------------------------------------------------
171 // Private
172
173 //-----------------------------------------------------------------------------
174 // Print
175 /**
176  * \brief   Print all 
177  * @param   os The output stream to be written to.
178  */
179 void VR::Print(std::ostream &os) 
180 {
181    std::ostringstream s;
182
183    for (VRHT::iterator it = vr.begin(); it != vr.end(); ++it)
184    {
185       s << "VR : " << it->first << " = " << it->second << std::endl;
186    }
187    os << s.str();
188 }
189
190 //-----------------------------------------------------------------------------
191 } // end namespace gdcm