7 gdcmDict::gdcmDict(const char* FileName) {
8 std::ifstream from(FileName);
9 dbg.Error(!from, "gdcmDict::gdcmDict: can't open dictionary", FileName);
10 guint16 group, element;
11 // CLEANME : use defines for all those constants
18 from >> hex >> group >> element;
20 from.getline(buff, 256, ' ');
23 from.getline(buff, 256, ' ');
25 from.getline(buff, 256, '\n');
27 gdcmDictEntry * newEntry = new gdcmDictEntry(group, element,
29 NameHt[name] = newEntry;
30 KeyHt[gdcmDictEntry::TranslateToKey(group, element)] = newEntry;
35 void gdcmDict::Print(ostream& os) {
41 * \brief Print all the dictionary entries contained in this dictionary.
42 * Entries will be sorted by tag i.e. the couple (group, element).
43 * @param os The output stream to be written to.
45 void gdcmDict::PrintByKey(ostream& os) {
46 for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag){
48 os << "(" << hex << tag->second->GetGroup() << ',';
49 os << hex << tag->second->GetElement() << ") = " << dec;
50 os << tag->second->GetVR() << ", ";
51 os << tag->second->GetFourth() << ", ";
52 os << tag->second->GetName() << "." << endl;
58 * \brief Print all the dictionary entries contained in this dictionary.
59 * Entries will be sorted by the name of the dictionary entries.
60 * @param os The output stream to be written to.
62 void gdcmDict::PrintByName(ostream& os) {
63 for (TagNameHT::iterator tag = NameHt.begin(); tag != NameHt.end(); ++tag){
65 os << tag->second->GetName() << ",";
66 os << tag->second->GetVR() << ", ";
67 os << tag->second->GetFourth() << ", ";
68 os << "(" << hex << tag->second->GetGroup() << ',';
69 os << hex << tag->second->GetElement() << ") = " << dec << endl;
75 * \brief Get the dictionnary entry identified by a given tag (group,element)
76 * @param group group of the entry to be found
77 * @param element element of the entry to be found
78 * @return the corresponding dictionnary entry when existing, NULL otherwise
80 gdcmDictEntry * gdcmDict::GetTagByKey(guint16 group, guint16 element) {
81 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
82 if ( ! KeyHt.count(key))
83 return (gdcmDictEntry*)0;
84 return KeyHt.find(key)->second;
89 * \brief Get the dictionnary entry identified by it's name.
90 * @param name element of the ElVal to modify
91 * @return the corresponding dictionnary entry when existing, NULL otherwise
93 gdcmDictEntry * gdcmDict::GetTagByName(TagName name) {
94 if ( ! NameHt.count(name))
95 return (gdcmDictEntry*)0;
96 return NameHt.find(name)->second;
99 int gdcmDict::ReplaceEntry(gdcmDictEntry* NewEntry) {
100 if ( RemoveEntry(NewEntry->gdcmDictEntry::GetKey()) ) {
101 KeyHt[ NewEntry->GetKey()] = NewEntry;
107 int gdcmDict::AddNewEntry(gdcmDictEntry* NewEntry) {
110 key = NewEntry->GetKey();
112 if(KeyHt.count(key) == 1) {
113 dbg.Verbose(1, "gdcmDict::AddNewEntry allready present", key.c_str());
116 KeyHt[NewEntry->GetKey()] = NewEntry;
122 int gdcmDict::RemoveEntry(TagKey key) {
123 if(KeyHt.count(key) == 1) {
127 dbg.Verbose(1, "gdcmDict::RemoveEntry unfound entry", key.c_str());
133 int gdcmDict::RemoveEntry (guint16 group, guint16 element) {
134 return( RemoveEntry(gdcmDictEntry::TranslateToKey(group, element)) );