6 #ifdef GDCM_NO_ANSI_STRING_STREAM
8 # define ostringstream ostrstream
16 * @param FileName from which to build the dictionary.
18 gdcmDict::gdcmDict(std::string & FileName) {
19 std::ifstream from(FileName.c_str());
20 dbg.Error(!from, "gdcmDict::gdcmDict: can't open dictionary",
22 guint16 group, element;
23 // CLEANME : use defines for all those constants
31 from >> std::hex >> group >> element;
33 from.getline(buff, 256, ' ');
36 from.getline(buff, 256, ' ');
38 from.getline(buff, 256, '\n');
40 gdcmDictEntry * newEntry = new gdcmDictEntry(group, element,
42 // FIXME: use AddNewEntry
43 NameHt[name] = newEntry;
44 KeyHt[gdcmDictEntry::TranslateToKey(group, element)] = newEntry;
53 gdcmDict::~gdcmDict() {
54 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) {
55 gdcmDictEntry* EntryToDelete = tag->second;
60 // Since AddNewEntry adds symetrical in both KeyHt and NameHT we can
61 // assume all the pointed gdcmDictEntries are already cleaned-up when
71 void gdcmDict::Print(std::ostream& os) {
77 * \brief Print all the dictionary entries contained in this dictionary.
78 * Entries will be sorted by tag i.e. the couple (group, element).
79 * @param os The output stream to be written to.
81 void gdcmDict::PrintByKey(std::ostream& os) {
84 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag){
86 s << "(" << std::hex << tag->second->GetGroup() << ',';
87 s << std::hex << tag->second->GetElement() << ") = " << std::dec;
88 s << tag->second->GetVR() << ", ";
89 s << tag->second->GetFourth() << ", ";
90 s << tag->second->GetName() << "." << std::endl;
97 * \brief Print all the dictionary entries contained in this dictionary.
98 * Entries will be sorted by the name of the dictionary entries.
99 * @param os The output stream to be written to.
101 void gdcmDict::PrintByName(std::ostream& os) {
102 std::ostringstream s;
104 for (TagNameHT::iterator tag = NameHt.begin(); tag != NameHt.end(); ++tag){
106 s << tag->second->GetName() << ",";
107 s << tag->second->GetVR() << ", ";
108 s << tag->second->GetFourth() << ", ";
109 s << "(" << std::hex << tag->second->GetGroup() << ',';
110 s << std::hex << tag->second->GetElement() << ") = " << std::dec << std::endl;
117 * \brief Get the dictionnary entry identified by a given tag (group,element)
118 * @param group group of the entry to be found
119 * @param element element of the entry to be found
120 * @return the corresponding dictionnary entry when existing, NULL otherwise
122 gdcmDictEntry * gdcmDict::GetTagByNumber(guint16 group, guint16 element) {
123 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
124 if ( ! KeyHt.count(key))
125 return (gdcmDictEntry*)0;
126 return KeyHt.find(key)->second;
131 * \brief Get the dictionnary entry identified by it's name.
132 * @param name element of the ElVal to modify
133 * @return the corresponding dictionnary entry when existing, NULL otherwise
135 gdcmDictEntry * gdcmDict::GetTagByName(TagName name) {
136 if ( ! NameHt.count(name))
137 return (gdcmDictEntry*)0;
138 return NameHt.find(name)->second;
147 int gdcmDict::ReplaceEntry(gdcmDictEntry* NewEntry) {
148 if ( RemoveEntry(NewEntry->gdcmDictEntry::GetKey()) ) {
149 KeyHt[ NewEntry->GetKey()] = NewEntry;
161 int gdcmDict::AddNewEntry(gdcmDictEntry* NewEntry) {
163 key = NewEntry->GetKey();
165 if(KeyHt.count(key) == 1) {
166 dbg.Verbose(1, "gdcmDict::AddNewEntry already present", key.c_str());
169 KeyHt[NewEntry->GetKey()] = NewEntry;
180 int gdcmDict::RemoveEntry(TagKey key) {
181 if(KeyHt.count(key) == 1) {
182 gdcmDictEntry* EntryToDelete = KeyHt.find(key)->second;
184 delete EntryToDelete;
188 dbg.Verbose(1, "gdcmDict::RemoveEntry unfound entry", key.c_str());
200 int gdcmDict::RemoveEntry (guint16 group, guint16 element) {
201 return( RemoveEntry(gdcmDictEntry::TranslateToKey(group, element)) );