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;
49 gdcmDict::~gdcmDict() {
50 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) {
51 gdcmDictEntry* EntryToDelete = tag->second;
56 // Since AddNewEntry adds symetrical in both KeyHt and NameHT we can
57 // assume all the pointed gdcmDictEntries are allready cleaned-up when
68 void gdcmDict::Print(std::ostream& os) {
74 * \brief Print all the dictionary entries contained in this dictionary.
75 * Entries will be sorted by tag i.e. the couple (group, element).
76 * @param os The output stream to be written to.
78 void gdcmDict::PrintByKey(std::ostream& os) {
79 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag){
81 os << "(" << hex << tag->second->GetGroup() << ',';
82 os << hex << tag->second->GetElement() << ") = " << dec;
83 os << tag->second->GetVR() << ", ";
84 os << tag->second->GetFourth() << ", ";
85 os << tag->second->GetName() << "." << endl;
91 * \brief Print all the dictionary entries contained in this dictionary.
92 * Entries will be sorted by the name of the dictionary entries.
93 * @param os The output stream to be written to.
95 void gdcmDict::PrintByName(std::ostream& os) {
96 for (TagNameHT::iterator tag = NameHt.begin(); tag != NameHt.end(); ++tag){
98 os << tag->second->GetName() << ",";
99 os << tag->second->GetVR() << ", ";
100 os << tag->second->GetFourth() << ", ";
101 os << "(" << std::hex << tag->second->GetGroup() << ',';
102 os << std::hex << tag->second->GetElement() << ") = " << dec << std::endl;
108 * \brief Get the dictionnary entry identified by a given tag (group,element)
109 * @param group group of the entry to be found
110 * @param element element of the entry to be found
111 * @return the corresponding dictionnary entry when existing, NULL otherwise
113 gdcmDictEntry * gdcmDict::GetTagByNumber(guint16 group, guint16 element) {
114 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
115 if ( ! KeyHt.count(key))
116 return (gdcmDictEntry*)0;
117 return KeyHt.find(key)->second;
122 * \brief Get the dictionnary entry identified by it's name.
123 * @param name element of the ElVal to modify
124 * @return the corresponding dictionnary entry when existing, NULL otherwise
126 gdcmDictEntry * gdcmDict::GetTagByName(TagName name) {
127 if ( ! NameHt.count(name))
128 return (gdcmDictEntry*)0;
129 return NameHt.find(name)->second;
138 int gdcmDict::ReplaceEntry(gdcmDictEntry* NewEntry) {
139 if ( RemoveEntry(NewEntry->gdcmDictEntry::GetKey()) ) {
140 KeyHt[ NewEntry->GetKey()] = NewEntry;
152 int gdcmDict::AddNewEntry(gdcmDictEntry* NewEntry) {
154 key = NewEntry->GetKey();
156 if(KeyHt.count(key) == 1) {
157 dbg.Verbose(1, "gdcmDict::AddNewEntry allready present", key.c_str());
160 KeyHt[NewEntry->GetKey()] = NewEntry;
171 int gdcmDict::RemoveEntry(TagKey key) {
172 if(KeyHt.count(key) == 1) {
173 gdcmDictEntry* EntryToDelete = KeyHt.find(key)->second;
175 delete EntryToDelete;
179 dbg.Verbose(1, "gdcmDict::RemoveEntry unfound entry", key.c_str());
190 int gdcmDict::RemoveEntry (guint16 group, guint16 element) {
191 return( RemoveEntry(gdcmDictEntry::TranslateToKey(group, element)) );