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