]> Creatis software - gdcm.git/blob - src/gdcmVR.cxx
ENH: Now Example is an option, ON by default
[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  * \ingroup gdcmVR
57  * \brief   Print all 
58  * @param   os The output stream to be written to.
59  */
60 void gdcmVR::Print(std::ostream &os) 
61 {
62    std::ostringstream s;
63
64    for (VRHT::iterator it = vr.begin(); it != vr.end(); ++it)
65    {
66       s << "VR : "<<it->first<<" = "<<it->second<<std::endl;
67    }
68    os << s.str();
69 }
70
71 //-----------------------------------------------------------------------------
72 // Public
73 /**
74  * \ingroup gdcmVR
75  * \brief   Get the count for an element
76  * @param   key key to count
77  */
78 int gdcmVR::Count(VRKey key) 
79 {
80    return vr.count(key);
81 }
82
83 //-----------------------------------------------------------------------------
84 // Protected
85
86 //-----------------------------------------------------------------------------
87 // Private
88
89 //-----------------------------------------------------------------------------