]> Creatis software - gdcm.git/blob - src/gdcmHeaderEntry.cxx
in ordrer to display the *stored* length when xxx.Print()
[gdcm.git] / src / gdcmHeaderEntry.cxx
1 // gdcmHeaderEntry.cxx
2 //-----------------------------------------------------------------------------
3 //
4 #include "gdcmHeaderEntry.h"
5 #include "gdcmTS.h"
6 #include "gdcmUtil.h"
7
8 #ifdef GDCM_NO_ANSI_STRING_STREAM
9 #  include <strstream>
10 #  define  ostringstream ostrstream
11 # else
12 #  include <sstream>
13 #endif
14 #include <iomanip> // for std::ios::left, ...
15
16 //-----------------------------------------------------------------------------
17 // Constructor / Destructor
18 /**
19  * \ingroup gdcmHeaderEntry
20  * \brief   Constructor from a given gdcmDictEntry
21  * @param   in Pointer to existing dictionary entry
22  */
23 gdcmHeaderEntry::gdcmHeaderEntry(gdcmDictEntry* in) {
24         ImplicitVR = false;
25         entry = in;
26 }
27
28 //-----------------------------------------------------------------------------
29 // Print
30
31 void gdcmHeaderEntry::Print(std::ostream & os) {
32    size_t o;
33    unsigned short int g, e;
34    char st[20];
35    TSKey v;
36    std::string d2;
37    gdcmTS * ts = gdcmGlobal::GetTS();
38    std::ostringstream s;
39    guint32 lgth;
40    char greltag[10];  //group element tag
41       
42    g = GetGroup();
43    e = GetElement();
44    v = GetValue();
45    o = GetOffset();
46    sprintf(greltag,"%04x|%04x ",g,e);           
47    d2 = _CreateCleanString(v);  // replace non printable characters by '.'
48    s << greltag ;
49        
50    if (printLevel>=2) { 
51       s << "lg : ";
52       lgth = GetReadLength();
53       if (lgth == 0xffffffff) {
54          sprintf(st,"x(ffff)");  // I said : "x(ffff)" !
55          s.setf(std::ios::left);
56          s << std::setw(10-strlen(st)) << " ";  
57          s << st << " ";
58          s.setf(std::ios::left);
59          s << std::setw(8) << "-1";      
60       } else {
61          sprintf(st,"x(%x)",lgth);
62          s.setf(std::ios::left);
63          s << std::setw(10-strlen(st)) << " ";  
64          s << st << " ";
65          s.setf(std::ios::left);
66          s << std::setw(8) << lgth; 
67       }
68       s << " Off.: ";
69       sprintf(st,"x(%x)",o); 
70       s << std::setw(10-strlen(st)) << " ";
71       s << st << " ";
72       s << std::setw(8) << o; 
73    }
74
75    s << "[" << GetVR()  << "] ";
76
77    if (printLevel>=1) {      
78       s.setf(std::ios::left);
79       s << std::setw(66-GetName().length()) << " ";              
80    } 
81      
82    s << "[" << GetName()<< "]";       
83    s << " [" << d2 << "]";
84     // Display the UID value (instead of displaying the rough code)  
85    if (g == 0x0002) {  // Any more to be displayed ?
86       if ( (e == 0x0010) || (e == 0x0002) )        
87          s << "  ==>\t[" << ts->GetValue(v) << "]";   
88    } else {
89       if (g == 0x0008) {
90          if ( (e == 0x0016) || (e == 0x1150)  )            
91             s << "  ==>\t[" << ts->GetValue(v) << "]"; 
92       }
93    } 
94    if (e == 0x0000) {        // elem 0x0000 --> group length 
95       if (v == "4294967295") // to avoid troubles in convertion 
96          sprintf (st," x(ffffffff)");
97       else      
98          sprintf(st," x(%08x)",atoi(v.c_str()));
99       s << st;
100    }                     
101    s << std::endl;
102    os << s.str();
103 }
104
105 //-----------------------------------------------------------------------------
106 // Public
107
108 //-----------------------------------------------------------------------------
109 // Protected
110
111 //-----------------------------------------------------------------------------
112 // Private
113
114 //-----------------------------------------------------------------------------