11 * @param FileName from which to build the dictionary.
13 gdcmDict::gdcmDict(std::string & FileName) {
14 std::ifstream from(FileName.c_str());
15 dbg.Error(!from, "gdcmDict::gdcmDict: can't open dictionary",
17 guint16 group, element;
18 // CLEANME : use defines for all those constants
25 from >> std::hex >> group >> element;
27 from.getline(buff, 256, ' ');
30 from.getline(buff, 256, ' ');
32 from.getline(buff, 256, '\n');
34 gdcmDictEntry * newEntry = new gdcmDictEntry(group, element,
36 // FIXME: use AddNewEntry
37 NameHt[name] = newEntry;
38 KeyHt[gdcmDictEntry::TranslateToKey(group, element)] = newEntry;
47 gdcmDict::~gdcmDict() {
48 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) {
49 gdcmDictEntry* EntryToDelete = tag->second;
54 // Since AddNewEntry adds symetrical in both KeyHt and NameHT we can
55 // assume all the pointed gdcmDictEntries are allready cleaned-up when
65 void gdcmDict::Print(std::ostream& os) {
71 * \brief Print all the dictionary entries contained in this dictionary.
72 * Entries will be sorted by tag i.e. the couple (group, element).
73 * @param os The output stream to be written to.
75 void gdcmDict::PrintByKey(std::ostream& os) {
76 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag){
78 os << "(" << hex << tag->second->GetGroup() << ',';
79 os << hex << tag->second->GetElement() << ") = " << dec;
80 os << tag->second->GetVR() << ", ";
81 os << tag->second->GetFourth() << ", ";
82 os << tag->second->GetName() << "." << endl;
88 * \brief Print all the dictionary entries contained in this dictionary.
89 * Entries will be sorted by the name of the dictionary entries.
90 * @param os The output stream to be written to.
92 void gdcmDict::PrintByName(std::ostream& os) {
93 for (TagNameHT::iterator tag = NameHt.begin(); tag != NameHt.end(); ++tag){
95 os << tag->second->GetName() << ",";
96 os << tag->second->GetVR() << ", ";
97 os << tag->second->GetFourth() << ", ";
98 os << "(" << std::hex << tag->second->GetGroup() << ',';
99 os << std::hex << tag->second->GetElement() << ") = " << dec << std::endl;
105 * \brief Get the dictionnary entry identified by a given tag (group,element)
106 * @param group group of the entry to be found
107 * @param element element of the entry to be found
108 * @return the corresponding dictionnary entry when existing, NULL otherwise
110 gdcmDictEntry * gdcmDict::GetTagByNumber(guint16 group, guint16 element) {
111 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
112 if ( ! KeyHt.count(key))
113 return (gdcmDictEntry*)0;
114 return KeyHt.find(key)->second;
119 * \brief Get the dictionnary entry identified by it's name.
120 * @param name element of the ElVal to modify
121 * @return the corresponding dictionnary entry when existing, NULL otherwise
123 gdcmDictEntry * gdcmDict::GetTagByName(TagName name) {
124 if ( ! NameHt.count(name))
125 return (gdcmDictEntry*)0;
126 return NameHt.find(name)->second;
135 int gdcmDict::ReplaceEntry(gdcmDictEntry* NewEntry) {
136 if ( RemoveEntry(NewEntry->gdcmDictEntry::GetKey()) ) {
137 KeyHt[ NewEntry->GetKey()] = NewEntry;
149 int gdcmDict::AddNewEntry(gdcmDictEntry* NewEntry) {
151 key = NewEntry->GetKey();
153 if(KeyHt.count(key) == 1) {
154 dbg.Verbose(1, "gdcmDict::AddNewEntry allready present", key.c_str());
157 KeyHt[NewEntry->GetKey()] = NewEntry;
168 int gdcmDict::RemoveEntry(TagKey key) {
169 if(KeyHt.count(key) == 1) {
170 gdcmDictEntry* EntryToDelete = KeyHt.find(key)->second;
172 delete EntryToDelete;
176 dbg.Verbose(1, "gdcmDict::RemoveEntry unfound entry", key.c_str());
188 int gdcmDict::RemoveEntry (guint16 group, guint16 element) {
189 return( RemoveEntry(gdcmDictEntry::TranslateToKey(group, element)) );