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