]> Creatis software - gdcm.git/blob - src/gdcmTS.cxx
* add shadow dictionary
[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       eatwhite(from);
38       from.getline(buff, 1024, '\n');
39       name = buff;
40
41       if(key!="") 
42       {
43          ts[key]=name;
44       }
45    }
46    from.close();
47 }
48
49 gdcmTS::~gdcmTS() 
50 {
51    ts.clear();
52 }
53
54 //-----------------------------------------------------------------------------
55 // Print
56 /**
57  * \ingroup gdcmVR
58  * \brief   Print all 
59  * @param   os The output stream to be written to.
60  */
61 void gdcmTS::Print(std::ostream &os) 
62 {
63    std::ostringstream s;
64
65    for (TSHT::iterator it = ts.begin(); it != ts.end(); ++it)
66    {
67       s << "TS : "<<it->first<<" = "<<it->second<<std::endl;
68    }
69    os << s.str();
70 }
71
72 //-----------------------------------------------------------------------------
73 // Public
74 int gdcmTS::Count(TSKey key) 
75 {
76    return ts.count(key);
77 }
78
79 std::string gdcmTS::GetValue(TSKey key) 
80 {
81    if (ts.count(key) == 0) 
82       return (GDCM_UNFOUND);
83    return ts[key];
84 }
85
86 //-----------------------------------------------------------------------------
87 // Protected
88
89 //-----------------------------------------------------------------------------
90 // Private
91
92 //-----------------------------------------------------------------------------