]> Creatis software - gdcm.git/blob - src/gdcmElValSet.cxx
Ajout fonctions
[gdcm.git] / src / gdcmElValSet.cxx
1 // gdcmElValSet.cxx
2
3 #include "gdcm.h"
4 #include "gdcmUtil.h"
5
6 TagElValueHT & ElValSet::GetTagHt(void) {
7         return tagHt;
8 }
9
10 void ElValSet::Add(ElValue * newElValue) {
11         tagHt[newElValue->GetKey()]   = newElValue;
12         NameHt[newElValue->GetName()] = newElValue;
13 }
14
15 void ElValSet::Print(ostream & os) {
16         for (TagElValueHT::iterator tag = tagHt.begin();
17                   tag != tagHt.end();
18                   ++tag){
19                 os << tag->first << ": ";
20                 os << "[" << tag->second->GetValue() << "]";
21                 os << "[" << tag->second->GetName()  << "]";
22                 os << "[" << tag->second->GetVR()    << "]" << endl;
23         }
24 }
25  
26
27 int ElValSet::Write(FILE * _fp) {
28
29 // ATTENTION : fonction non terminée (commitée a titre de precaution)
30
31         guint16 gr, el;
32         guint32 lgr;
33         const char * val;
34         
35         // A FAIRE :
36         // parcourir la table pour recalculer la longueur des 'elements 0x0000'
37         // au cas ou un tag ai été ajouté par rapport à ce qui a été lu
38         // dans l'image native
39         //
40         // cf : code IdDcmWriteFile
41         
42 /*      
43         for (TagElValueHT::iterator tag = tagHt.begin();
44                   tag != tagHt.end();
45                   ++tag){
46
47
48         }
49 */
50         // resteront à tester les echecs en écriture
51         for (TagElValueHT::iterator tag = tagHt.begin();
52                   tag != tagHt.end();
53                   ++tag){
54
55                 // Question :
56                 // peut-on se passer des affectations?
57                 // - passer l'adresse du resultat d'une fonction (???)
58                 // - acceder au champ sans passer par un accesseur ?
59                 gr =  tag->second->GetGroup();
60                 el =  tag->second->GetElement();
61                 lgr = tag->second->GetLength();
62                 val = tag->second->GetValue().c_str();
63                 
64                 fwrite ( &gr,(size_t)2 ,(size_t)1 ,_fp);        //group
65                 fwrite ( &el,(size_t)2 ,(size_t)1 ,_fp);        //element
66                 
67                 //fwrite ( tag->second->GetVR(),(size_t)2 ,(size_t)1 ,_fp);     //VR
68                 // voir pb lgr  + VR
69                 
70                 fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp);                       //lgr
71                  
72                 // ATTENTION
73                 // voir pb des int16 et int32 : les identifier, les convertir, modifier la longueur
74                 // ou alors stocker la valeur 16 ou 32 bits, + un indicateur : char, int16, int32
75                 
76                 fwrite ( val,(size_t)lgr ,(size_t)1 ,_fp); //valeur Elem
77         }
78         return(1);
79 }
80
81
82
83 void ElValSet::PrintByName(ostream & os) {
84         for (TagElValueNameHT::iterator tag = NameHt.begin();
85                   tag != NameHt.end();
86                   ++tag){
87                 os << tag->first << ": ";
88                 os << "[" << tag->second->GetValue() << "]";
89                 os << "[" << tag->second->GetKey()   << "]";
90                 os << "[" << tag->second->GetVR()    << "]" << endl;
91         }
92 }
93
94 ElValue* ElValSet::GetElementByNumber(guint32 group, guint32 element) {
95         TagKey key = gdcmDictEntry::TranslateToKey(group, element);
96         if ( ! tagHt.count(key))
97                 return (ElValue*)0;
98         if (tagHt.count(key) > 1)
99                 dbg.Verbose(0, "ElValSet::GetElementByNumber",
100                             "multiple entries for this key (FIXME) !");
101         return tagHt.find(key)->second;
102 }
103
104 ElValue* ElValSet::GetElementByName(string TagName) {
105    if ( ! NameHt.count(TagName))
106       return (ElValue*)0;
107    if (NameHt.count(TagName) > 1)
108       dbg.Verbose(0, "ElValSet::GetElement",
109                   "multipe entries for this key (FIXME) !");
110    return NameHt.find(TagName)->second;
111 }
112
113 string ElValSet::GetElValueByNumber(guint32 group, guint32 element) {
114         TagKey key = gdcmDictEntry::TranslateToKey(group, element);
115         if ( ! tagHt.count(key))
116                 return "gdcm::Unfound";
117         if (tagHt.count(key) > 1)
118                 dbg.Verbose(0, "ElValSet::GetElValueByNumber",
119                             "multiple entries for this key (FIXME) !");
120         return tagHt.find(key)->second->GetValue();
121 }
122
123 int ElValSet::SetElValueByNumber(string content, guint32 group, guint32 element) {
124         TagKey key = gdcmDictEntry::TranslateToKey(group, element);
125         if ( ! tagHt.count(key))
126                 return 0;
127         if (tagHt.count(key) > 1) {
128                 dbg.Verbose(0, "ElValSet::SetElValueByNumber",
129                             "multiple entries for this key (FIXME) !");
130                 return (0); 
131         }
132                                        
133         tagHt[key]->SetValue(content);
134         return(1);              
135 }
136
137 string ElValSet::GetElValueByName(string TagName) {
138         if ( ! NameHt.count(TagName))
139                 return "gdcm::Unfound";
140         if (NameHt.count(TagName) > 1)
141                 dbg.Verbose(0, "ElValSet::GetElValue",
142                             "multipe entries for this key (FIXME) !");
143         return NameHt.find(TagName)->second->GetValue();
144 }
145
146 int ElValSet::SetElValueByName(string content, string TagName) {
147         if ( ! NameHt.count(TagName))
148                 return 0;
149         if (NameHt.count(TagName) > 1) {
150                 dbg.Verbose(0, "ElValSet::SetElValue",
151                             "multipe entries for this key (FIXME) !");
152                 return 0;
153         }
154         NameHt.find(TagName)->second->SetValue(content);
155 }
156
157