]> Creatis software - gdcm.git/blob - src/gdcmDictGroupName.cxx
Summer nights are really too hot to sleep.
[gdcm.git] / src / gdcmDictGroupName.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDictGroupName.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/06/24 10:55:58 $
7   Version:   $Revision: 1.4 $
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 "gdcmDictGroupName.h"
20 #include "gdcmUtil.h"
21 #include "gdcmDictSet.h"
22 #include "gdcmDebug.h"
23
24 #include <fstream>
25 #include <iostream>
26 #include <iomanip>
27
28 namespace gdcm 
29 {
30 //-----------------------------------------------------------------------------
31 /// \brief auto generated function, to fill up the 'Value Representation'
32 ///        Dictionnary, if relevant file is not found on user's disk
33 void FillDefaultDictGroupName(DictGroupNameHT &groupName);
34
35 //-----------------------------------------------------------------------------
36 // Constructor / Destructor
37 /**
38  * \brief Constructor
39  */
40 DictGroupName::DictGroupName() 
41 {
42    std::string filename = DictSet::BuildDictPath() + DICT_GROUP_NAME;
43    std::ifstream from(filename.c_str());
44    if ( !from )
45    {
46       gdcmWarningMacro("Can't open dictionary" << filename.c_str());
47       FillDefaultDictGroupName(groupName);
48    }
49    else
50    {
51       char buff[1024];
52       uint16_t key;
53       TagName value;
54    
55       while (!from.eof()) 
56       {
57          from >> std::ws;
58          from >> std::hex;
59          from >> key;
60          from >> std::ws;
61          from.getline(buff, 1024, '"');
62          from.getline(buff, 1024, '"');
63          value = buff;
64          if ( !from.eof() )
65             groupName[key] = value;
66
67          from.getline(buff, 1024, '\n');
68       }
69       from.close();
70    }
71 }
72
73 /**
74  * \brief Destructor
75  */
76 DictGroupName::~DictGroupName()
77 {
78    groupName.clear();
79 }
80
81 //-----------------------------------------------------------------------------
82 // Public
83 const TagName &DictGroupName::GetName(uint16_t group)
84 {
85    DictGroupNameHT::const_iterator it = groupName.find(group);
86    if ( it == groupName.end() )
87    {
88       return GDCM_UNFOUND;
89    }
90    return it->second;
91 }
92
93 //-----------------------------------------------------------------------------
94 // Protected
95
96 //-----------------------------------------------------------------------------
97 // Private
98
99 //-----------------------------------------------------------------------------
100 // Print
101 /**
102  * \brief   Print all 
103  * @param   os The output stream to be written to.
104  */
105 void DictGroupName::Print(std::ostream &os) 
106 {
107    std::ostringstream s;
108
109    for (DictGroupNameHT::iterator it = groupName.begin(); it != groupName.end(); ++it)
110    {
111       s << "DictGroupName : 0x" << std::hex << std::setw(4) << it->first 
112         << std::dec << " = " << it->second << std::endl;
113    }
114    os << s.str();
115 }
116
117 //-----------------------------------------------------------------------------
118 } // end namespace gdcm