2 //-----------------------------------------------------------------------------
6 #ifdef GDCM_NO_ANSI_STRING_STREAM
8 # define ostringstream ostrstream
13 //-----------------------------------------------------------------------------
14 // Constructor / Destructor
18 * @param FileName from which to build the dictionary.
20 gdcmDict::gdcmDict(std::string & FileName) {
21 std::ifstream from(FileName.c_str());
22 dbg.Error(!from, "gdcmDict::gdcmDict: can't open dictionary",
24 guint16 group, element;
25 // CLEANME : use defines for all those constants
33 from >> std::hex >> group >> element;
35 from.getline(buff, 256, ' ');
38 from.getline(buff, 256, ' ');
40 from.getline(buff, 256, '\n');
42 gdcmDictEntry * newEntry = new gdcmDictEntry(group, element,
44 // FIXME: use AddNewEntry
45 NameHt[name] = newEntry;
46 KeyHt[gdcmDictEntry::TranslateToKey(group, element)] = newEntry;
55 gdcmDict::~gdcmDict() {
56 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) {
57 gdcmDictEntry* EntryToDelete = tag->second;
62 // Since AddNewEntry adds symetrical in both KeyHt and NameHT we can
63 // assume all the pointed gdcmDictEntries are already cleaned-up when
68 //-----------------------------------------------------------------------------
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::Print(std::ostream& os) {
81 * \brief Print all the dictionary entries contained in this dictionary.
82 * Entries will be sorted by tag i.e. the couple (group, element).
83 * @param os The output stream to be written to.
85 void gdcmDict::PrintByKey(std::ostream& os) {
88 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag){
90 s << "(" << std::hex << tag->second->GetGroup() << ',';
91 s << std::hex << tag->second->GetElement() << ") = " << std::dec;
92 s << tag->second->GetVR() << ", ";
93 s << tag->second->GetFourth() << ", ";
94 s << tag->second->GetName() << "." << std::endl;
101 * \brief Print all the dictionary entries contained in this dictionary.
102 * Entries will be sorted by the name of the dictionary entries.
103 * \warning AVOID USING IT : the name IS NOT an identifier
104 * unpredictable result
105 * @param os The output stream to be written to.
107 void gdcmDict::PrintByName(std::ostream& os) {
108 std::ostringstream s;
110 for (TagNameHT::iterator tag = NameHt.begin(); tag != NameHt.end(); ++tag){
112 s << tag->second->GetName() << ",";
113 s << tag->second->GetVR() << ", ";
114 s << tag->second->GetFourth() << ", ";
115 s << "(" << std::hex << tag->second->GetGroup() << ',';
116 s << std::hex << tag->second->GetElement() << ") = " << std::dec << std::endl;
121 //-----------------------------------------------------------------------------
125 * \brief adds a new Dicom Dictionary Entry
127 * @return false if Dicom Element already existed
129 bool gdcmDict::AddNewEntry(gdcmDictEntry* NewEntry) {
131 key = NewEntry->GetKey();
133 if(KeyHt.count(key) == 1) {
134 dbg.Verbose(1, "gdcmDict::AddNewEntry already present", key.c_str());
137 KeyHt[NewEntry->GetKey()] = NewEntry;
144 * \brief replaces an already existing Dicom Element by a new one
146 * @return false if Dicom Element doesn't exist
148 bool gdcmDict::ReplaceEntry(gdcmDictEntry* NewEntry) {
149 if ( RemoveEntry(NewEntry->gdcmDictEntry::GetKey()) ) {
150 KeyHt[ NewEntry->GetKey()] = NewEntry;
158 * \brief removes an already existing Dicom Dictionary Entry,
159 * identified by its Tag
160 * @param key (group|element)
161 * @return false if Dicom Dictionary Entry doesn't exist
163 bool gdcmDict::RemoveEntry(TagKey key) {
164 if(KeyHt.count(key) == 1) {
165 gdcmDictEntry* EntryToDelete = KeyHt.find(key)->second;
167 delete EntryToDelete;
171 dbg.Verbose(1, "gdcmDict::RemoveEntry unfound entry", key.c_str());
178 * \brief removes an already existing Dicom Dictionary Entry,
179 * identified by its group,element
181 * @param group Dicom group number of the Dicom Element
182 * @param element Dicom element number of the Dicom Element
183 * @return false if Dicom Dictionary Entry doesn't exist
185 bool gdcmDict::RemoveEntry (guint16 group, guint16 element) {
186 return( RemoveEntry(gdcmDictEntry::TranslateToKey(group, element)) );
191 * \brief Get the dictionnary entry identified by a given tag (group,element)
192 * @param group group of the entry to be found
193 * @param element element of the entry to be found
194 * @return the corresponding dictionnary entry when existing, NULL otherwise
196 gdcmDictEntry * gdcmDict::GetTagByNumber(guint16 group, guint16 element) {
197 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
198 if ( ! KeyHt.count(key))
199 return (gdcmDictEntry*)0;
200 return KeyHt.find(key)->second;
205 * \brief Get the dictionnary entry identified by it's name.
206 * @param name element of the ElVal to modify
207 * \warning : NEVER use it !
208 * the 'name' IS NOT an identifier within the Dicom Dicom Dictionary
209 * the name MAY CHANGE between two versions !
210 * @return the corresponding dictionnary entry when existing, NULL otherwise
212 gdcmDictEntry * gdcmDict::GetTagByName(TagName name) {
213 if ( ! NameHt.count(name))
214 return (gdcmDictEntry*)0;
215 return NameHt.find(name)->second;
218 //-----------------------------------------------------------------------------
221 //-----------------------------------------------------------------------------
224 //-----------------------------------------------------------------------------