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