]> Creatis software - gdcm.git/blob - src/gdcmDict.cxx
Commenataires?
[gdcm.git] / src / gdcmDict.cxx
1 // gdcmDict.cxx
2
3 #include <fstream>
4 #include "gdcm.h"
5 #include "gdcmUtil.h"
6
7 gdcmDict::gdcmDict(const char* FileName) {
8         std::ifstream from(FileName);
9         dbg.Error(!from, "gdcmDict::gdcmDict: can't open dictionary", FileName);
10         guint16 group, element;
11         // CLEANME : use defines for all those constants
12         char buff[1024];
13         TagKey key, vr, fourth, name;
14         while (!from.eof()) {
15                 from >> hex >> group >> element;
16                 eatwhite(from);
17                 from.getline(buff, 256, ' ');
18                 vr = buff;
19                 eatwhite(from);
20                 from.getline(buff, 256, ' ');
21                 fourth = buff;
22                 from.getline(buff, 256, '\n');
23                 name = buff;
24                 gdcmDictEntry * newEntry = new gdcmDictEntry(group, element,
25                                                          vr, fourth, name);
26                 entries[gdcmDictEntry::TranslateToKey(group, element)] = newEntry;
27         }
28    from.close();
29 }
30
31 void gdcmDict::Print(ostream& os) {
32         for (TagHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){
33        os << "Tag : ";
34        os << "(" << hex << tag->second->GetGroup() << ',';
35        os << hex << tag->second->GetElement() << ") = " << dec;
36        os << tag->second->GetVR() << ", ";
37        os << tag->second->GetFourth() << ", ";
38        os << tag->second->GetName() << "."  << endl;
39     }
40 }
41
42 // renvoie une ligne de Dictionnaire Dicom à partir de (numGroup, numElement)
43
44 gdcmDictEntry * gdcmDict::GetTag(guint32 group, guint32 element) {
45         TagKey key = gdcmDictEntry::TranslateToKey(group, element);
46         if ( ! entries.count(key))
47                 return (gdcmDictEntry*)0; 
48         if (entries.count(key) > 1)
49                 dbg.Verbose(0, "gdcmDict::GetTag", 
50                             "multiple entries for this key (FIXME) !");
51         return entries.find(key)->second;
52 }