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
18 from >> hex >> group >> element;
20 from.getline(buff, 256, ' ');
23 from.getline(buff, 256, ' ');
25 from.getline(buff, 256, '\n');
27 gdcmDictEntry * newEntry = new gdcmDictEntry(group, element,
29 NameHt[name] = newEntry;
30 KeyHt[gdcmDictEntry::TranslateToKey(group, element)] = newEntry;
35 void gdcmDict::Print(ostream& os) {
41 * \brief Print all the dictionary entries contained in this dictionary.
42 * Entries will be sorted by tag i.e. the couple (group, element).
43 * @param os The output stream to be written to.
45 void gdcmDict::PrintByKey(ostream& os) {
46 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag){
48 os << "(" << hex << tag->second->GetGroup() << ',';
49 os << hex << tag->second->GetElement() << ") = " << dec;
50 os << tag->second->GetVR() << ", ";
51 os << tag->second->GetFourth() << ", ";
52 os << tag->second->GetName() << "." << endl;
58 * \brief Print all the dictionary entries contained in this dictionary.
59 * Entries will be sorted by the name of the dictionary entries.
60 * @param os The output stream to be written to.
62 void gdcmDict::PrintByName(ostream& os) {
63 for (TagNameHT::iterator tag = NameHt.begin(); tag != NameHt.end(); ++tag){
65 os << tag->second->GetName() << ",";
66 os << tag->second->GetVR() << ", ";
67 os << tag->second->GetFourth() << ", ";
68 os << "(" << hex << tag->second->GetGroup() << ',';
69 os << hex << tag->second->GetElement() << ") = " << dec << endl;
75 * \brief Get the dictionnary entry identified by a given tag (group,element)
76 * @param group group of the entry to be found
77 * @param element element of the entry to be found
78 * @return the corresponding dictionnary entry when existing, NULL otherwise
80 gdcmDictEntry * gdcmDict::GetTagByKey(guint16 group, guint16 element) {
81 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
82 if ( ! KeyHt.count(key))
83 return (gdcmDictEntry*)0;
84 if (KeyHt.count(key) > 1)
85 dbg.Verbose(0, "gdcmDict::GetTagByName",
86 "multiple entries for this key (FIXME) !");
87 return KeyHt.find(key)->second;
92 * \brief Get the dictionnary entry identified by it's name.
93 * @param name element of the ElVal to modify
94 * @return the corresponding dictionnary entry when existing, NULL otherwise
96 gdcmDictEntry * gdcmDict::GetTagByName(TagName name) {
97 if ( ! NameHt.count(name))
98 return (gdcmDictEntry*)0;
99 if (NameHt.count(name) > 1)
100 dbg.Verbose(0, "gdcmDict::GetTagByName",
101 "multiple entries for this key (FIXME) !");
102 return NameHt.find(name)->second;
106 int gdcmDict::ReplaceEntry(gdcmDictEntry* NewEntry) {
108 // au cas ou la NewEntry serait incomplete
109 // Question : cela peut-il se produire ?
111 // --> NON : voir constructeur
113 //key = NewEntry->GetKey();
115 // NewEntry->gdcmDictEntry::SetKey(
116 // gdcmDictEntry::TranslateToKey(NewEntry->GetGroup(), NewEntry->GetElement())
120 KeyHt.erase (NewEntry->gdcmDictEntry::GetKey());
121 KeyHt[ NewEntry->GetKey()] = NewEntry;
123 // Question(jpr): Dans quel cas ça peut planter ?
124 // Reponse(frog): dans les mauvais cas...
128 int gdcmDict::AddNewEntry(gdcmDictEntry* NewEntry) {
131 key = NewEntry->GetKey();
133 if(KeyHt.count(key) >= 1) {
134 dbg.Verbose(1, "gdcmDict::AddNewEntry allready present", key.c_str());
137 KeyHt[NewEntry->GetKey()] = NewEntry;
143 int gdcmDict::RemoveEntry(TagKey key) {
144 if(KeyHt.count(key) == 1) {
148 dbg.Verbose(1, "gdcmDict::RemoveEntry unfound entry", key.c_str());
154 int gdcmDict::RemoveEntry (guint16 group, guint16 element) {
156 return( RemoveEntry(gdcmDictEntry::TranslateToKey(group, element)) );