]> Creatis software - gdcm.git/blob - src/gdcmTS.cxx
ENH: Now the dictionary is compiled into gdcm lib. This is a default behavior, thus...
[gdcm.git] / src / gdcmTS.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmTS.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/11/03 18:08:56 $
7   Version:   $Revision: 1.28 $
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 void FillDefaultTSDict(TSHT & ts);
31 //-----------------------------------------------------------------------------
32 // Constructor / Destructor
33 TS::TS() 
34 {
35    std::string filename = DictSet::BuildDictPath() + DICT_TS;
36    std::ifstream from(filename.c_str());
37    if( !from )
38    {
39       dbg.Verbose(2, "TS::TS: can't open dictionary", filename.c_str());
40       FillDefaultTSDict( TsMap );
41    }
42    else
43    {
44       TSKey key;
45       TSAtr name;
46    
47       while (!from.eof())
48       {
49          from >> key;
50          from >> std::ws;
51          std::getline(from, name);
52    
53          if(key != "")
54          {
55             TsMap[key] = name;
56          }
57       }
58       from.close();
59    }
60 }
61
62 //-----------------------------------------------------------------------------
63 TS::~TS() 
64 {
65    TsMap.clear();
66 }
67
68 //-----------------------------------------------------------------------------
69 // Print
70 /**
71  * \ingroup VR
72  * \brief   Print all 
73  * @param   os The output stream to be written to.
74  */
75 void TS::Print(std::ostream &os) 
76 {
77    std::ostringstream s;
78
79    for (TSHT::const_iterator it = TsMap.begin(); it != TsMap.end(); ++it)
80    {
81       s << "TS : " << it->first << " = " << it->second << std::endl;
82    }
83    os << s.str();
84 }
85
86 //-----------------------------------------------------------------------------
87 // Public
88 int TS::Count(TSKey const & key) 
89 {
90    return TsMap.count(key);
91 }
92
93 TSAtr const & TS::GetValue(TSKey const & key) 
94 {
95    TSHT::const_iterator it = TsMap.find(key);
96    if (it == TsMap.end())
97    {
98       return GDCM_UNFOUND;
99    }
100    return it->second;
101 }
102
103 //-----------------------------------------------------------------------------
104 // Protected
105
106 //-----------------------------------------------------------------------------
107 // Private
108
109 //-----------------------------------------------------------------------------
110
111 } // end namespace gdcm