]> Creatis software - gdcm.git/blob - src/gdcmVR.cxx
to avoid printing troubles with odd length fields padded with zero to become even
[gdcm.git] / src / gdcmVR.cxx
1 // gdcmVR.cxx
2 #include <fstream>
3 //-----------------------------------------------------------------------------
4 #include "gdcmVR.h"
5 #include "gdcmUtil.h"
6
7 #ifndef PUB_DICT_PATH
8 #  define PUB_DICT_PATH     "../Dicts/"
9 #endif
10 #define DICT_VR "dicomVR.dic"
11
12 #include <iostream>
13 #ifdef GDCM_NO_ANSI_STRING_STREAM
14 #  include <strstream>
15 #  define  ostringstream ostrstream
16 # else
17 #  include <sstream>
18 #endif
19
20 //-----------------------------------------------------------------------------
21 // Constructor / Destructor
22 gdcmVR::gdcmVR(void) 
23 {
24    std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_VR);
25    std::ifstream from(filename.c_str());
26    dbg.Error(!from, "gdcmVR::gdcmVR: can't open dictionary",filename.c_str());
27
28    char buff[1024];
29    std::string key;
30    std::string name;
31
32    while (!from.eof()) 
33    {
34       eatwhite(from);
35       from.getline(buff, 1024, ' ');
36       key = buff;
37       eatwhite(from);
38       from.getline(buff, 1024, ';');
39       name = buff;
40
41       eatwhite(from);
42       from.getline(buff, 1024, '\n');
43
44       if(key!="")
45       {
46          vr[key]=name;
47       }
48    }
49    from.close();
50 }
51
52 gdcmVR::~gdcmVR() {
53    vr.clear();
54 }
55
56 //-----------------------------------------------------------------------------
57 // Print
58 /**
59  * \ingroup gdcmVR
60  * \brief   Print all 
61  * @param   os The output stream to be written to.
62  */
63 void gdcmVR::Print(std::ostream &os) 
64 {
65    std::ostringstream s;
66
67    for (VRHT::iterator it = vr.begin(); it != vr.end(); ++it)
68    {
69       s << "VR : "<<it->first<<" = "<<it->second<<std::endl;
70    }
71    os << s.str();
72 }
73
74 //-----------------------------------------------------------------------------
75 // Public
76 /**
77  * \ingroup gdcmVR
78  * \brief   Get the count for an element
79  * @param   key key to count
80  */
81 int gdcmVR::Count(VRKey key) 
82 {
83    return vr.count(key);
84 }
85
86 //-----------------------------------------------------------------------------
87 // Protected
88
89 //-----------------------------------------------------------------------------
90 // Private
91
92 //-----------------------------------------------------------------------------