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