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