]> Creatis software - gdcm.git/blob - src/gdcmVR.cxx
* Erroneous leading white fix:
[gdcm.git] / src / gdcmVR.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmVR.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/06/20 18:08:48 $
7   Version:   $Revision: 1.13 $
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.htm 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 (VRHT::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(VRKey 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 represenation to check for.
103  */
104 bool gdcmVR::IsVROfGdcmBinaryRepresentable(VRKey tested)
105 {
106    if ( ! Count(tested) )
107    {
108       dbg.Verbose(0, "gdcmVR::IsVROfGdcmBinaryRepresentable: tested not a VR!");
109       return false;
110    }
111
112    if ( IsVROfGdcmStringRepresentable(tested) )
113    {
114       dbg.Verbose(0, "gdcmVR::IsVROfGdcmBinaryRepresentable: binary VR !");
115       return false;
116    }
117
118    return true;
119 }
120
121 /**
122  * \brief   Simple predicate that checks wether the given argument
123  *          corresponds to the Value Representation of a \ref gdcmValEntry
124  *          but NOT a \ref gdcmBinEntry.
125  * @param   tested value represenation to check for.
126  */
127 bool gdcmVR::IsVROfGdcmStringRepresentable(VRKey tested)
128 {
129    if ( ! Count(tested) )
130    {
131       dbg.Verbose(0, "gdcmVR::IsVROfGdcmStringRepresentable: tested not a VR!");
132       return false;
133    }
134
135    if (tested == "AE" || tested == "AS" || tested == "DA" || tested == "PN" ||
136        tested == "UI" || tested == "TM" || tested == "SH" || tested == "LO" ||
137        tested == "CS" || tested == "IS" || tested == "LO" || tested == "LT" ||
138        tested == "SH" || tested == "ST" || tested == "DS" || tested == "SL" ||
139        tested == "SS" || tested == "UL" || tested == "US" )
140    {
141       return true;
142    }
143    return false;
144 }
145
146 //-----------------------------------------------------------------------------
147 // Protected
148
149 //-----------------------------------------------------------------------------
150 // Private
151
152 //-----------------------------------------------------------------------------