]> Creatis software - gdcm.git/blob - src/gdcmTS.cxx
ENH: If possible move the stl include after the gdcm ones, to avoid vc warnings
[gdcm.git] / src / gdcmTS.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmTS.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/10/08 04:43:38 $
7   Version:   $Revision: 1.25 $
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 //-----------------------------------------------------------------------------
29 // Constructor / Destructor
30 gdcmTS::gdcmTS() 
31 {
32    std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_TS);
33    std::ifstream from(filename.c_str());
34    dbg.Error(!from, "gdcmTS::gdcmTS: can't open dictionary",filename.c_str());
35
36    std::string key;
37    std::string name;
38
39    while (!from.eof())
40    {
41       from >> key;
42
43       from >> std::ws; // used to be eatwhite(from);
44       std::getline(from, name);    /// MEMORY LEAK
45
46       if(key!="")
47       {
48          ts[key]=name;
49       }
50    }
51    from.close();
52 }
53
54 //-----------------------------------------------------------------------------
55 gdcmTS::~gdcmTS() 
56 {
57    ts.clear();
58 }
59
60 //-----------------------------------------------------------------------------
61 // Print
62 /**
63  * \ingroup gdcmVR
64  * \brief   Print all 
65  * @param   os The output stream to be written to.
66  */
67 void gdcmTS::Print(std::ostream &os) 
68 {
69    std::ostringstream s;
70
71    for (TSHT::iterator it = ts.begin(); it != ts.end(); ++it)
72    {
73       s << "TS : "<<it->first<<" = "<<it->second<<std::endl;
74    }
75    os << s.str();
76 }
77
78 //-----------------------------------------------------------------------------
79 // Public
80 int gdcmTS::Count(TSKey key) 
81 {
82    return ts.count(key);
83 }
84
85 std::string gdcmTS::GetValue(TSKey key) 
86 {
87    if (ts.count(key) == 0)
88    {
89       return GDCM_UNFOUND;
90    }
91    return ts[key];
92 }
93
94 //-----------------------------------------------------------------------------
95 // Protected
96
97 //-----------------------------------------------------------------------------
98 // Private
99
100 //-----------------------------------------------------------------------------