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