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