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