3 //This is needed when compiling in debug mode
5 // 'identifier' : class 'type' needs to have dll-interface to be used by
6 // clients of class 'type2'
7 #pragma warning ( disable : 4251 )
8 // 'identifier' : identifier was truncated to 'number' characters in the
10 #pragma warning ( disable : 4786 )
21 * @param FileName from which to build the dictionary.
23 gdcmDict::gdcmDict(std::string & FileName) {
24 std::ifstream from(FileName.c_str());
25 dbg.Error(!from, "gdcmDict::gdcmDict: can't open dictionary",
27 guint16 group, element;
28 // CLEANME : use defines for all those constants
35 from >> std::hex >> group >> element;
37 from.getline(buff, 256, ' ');
40 from.getline(buff, 256, ' ');
42 from.getline(buff, 256, '\n');
44 gdcmDictEntry * newEntry = new gdcmDictEntry(group, element,
46 // FIXME: use AddNewEntry
47 NameHt[name] = newEntry;
48 KeyHt[gdcmDictEntry::TranslateToKey(group, element)] = newEntry;
57 gdcmDict::~gdcmDict() {
58 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) {
59 gdcmDictEntry* EntryToDelete = tag->second;
64 // Since AddNewEntry adds symetrical in both KeyHt and NameHT we can
65 // assume all the pointed gdcmDictEntries are already cleaned-up when
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) {
86 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag){
88 os << "(" << hex << tag->second->GetGroup() << ',';
89 os << hex << tag->second->GetElement() << ") = " << dec;
90 os << tag->second->GetVR() << ", ";
91 os << tag->second->GetFourth() << ", ";
92 os << tag->second->GetName() << "." << endl;
98 * \brief Print all the dictionary entries contained in this dictionary.
99 * Entries will be sorted by the name of the dictionary entries.
100 * @param os The output stream to be written to.
102 void gdcmDict::PrintByName(std::ostream& os) {
103 for (TagNameHT::iterator tag = NameHt.begin(); tag != NameHt.end(); ++tag){
105 os << tag->second->GetName() << ",";
106 os << tag->second->GetVR() << ", ";
107 os << tag->second->GetFourth() << ", ";
108 os << "(" << std::hex << tag->second->GetGroup() << ',';
109 os << std::hex << tag->second->GetElement() << ") = " << dec << std::endl;
115 * \brief Get the dictionnary entry identified by a given tag (group,element)
116 * @param group group of the entry to be found
117 * @param element element of the entry to be found
118 * @return the corresponding dictionnary entry when existing, NULL otherwise
120 gdcmDictEntry * gdcmDict::GetTagByNumber(guint16 group, guint16 element) {
121 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
122 if ( ! KeyHt.count(key))
123 return (gdcmDictEntry*)0;
124 return KeyHt.find(key)->second;
129 * \brief Get the dictionnary entry identified by it's name.
130 * @param name element of the ElVal to modify
131 * @return the corresponding dictionnary entry when existing, NULL otherwise
133 gdcmDictEntry * gdcmDict::GetTagByName(TagName name) {
134 if ( ! NameHt.count(name))
135 return (gdcmDictEntry*)0;
136 return NameHt.find(name)->second;
145 int gdcmDict::ReplaceEntry(gdcmDictEntry* NewEntry) {
146 if ( RemoveEntry(NewEntry->gdcmDictEntry::GetKey()) ) {
147 KeyHt[ NewEntry->GetKey()] = NewEntry;
159 int gdcmDict::AddNewEntry(gdcmDictEntry* NewEntry) {
161 key = NewEntry->GetKey();
163 if(KeyHt.count(key) == 1) {
164 dbg.Verbose(1, "gdcmDict::AddNewEntry already present", key.c_str());
167 KeyHt[NewEntry->GetKey()] = NewEntry;
178 int gdcmDict::RemoveEntry(TagKey key) {
179 if(KeyHt.count(key) == 1) {
180 gdcmDictEntry* EntryToDelete = KeyHt.find(key)->second;
182 delete EntryToDelete;
186 dbg.Verbose(1, "gdcmDict::RemoveEntry unfound entry", key.c_str());
198 int gdcmDict::RemoveEntry (guint16 group, guint16 element) {
199 return( RemoveEntry(gdcmDictEntry::TranslateToKey(group, element)) );