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