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