]> Creatis software - gdcm.git/blob - src/gdcmTS.cxx
ENH: Adding 'gdcm' namespace. Be nice with me this was a ~13000 lines patch. Also...
[gdcm.git] / src / gdcmTS.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmTS.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/10/12 04:35:48 $
7   Version:   $Revision: 1.26 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19 #include "gdcmTS.h"
20 #include "gdcmDebug.h"
21 #include "gdcmUtil.h"
22 #include "gdcmDictSet.h"
23
24 #include <fstream>
25 #include <string>
26 #include <iostream>
27
28 namespace gdcm 
29 {
30
31 //-----------------------------------------------------------------------------
32 // Constructor / Destructor
33 TS::TS() 
34 {
35    std::string filename=DictSet::BuildDictPath() + std::string(DICT_TS);
36    std::ifstream from(filename.c_str());
37    dbg.Error(!from, "TS::TS: can't open dictionary",filename.c_str());
38
39    std::string key;
40    std::string name;
41
42    while (!from.eof())
43    {
44       from >> key;
45
46       from >> std::ws; // used to be eatwhite(from);
47       std::getline(from, name);    /// MEMORY LEAK
48
49       if(key!="")
50       {
51          ts[key]=name;
52       }
53    }
54    from.close();
55 }
56
57 //-----------------------------------------------------------------------------
58 TS::~TS() 
59 {
60    ts.clear();
61 }
62
63 //-----------------------------------------------------------------------------
64 // Print
65 /**
66  * \ingroup VR
67  * \brief   Print all 
68  * @param   os The output stream to be written to.
69  */
70 void TS::Print(std::ostream &os) 
71 {
72    std::ostringstream s;
73
74    for (TSHT::iterator it = ts.begin(); it != ts.end(); ++it)
75    {
76       s << "TS : "<<it->first<<" = "<<it->second<<std::endl;
77    }
78    os << s.str();
79 }
80
81 //-----------------------------------------------------------------------------
82 // Public
83 int TS::Count(TSKey key) 
84 {
85    return ts.count(key);
86 }
87
88 std::string TS::GetValue(TSKey key) 
89 {
90    if (ts.count(key) == 0)
91    {
92       return GDCM_UNFOUND;
93    }
94    return ts[key];
95 }
96
97 //-----------------------------------------------------------------------------
98 // Protected
99
100 //-----------------------------------------------------------------------------
101 // Private
102
103 //-----------------------------------------------------------------------------
104
105 } // end namespace gdcm