]> Creatis software - gdcm.git/blob - src/gdcmDocEntry.cxx
about compile errors
[gdcm.git] / src / gdcmDocEntry.cxx
1 // gdcmDocEntry.cxx
2 //-----------------------------------------------------------------------------
3 //
4 #include "gdcmDocEntry.h"
5 #include "gdcmTS.h"
6 #include "gdcmGlobal.h"
7 #include "gdcmUtil.h"
8
9 #include <iomanip> // for std::ios::left, ...
10
11
12 #define MAX_SIZE_PRINT_ELEMENT_VALUE 64
13
14 //-----------------------------------------------------------------------------
15 // Constructor / Destructor
16 /**
17  * \ingroup gdcmDocEntry
18  * \brief   Constructor from a given gdcmDictEntry
19  * @param   in Pointer to existing dictionary entry
20  */
21 gdcmDocEntry::gdcmDocEntry(gdcmDictEntry* in) {
22    ImplicitVR = false;
23    entry = in;
24 }
25
26 //-----------------------------------------------------------------------------
27 // Print
28 /**
29  * \ingroup gdcmDocEntry
30  * \brief   canonical Printer
31  */
32 void gdcmDocEntry::Print(std::ostream & os) {
33
34 // TODO : (no more chained list ...)
35
36 /*
37    size_t o;
38    unsigned short int g, e;
39    char st[20];
40    TSKey v;
41    std::string d2, vr;
42    gdcmTS * ts = gdcmGlobal::GetTS();
43    std::ostringstream s;
44    guint32 lgth;
45    char greltag[10];  //group element tag
46
47    g  = GetGroup();
48    e  = GetElement();
49    v  = GetValue();
50    o  = GetOffset();
51    vr = GetVR();
52    sprintf(greltag,"%04x|%04x ",g,e);           
53    s << greltag ;
54        
55    d2 = CreateCleanString(v);  // replace non printable characters by '.'
56    if (printLevel>=2) { 
57       s << "lg : ";
58       lgth = GetReadLength(); // ReadLength, as opposed to UsableLength
59       if (lgth == 0xffffffff) {
60          sprintf(st,"x(ffff)");  // I said : "x(ffff)" !
61          s.setf(std::ios::left);
62          s << std::setw(10-strlen(st)) << " ";  
63          s << st << " ";
64          s.setf(std::ios::left);
65          s << std::setw(8) << "-1";      
66       } else {
67          sprintf(st,"x(%x)",lgth);
68          s.setf(std::ios::left);
69          s << std::setw(10-strlen(st)) << " ";  
70          s << st << " ";
71          s.setf(std::ios::left);
72          s << std::setw(8) << lgth; 
73       }
74       s << " Off.: ";
75       sprintf(st,"x(%x)",o); 
76       s << std::setw(10-strlen(st)) << " ";
77       s << st << " ";
78       s << std::setw(8) << o; 
79    }
80
81    s << "[" << vr  << "] ";
82
83    if (printLevel>=1) {      
84       s.setf(std::ios::left);
85       s << std::setw(66-GetName().length()) << " ";
86    }
87     
88    s << "[" << GetName()<< "]";
89
90    if (voidArea != NULL) {
91        s << " [gdcm::Non String Data Loaded in Unsecure Area (" 
92          << GetLength() << ") ]";
93    } 
94    
95    else {             
96       if( (GetLength()<MAX_SIZE_PRINT_ELEMENT_VALUE) || 
97           (printLevel>=3)  || 
98           (d2.find("gdcm::NotLoaded.") < d2.length()) )
99          s << " [" << d2 << "]";
100       else 
101          s << " [gdcm::too long for print (" << GetLength() << ") ]";
102    }
103    
104    // Display the UID value (instead of displaying only the rough code)  
105    if (g == 0x0002) {  // Any more to be displayed ?
106       if ( (e == 0x0010) || (e == 0x0002) )
107          s << "  ==>\t[" << ts->GetValue(v) << "]";
108    } else {
109       if (g == 0x0008) {
110          if ( (e == 0x0016) || (e == 0x1150)  )
111             s << "  ==>\t[" << ts->GetValue(v) << "]";
112       } else {
113          if (g == 0x0004) {
114             if ( (e == 0x1510) || (e == 0x1512)  )
115                s << "  ==>\t[" << ts->GetValue(v) << "]";
116          }     
117       }
118    }
119    //if (e == 0x0000) {        // elem 0x0000 --> group length 
120    if ( (vr == "UL") || (vr == "US") || (vr == "SL") || (vr == "SS") ) {
121       if (v == "4294967295") // to avoid troubles in convertion 
122          sprintf (st," x(ffffffff)");
123       else {
124          if ( GetLength() !=0 )        
125             sprintf(st," x(%x)", atoi(v.c_str()));//FIXME
126          else
127           sprintf(st," "); 
128       }
129       s << st;
130    }
131    s << std::endl;
132    os << s.str();
133    
134    */
135 }
136
137 //-----------------------------------------------------------------------------
138 // Public
139
140 /**
141  * \ingroup gdcmDocEntry
142  * \brief   Gets the full length of the DocEntry (not only value length)
143  */
144 guint32 gdcmDocEntry::GetFullLength(void) {
145    guint32 l;
146    l = GetLength();
147    if ( IsImplicitVR() ) 
148       l = l + 8;  // 2 (gr) + 2 (el) + 4 (lgth) 
149    else    
150       if ( GetVR()=="OB" || GetVR()=="OW" || GetVR()=="SQ" )
151          l = l + 12; // 2 (gr) + 2 (el) + 2 (vr) + 2 (unused) + 4 (lgth)
152       else
153          l = l + 8;  // 2 (gr) + 2 (el) + 2 (vr) + 2 (lgth)
154    return(l);
155 }
156
157 /**
158  * \ingroup gdcmDocEntry
159  * \brief   Copies all the attributes from an other DocEntry 
160  */
161
162 void gdcmDocEntry::Copy (gdcmDocEntry* e) {
163    this->entry        = e->entry;
164    this->UsableLength = e->UsableLength;
165    this->ReadLength   = e->ReadLength;
166    this->ImplicitVR   = e->ImplicitVR;
167    this->Offset       = e->Offset;
168    this->printLevel   = e->printLevel;
169    this->SQDepthLevel = e->SQDepthLevel;      
170 }
171
172 //-----------------------------------------------------------------------------
173 // Protected
174
175 //-----------------------------------------------------------------------------
176 // Private
177
178 //-----------------------------------------------------------------------------