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
67 * \brief Print all the dictionary entries contained in this dictionary.
68 * Entries will be sorted by tag i.e. the couple (group, element).
69 * @param os The output stream to be written to.
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 * \warning AVOID USING IT : the name IS NOT an identifier
100 * unpredictable result
101 * @param os The output stream to be written to.
103 void gdcmDict::PrintByName(std::ostream& os) {
104 std::ostringstream s;
106 for (TagNameHT::iterator tag = NameHt.begin(); tag != NameHt.end(); ++tag){
108 s << tag->second->GetName() << ",";
109 s << tag->second->GetVR() << ", ";
110 s << tag->second->GetFourth() << ", ";
111 s << "(" << std::hex << tag->second->GetGroup() << ',';
112 s << std::hex << tag->second->GetElement() << ") = " << std::dec << std::endl;
119 * \brief Get the dictionnary entry identified by a given tag (group,element)
120 * @param group group of the entry to be found
121 * @param element element of the entry to be found
122 * @return the corresponding dictionnary entry when existing, NULL otherwise
124 gdcmDictEntry * gdcmDict::GetTagByNumber(guint16 group, guint16 element) {
125 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
126 if ( ! KeyHt.count(key))
127 return (gdcmDictEntry*)0;
128 return KeyHt.find(key)->second;
133 * \brief Get the dictionnary entry identified by it's name.
134 * @param name element of the ElVal to modify
135 * \warning : NEVER use it !
136 * the 'name' IS NOT an identifier within the Dicom Dicom Dictionary
137 * the name MAY CHANGE between two versions !
138 * @return the corresponding dictionnary entry when existing, NULL otherwise
140 gdcmDictEntry * gdcmDict::GetTagByName(TagName name) {
141 if ( ! NameHt.count(name))
142 return (gdcmDictEntry*)0;
143 return NameHt.find(name)->second;
148 * \brief replaces an already existing Dicom Element by a new one
150 * @return false if Dicom Element doesn't exist
152 bool gdcmDict::ReplaceEntry(gdcmDictEntry* NewEntry) {
153 if ( RemoveEntry(NewEntry->gdcmDictEntry::GetKey()) ) {
154 KeyHt[ NewEntry->GetKey()] = NewEntry;
162 * \brief adds a new Dicom Dictionary Entry
164 * @return false if Dicom Element already existed
166 bool gdcmDict::AddNewEntry(gdcmDictEntry* NewEntry) {
168 key = NewEntry->GetKey();
170 if(KeyHt.count(key) == 1) {
171 dbg.Verbose(1, "gdcmDict::AddNewEntry already present", key.c_str());
174 KeyHt[NewEntry->GetKey()] = NewEntry;
181 * \brief removes an already existing Dicom Dictionary Entry,
182 * identified by its Tag
183 * @param key (group|element)
184 * @return false if Dicom Dictionary Entry doesn't exist
186 bool gdcmDict::RemoveEntry(TagKey key) {
187 if(KeyHt.count(key) == 1) {
188 gdcmDictEntry* EntryToDelete = KeyHt.find(key)->second;
190 delete EntryToDelete;
194 dbg.Verbose(1, "gdcmDict::RemoveEntry unfound entry", key.c_str());
201 * \brief removes an already existing Dicom Dictionary Entry,
202 * identified by its group,element
204 * @param group Dicom group number of the Dicom Element
205 * @param element Dicom element number of the Dicom Element
206 * @return false if Dicom Dictionary Entry doesn't exist
208 bool gdcmDict::RemoveEntry (guint16 group, guint16 element) {
209 return( RemoveEntry(gdcmDictEntry::TranslateToKey(group, element)) );