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 )
20 * @param FileName from which to build the dictionary.
22 gdcmDict::gdcmDict(std::string & FileName) {
23 std::ifstream from(FileName.c_str());
24 dbg.Error(!from, "gdcmDict::gdcmDict: can't open dictionary",
26 guint16 group, element;
27 // CLEANME : use defines for all those constants
34 from >> std::hex >> group >> element;
36 from.getline(buff, 256, ' ');
39 from.getline(buff, 256, ' ');
41 from.getline(buff, 256, '\n');
43 gdcmDictEntry * newEntry = new gdcmDictEntry(group, element,
45 // FIXME: use AddNewEntry
46 NameHt[name] = newEntry;
47 KeyHt[gdcmDictEntry::TranslateToKey(group, element)] = newEntry;
56 gdcmDict::~gdcmDict() {
57 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) {
58 gdcmDictEntry* EntryToDelete = tag->second;
63 // Since AddNewEntry adds symetrical in both KeyHt and NameHT we can
64 // assume all the pointed gdcmDictEntries are already cleaned-up when
74 void gdcmDict::Print(std::ostream& os) {
80 * \brief Print all the dictionary entries contained in this dictionary.
81 * Entries will be sorted by tag i.e. the couple (group, element).
82 * @param os The output stream to be written to.
84 void gdcmDict::PrintByKey(std::ostream& os) {
85 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag){
87 os << "(" << hex << tag->second->GetGroup() << ',';
88 os << hex << tag->second->GetElement() << ") = " << dec;
89 os << tag->second->GetVR() << ", ";
90 os << tag->second->GetFourth() << ", ";
91 os << 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 for (TagNameHT::iterator tag = NameHt.begin(); tag != NameHt.end(); ++tag){
104 os << tag->second->GetName() << ",";
105 os << tag->second->GetVR() << ", ";
106 os << tag->second->GetFourth() << ", ";
107 os << "(" << std::hex << tag->second->GetGroup() << ',';
108 os << std::hex << tag->second->GetElement() << ") = " << dec << std::endl;
114 * \brief Get the dictionnary entry identified by a given tag (group,element)
115 * @param group group of the entry to be found
116 * @param element element of the entry to be found
117 * @return the corresponding dictionnary entry when existing, NULL otherwise
119 gdcmDictEntry * gdcmDict::GetTagByNumber(guint16 group, guint16 element) {
120 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
121 if ( ! KeyHt.count(key))
122 return (gdcmDictEntry*)0;
123 return KeyHt.find(key)->second;
128 * \brief Get the dictionnary entry identified by it's name.
129 * @param name element of the ElVal to modify
130 * @return the corresponding dictionnary entry when existing, NULL otherwise
132 gdcmDictEntry * gdcmDict::GetTagByName(TagName name) {
133 if ( ! NameHt.count(name))
134 return (gdcmDictEntry*)0;
135 return NameHt.find(name)->second;
144 int gdcmDict::ReplaceEntry(gdcmDictEntry* NewEntry) {
145 if ( RemoveEntry(NewEntry->gdcmDictEntry::GetKey()) ) {
146 KeyHt[ NewEntry->GetKey()] = NewEntry;
158 int gdcmDict::AddNewEntry(gdcmDictEntry* NewEntry) {
160 key = NewEntry->GetKey();
162 if(KeyHt.count(key) == 1) {
163 dbg.Verbose(1, "gdcmDict::AddNewEntry already present", key.c_str());
166 KeyHt[NewEntry->GetKey()] = NewEntry;
177 int gdcmDict::RemoveEntry(TagKey key) {
178 if(KeyHt.count(key) == 1) {
179 gdcmDictEntry* EntryToDelete = KeyHt.find(key)->second;
181 delete EntryToDelete;
185 dbg.Verbose(1, "gdcmDict::RemoveEntry unfound entry", key.c_str());
197 int gdcmDict::RemoveEntry (guint16 group, guint16 element) {
198 return( RemoveEntry(gdcmDictEntry::TranslateToKey(group, element)) );