]> Creatis software - gdcm.git/blob - src/gdcmTS.cxx
* Memory leak hunt with the following command:
[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       from >> key;
28       getline(from, name);    /// MEMORY LEAK
29
30       if(key!="") 
31       {
32          ts[key]=name;
33       }
34    }
35    from.close();
36 }
37
38 gdcmTS::~gdcmTS() 
39 {
40    ts.clear();
41 }
42
43 //-----------------------------------------------------------------------------
44 // Print
45 /**
46  * \ingroup gdcmVR
47  * \brief   Print all 
48  * @param   os The output stream to be written to.
49  */
50 void gdcmTS::Print(std::ostream &os) 
51 {
52    std::ostringstream s;
53
54    for (TSHT::iterator it = ts.begin(); it != ts.end(); ++it)
55    {
56       s << "TS : "<<it->first<<" = "<<it->second<<std::endl;
57    }
58    os << s.str();
59 }
60
61 //-----------------------------------------------------------------------------
62 // Public
63 int gdcmTS::Count(TSKey key) 
64 {
65    return ts.count(key);
66 }
67
68 std::string gdcmTS::GetValue(TSKey key) 
69 {
70    if (ts.count(key) == 0) 
71       return (GDCM_UNFOUND);
72    return ts[key];
73 }
74
75 //-----------------------------------------------------------------------------
76 // Protected
77
78 //-----------------------------------------------------------------------------
79 // Private
80
81 //-----------------------------------------------------------------------------