00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "gdcmDictGroupName.h"
00020 #include "gdcmUtil.h"
00021 #include "gdcmDictSet.h"
00022 #include "gdcmDebug.h"
00023
00024 #include <fstream>
00025 #include <iostream>
00026 #include <iomanip>
00027
00028 namespace GDCM_NAME_SPACE
00029 {
00030
00033 void FillDefaultDictGroupName(DictGroupNameHT &groupName);
00034
00035
00036
00040 DictGroupName::DictGroupName()
00041 {
00042 std::string filename = DictSet::BuildDictPath() + DICT_GROUP_NAME;
00043 std::ifstream from(filename.c_str());
00044 if ( !from )
00045 {
00046 gdcmWarningMacro("Can't open dictionary" << filename.c_str());
00047 FillDefaultDictGroupName(groupName);
00048 }
00049 else
00050 {
00051 char buff[1024];
00052 uint16_t key;
00053 TagName value;
00054
00055 while (!from.eof())
00056 {
00057 from >> std::ws;
00058 from >> std::hex;
00059 from >> key;
00060 from >> std::ws;
00061 from.getline(buff, 1024, '"');
00062 from.getline(buff, 1024, '"');
00063 value = buff;
00064 if ( !from.eof() )
00065 groupName[key] = value;
00066
00067 from.getline(buff, 1024, '\n');
00068 }
00069 from.close();
00070 }
00071 }
00072
00076 DictGroupName::~DictGroupName()
00077 {
00078 groupName.clear();
00079 }
00080
00081
00082
00084 const TagName &DictGroupName::GetName(uint16_t group)
00085 {
00086 DictGroupNameHT::const_iterator it = groupName.find(group);
00087 if ( it == groupName.end() )
00088 {
00089 return GDCM_UNFOUND;
00090 }
00091 return it->second;
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101
00106 void DictGroupName::Print(std::ostream &os,std::string const &)
00107 {
00108 std::ostringstream s;
00109
00110 for (DictGroupNameHT::iterator it = groupName.begin(); it != groupName.end(); ++it)
00111 {
00112 s << "DictGroupName : 0x" << std::hex << std::setw(4) << it->first
00113 << std::dec << " = " << it->second << std::endl;
00114 }
00115 os << s.str();
00116 }
00117
00118
00119 }