]> Creatis software - gdcm.git/blob - src/gdcmDictGroupName.cxx
Fix mistypings
[gdcm.git] / src / gdcmDictGroupName.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDictGroupName.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/05/23 14:18:09 $
7   Version:   $Revision: 1.8 $
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_NAME_SPACE 
29 {
30 //-----------------------------------------------------------------------------
31 /// \brief auto generated function, to fill up the 'Group Name'
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 /// \returns the formerly NIH defined ACR-NEMA group name
84 const TagName &DictGroupName::GetName(uint16_t group)
85 {
86    DictGroupNameHT::const_iterator it = groupName.find(group);
87    if ( it == groupName.end() )
88    {
89       return GDCM_UNFOUND;
90    }
91    return it->second;
92 }
93
94 //-----------------------------------------------------------------------------
95 // Protected
96
97 //-----------------------------------------------------------------------------
98 // Private
99
100 //-----------------------------------------------------------------------------
101 // Print
102 /**
103  * \brief   Print all 
104  * @param   os The output stream to be written to.
105  */
106 void DictGroupName::Print(std::ostream &os,std::string const &) 
107 {
108    std::ostringstream s;
109
110    for (DictGroupNameHT::iterator it = groupName.begin(); it != groupName.end(); ++it)
111    {
112       s << "DictGroupName : 0x" << std::hex << std::setw(4) << it->first 
113         << std::dec << " = " << it->second << std::endl;
114    }
115    os << s.str();
116 }
117
118 //-----------------------------------------------------------------------------
119 } // end namespace gdcm