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