11 * @param FileName from which to build the dictionary.
13 gdcmDict::gdcmDict(std::string & FileName) {
14 std::ifstream from(FileName.c_str());
15 dbg.Error(!from, "gdcmDict::gdcmDict: can't open dictionary",
17 guint16 group, element;
18 // CLEANME : use defines for all those constants
25 from >> std::hex >> group >> element;
27 from.getline(buff, 256, ' ');
30 from.getline(buff, 256, ' ');
32 from.getline(buff, 256, '\n');
34 gdcmDictEntry * newEntry = new gdcmDictEntry(group, element,
36 // FIXME: use AddNewEntry
37 NameHt[name] = newEntry;
38 KeyHt[gdcmDictEntry::TranslateToKey(group, element)] = newEntry;
43 gdcmDict::~gdcmDict() {
44 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) {
45 gdcmDictEntry* EntryToDelete = tag->second;
50 // Since AddNewEntry adds symetrical in both KeyHt and NameHT we can
51 // assume all the pointed gdcmDictEntries are allready cleaned-up when
56 void gdcmDict::Print(std::ostream& os) {
62 * \brief Print all the dictionary entries contained in this dictionary.
63 * Entries will be sorted by tag i.e. the couple (group, element).
64 * @param os The output stream to be written to.
66 void gdcmDict::PrintByKey(std::ostream& os) {
67 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag){
69 os << "(" << hex << tag->second->GetGroup() << ',';
70 os << hex << tag->second->GetElement() << ") = " << dec;
71 os << tag->second->GetVR() << ", ";
72 os << tag->second->GetFourth() << ", ";
73 os << tag->second->GetName() << "." << endl;
79 * \brief Print all the dictionary entries contained in this dictionary.
80 * Entries will be sorted by the name of the dictionary entries.
81 * @param os The output stream to be written to.
83 void gdcmDict::PrintByName(std::ostream& os) {
84 for (TagNameHT::iterator tag = NameHt.begin(); tag != NameHt.end(); ++tag){
86 os << tag->second->GetName() << ",";
87 os << tag->second->GetVR() << ", ";
88 os << tag->second->GetFourth() << ", ";
89 os << "(" << std::hex << tag->second->GetGroup() << ',';
90 os << std::hex << tag->second->GetElement() << ") = " << dec << std::endl;
96 * \brief Get the dictionnary entry identified by a given tag (group,element)
97 * @param group group of the entry to be found
98 * @param element element of the entry to be found
99 * @return the corresponding dictionnary entry when existing, NULL otherwise
101 gdcmDictEntry * gdcmDict::GetTagByNumber(guint16 group, guint16 element) {
102 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
103 if ( ! KeyHt.count(key))
104 return (gdcmDictEntry*)0;
105 return KeyHt.find(key)->second;
110 * \brief Get the dictionnary entry identified by it's name.
111 * @param name element of the ElVal to modify
112 * @return the corresponding dictionnary entry when existing, NULL otherwise
114 gdcmDictEntry * gdcmDict::GetTagByName(TagName name) {
115 if ( ! NameHt.count(name))
116 return (gdcmDictEntry*)0;
117 return NameHt.find(name)->second;
120 int gdcmDict::ReplaceEntry(gdcmDictEntry* NewEntry) {
121 if ( RemoveEntry(NewEntry->gdcmDictEntry::GetKey()) ) {
122 KeyHt[ NewEntry->GetKey()] = NewEntry;
128 int gdcmDict::AddNewEntry(gdcmDictEntry* NewEntry) {
131 key = NewEntry->GetKey();
133 if(KeyHt.count(key) == 1) {
134 dbg.Verbose(1, "gdcmDict::AddNewEntry allready present", key.c_str());
137 KeyHt[NewEntry->GetKey()] = NewEntry;
143 int gdcmDict::RemoveEntry(TagKey key) {
144 if(KeyHt.count(key) == 1) {
145 gdcmDictEntry* EntryToDelete = KeyHt.find(key)->second;
147 delete EntryToDelete;
151 dbg.Verbose(1, "gdcmDict::RemoveEntry unfound entry", key.c_str());
157 int gdcmDict::RemoveEntry (guint16 group, guint16 element) {
158 return( RemoveEntry(gdcmDictEntry::TranslateToKey(group, element)) );