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