]> Creatis software - gdcm.git/blob - src/gdcmTS.cxx
ENH: Ok second chunk of patch, tests seems to go smoothly
[gdcm.git] / src / gdcmTS.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmTS.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/06/21 04:43:02 $
7   Version:   $Revision: 1.19 $
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       eatwhite(from);
45       getline(from, name);    /// MEMORY LEAK
46
47       if(key!="") 
48       {
49          ts[key]=name;
50       }
51    }
52    from.close();
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       return (GDCM_UNFOUND);
89    return ts[key];
90 }
91
92 //-----------------------------------------------------------------------------
93 // Protected
94
95 //-----------------------------------------------------------------------------
96 // Private
97
98 //-----------------------------------------------------------------------------