]> Creatis software - gdcm.git/blob - src/gdcmElValSet.cxx
ajout quelques fonctions pour WriteDcm
[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         guint16 gr, el;
30         guint32 lgr;
31         const char * val;
32         // restent à tester les echecs en écriture
33         for (TagElValueHT::iterator tag = tagHt.begin();
34                   tag != tagHt.end();
35                   ++tag){
36
37                 // Question :
38                 // peut-on se passer des affectations?
39                 // - passer l'adresse du resultat d'une fonction (???)
40                 // - acceder au champ sans passer par un accesseur ?
41                 gr = tag->second->GetGroup();
42                 el = tag->second->GetElement();
43                 lgr = tag->second->GetLength();
44                 val = tag->second->GetValue().c_str();
45                 
46                 fwrite ( &gr,(size_t)2 ,(size_t)1 ,_fp);        //group
47                 fwrite ( &el,(size_t)2 ,(size_t)1 ,_fp);        //element
48                 //fwrite ( tag->second->GetVR(),(size_t)2 ,(size_t)1 ,_fp);     //VR
49                 
50                 // voir pb lgr  + VR
51                 fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp);                       //lgr 
52                 // voir pb des int16 et int32 : les identifier, les convertir, modifier la longueur
53                 fwrite ( val,(size_t)lgr ,(size_t)1 ,_fp); //valeur Elem
54         }
55         return(1);
56 }
57 void ElValSet::PrintByName(ostream & os) {
58         for (TagElValueNameHT::iterator tag = NameHt.begin();
59                   tag != NameHt.end();
60                   ++tag){
61                 os << tag->first << ": ";
62                 os << "[" << tag->second->GetValue() << "]";
63                 os << "[" << tag->second->GetKey()  << "]";
64                 os << "[" << tag->second->GetVR()    << "]" << endl;
65         }
66 }
67
68 ElValue* ElValSet::GetElementByNumber(guint32 group, guint32 element) {
69         TagKey key = gdcmDictEntry::TranslateToKey(group, element);
70         if ( ! tagHt.count(key))
71                 return (ElValue*)0;
72         if (tagHt.count(key) > 1)
73                 dbg.Verbose(0, "ElValSet::GetElementByNumber",
74                             "multiple entries for this key (FIXME) !");
75         return tagHt.find(key)->second;
76 }
77
78 ElValue* ElValSet::GetElementByName(string TagName) {
79    if ( ! NameHt.count(TagName))
80       return (ElValue*)0;
81    if (NameHt.count(TagName) > 1)
82       dbg.Verbose(0, "ElValSet::GetElement",
83                   "multipe entries for this key (FIXME) !");
84    return NameHt.find(TagName)->second;
85 }
86
87 string ElValSet::GetElValueByNumber(guint32 group, guint32 element) {
88         TagKey key = gdcmDictEntry::TranslateToKey(group, element);
89         if ( ! tagHt.count(key))
90                 return "gdcm::Unfound";
91         if (tagHt.count(key) > 1)
92                 dbg.Verbose(0, "ElValSet::GetElValueByNumber",
93                             "multiple entries for this key (FIXME) !");
94         return tagHt.find(key)->second->GetValue();
95 }
96
97 int ElValSet::SetElValueByNumber(string content, guint32 group, guint32 element) {
98         TagKey key = gdcmDictEntry::TranslateToKey(group, element);
99         if ( ! tagHt.count(key))
100                 return 0;
101         if (tagHt.count(key) > 1) {
102                 dbg.Verbose(0, "ElValSet::SetElValueByNumber",
103                             "multiple entries for this key (FIXME) !");
104                 return (0); 
105         }
106                                        
107         tagHt[key]->SetValue(content);
108         return(1);              
109 }
110
111 string ElValSet::GetElValueByName(string TagName) {
112         if ( ! NameHt.count(TagName))
113                 return "gdcm::Unfound";
114         if (NameHt.count(TagName) > 1)
115                 dbg.Verbose(0, "ElValSet::GetElValue",
116                             "multipe entries for this key (FIXME) !");
117         return NameHt.find(TagName)->second->GetValue();
118 }
119
120 int ElValSet::SetElValueByName(string content, string TagName) {
121         if ( ! NameHt.count(TagName))
122                 return 0;
123         if (NameHt.count(TagName) > 1) {
124                 dbg.Verbose(0, "ElValSet::SetElValue",
125                             "multipe entries for this key (FIXME) !");
126                 return 0;
127         }
128         NameHt.find(TagName)->second->SetValue(content);
129 }
130
131