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