10 * @param FileName from which to build the dictionary.
12 gdcmDict::gdcmDict(std::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 >> std::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;
46 gdcmDict::~gdcmDict() {
47 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) {
48 gdcmDictEntry* EntryToDelete = tag->second;
53 // Since AddNewEntry adds symetrical in both KeyHt and NameHT we can
54 // assume all the pointed gdcmDictEntries are already cleaned-up when
64 void gdcmDict::Print(std::ostream& os) {
70 * \brief Print all the dictionary entries contained in this dictionary.
71 * Entries will be sorted by tag i.e. the couple (group, element).
72 * @param os The output stream to be written to.
74 void gdcmDict::PrintByKey(std::ostream& os) {
75 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag){
77 os << "(" << std::hex << tag->second->GetGroup() << ',';
78 os << std::hex << tag->second->GetElement() << ") = " << std::dec;
79 os << tag->second->GetVR() << ", ";
80 os << tag->second->GetFourth() << ", ";
81 os << tag->second->GetName() << "." << std::endl;
87 * \brief Print all the dictionary entries contained in this dictionary.
88 * Entries will be sorted by the name of the dictionary entries.
89 * @param os The output stream to be written to.
91 void gdcmDict::PrintByName(std::ostream& os) {
92 for (TagNameHT::iterator tag = NameHt.begin(); tag != NameHt.end(); ++tag){
94 os << tag->second->GetName() << ",";
95 os << tag->second->GetVR() << ", ";
96 os << tag->second->GetFourth() << ", ";
97 os << "(" << std::hex << tag->second->GetGroup() << ',';
98 os << std::hex << tag->second->GetElement() << ") = " << std::dec << std::endl;
104 * \brief Get the dictionnary entry identified by a given tag (group,element)
105 * @param group group of the entry to be found
106 * @param element element of the entry to be found
107 * @return the corresponding dictionnary entry when existing, NULL otherwise
109 gdcmDictEntry * gdcmDict::GetTagByNumber(guint16 group, guint16 element) {
110 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
111 if ( ! KeyHt.count(key))
112 return (gdcmDictEntry*)0;
113 return KeyHt.find(key)->second;
118 * \brief Get the dictionnary entry identified by it's name.
119 * @param name element of the ElVal to modify
120 * @return the corresponding dictionnary entry when existing, NULL otherwise
122 gdcmDictEntry * gdcmDict::GetTagByName(TagName name) {
123 if ( ! NameHt.count(name))
124 return (gdcmDictEntry*)0;
125 return NameHt.find(name)->second;
134 int gdcmDict::ReplaceEntry(gdcmDictEntry* NewEntry) {
135 if ( RemoveEntry(NewEntry->gdcmDictEntry::GetKey()) ) {
136 KeyHt[ NewEntry->GetKey()] = NewEntry;
148 int gdcmDict::AddNewEntry(gdcmDictEntry* NewEntry) {
150 key = NewEntry->GetKey();
152 if(KeyHt.count(key) == 1) {
153 dbg.Verbose(1, "gdcmDict::AddNewEntry already present", key.c_str());
156 KeyHt[NewEntry->GetKey()] = NewEntry;
167 int gdcmDict::RemoveEntry(TagKey key) {
168 if(KeyHt.count(key) == 1) {
169 gdcmDictEntry* EntryToDelete = KeyHt.find(key)->second;
171 delete EntryToDelete;
175 dbg.Verbose(1, "gdcmDict::RemoveEntry unfound entry", key.c_str());
187 int gdcmDict::RemoveEntry (guint16 group, guint16 element) {
188 return( RemoveEntry(gdcmDictEntry::TranslateToKey(group, element)) );