10 * @param FileName from which to build the dictionary.
12 gdcmDict::gdcmDict(string & FileName) {
13 std::ifstream from(FileName.c_str());
14 dbg.Error(!from, "gdcmDict::gdcmDict: can't open dictionary",
16 guint16 group, element;
17 // CLEANME : use defines for all those constants
24 from >> hex >> group >> element;
26 from.getline(buff, 256, ' ');
29 from.getline(buff, 256, ' ');
31 from.getline(buff, 256, '\n');
33 gdcmDictEntry * newEntry = new gdcmDictEntry(group, element,
35 // FIXME: use AddNewEntry
36 NameHt[name] = newEntry;
37 KeyHt[gdcmDictEntry::TranslateToKey(group, element)] = newEntry;
42 gdcmDict::~gdcmDict() {
43 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) {
44 gdcmDictEntry* EntryToDelete = tag->second;
49 // Since AddNewEntry adds symetrical in both KeyHt and NameHT we can
50 // assume all the pointed gdcmDictEntries are allready cleaned-up when
55 void gdcmDict::Print(ostream& os) {
61 * \brief Print all the dictionary entries contained in this dictionary.
62 * Entries will be sorted by tag i.e. the couple (group, element).
63 * @param os The output stream to be written to.
65 void gdcmDict::PrintByKey(ostream& os) {
66 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag){
68 os << "(" << hex << tag->second->GetGroup() << ',';
69 os << hex << tag->second->GetElement() << ") = " << dec;
70 os << tag->second->GetVR() << ", ";
71 os << tag->second->GetFourth() << ", ";
72 os << tag->second->GetName() << "." << endl;
78 * \brief Print all the dictionary entries contained in this dictionary.
79 * Entries will be sorted by the name of the dictionary entries.
80 * @param os The output stream to be written to.
82 void gdcmDict::PrintByName(ostream& os) {
83 for (TagNameHT::iterator tag = NameHt.begin(); tag != NameHt.end(); ++tag){
85 os << tag->second->GetName() << ",";
86 os << tag->second->GetVR() << ", ";
87 os << tag->second->GetFourth() << ", ";
88 os << "(" << hex << tag->second->GetGroup() << ',';
89 os << hex << tag->second->GetElement() << ") = " << dec << endl;
95 * \brief Get the dictionnary entry identified by a given tag (group,element)
96 * @param group group of the entry to be found
97 * @param element element of the entry to be found
98 * @return the corresponding dictionnary entry when existing, NULL otherwise
100 gdcmDictEntry * gdcmDict::GetTagByNumber(guint16 group, guint16 element) {
101 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
102 if ( ! KeyHt.count(key))
103 return (gdcmDictEntry*)0;
104 return KeyHt.find(key)->second;
109 * \brief Get the dictionnary entry identified by it's name.
110 * @param name element of the ElVal to modify
111 * @return the corresponding dictionnary entry when existing, NULL otherwise
113 gdcmDictEntry * gdcmDict::GetTagByName(TagName name) {
114 if ( ! NameHt.count(name))
115 return (gdcmDictEntry*)0;
116 return NameHt.find(name)->second;
119 int gdcmDict::ReplaceEntry(gdcmDictEntry* NewEntry) {
120 if ( RemoveEntry(NewEntry->gdcmDictEntry::GetKey()) ) {
121 KeyHt[ NewEntry->GetKey()] = NewEntry;
127 int gdcmDict::AddNewEntry(gdcmDictEntry* NewEntry) {
130 key = NewEntry->GetKey();
132 if(KeyHt.count(key) == 1) {
133 dbg.Verbose(1, "gdcmDict::AddNewEntry allready present", key.c_str());
136 KeyHt[NewEntry->GetKey()] = NewEntry;
142 int gdcmDict::RemoveEntry(TagKey key) {
143 if(KeyHt.count(key) == 1) {
144 gdcmDictEntry* EntryToDelete = KeyHt.find(key)->second;
146 delete EntryToDelete;
150 dbg.Verbose(1, "gdcmDict::RemoveEntry unfound entry", key.c_str());
156 int gdcmDict::RemoveEntry (guint16 group, guint16 element) {
157 return( RemoveEntry(gdcmDictEntry::TranslateToKey(group, element)) );