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