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