]> Creatis software - gdcm.git/blob - src/gdcmHeaderEntry.cxx
a55933c0502308db78c8532a92faf5ab626e7d67
[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 #define MAX_SIZE_PRINT_ELEMENT_VALUE 64
18
19 //-----------------------------------------------------------------------------
20 // Constructor / Destructor
21 /**
22  * \ingroup gdcmHeaderEntry
23  * \brief   Constructor from a given gdcmDictEntry
24  * @param   in Pointer to existing dictionary entry
25  */
26 gdcmHeaderEntry::gdcmHeaderEntry(gdcmDictEntry* in) {
27         ImplicitVR = false;
28         voidArea = NULL; // unsecure memory area to hold 'non string' values
29         entry = in;
30 }
31
32 //-----------------------------------------------------------------------------
33 // Print
34 void gdcmHeaderEntry::Print(std::ostream & os) {
35    size_t o;
36    unsigned short int g, e;
37    char st[20];
38    TSKey v;
39    std::string d2, vr;
40    gdcmTS * ts = gdcmGlobal::GetTS();
41    std::ostringstream s;
42    guint32 lgth;
43    char greltag[10];  //group element tag
44
45    g  = GetGroup();
46    e  = GetElement();
47    v  = GetValue();
48    o  = GetOffset();
49    vr = GetVR();
50    sprintf(greltag,"%04x|%04x ",g,e);           
51    s << greltag ;
52        
53    d2 = _CreateCleanString(v);  // replace non printable characters by '.'
54    if (printLevel>=2) { 
55       s << "lg : ";
56       lgth = GetReadLength(); // ReadLength, as opposed to UsableLength
57       if (lgth == 0xffffffff) {
58          sprintf(st,"x(ffff)");  // I said : "x(ffff)" !
59          s.setf(std::ios::left);
60          s << std::setw(10-strlen(st)) << " ";  
61          s << st << " ";
62          s.setf(std::ios::left);
63          s << std::setw(8) << "-1";      
64       } else {
65          sprintf(st,"x(%x)",lgth);
66          s.setf(std::ios::left);
67          s << std::setw(10-strlen(st)) << " ";  
68          s << st << " ";
69          s.setf(std::ios::left);
70          s << std::setw(8) << lgth; 
71       }
72       s << " Off.: ";
73       sprintf(st,"x(%x)",o); 
74       s << std::setw(10-strlen(st)) << " ";
75       s << st << " ";
76       s << std::setw(8) << o; 
77    }
78
79    s << "[" << vr  << "] ";
80
81    if (printLevel>=1) {      
82       s.setf(std::ios::left);
83       s << std::setw(66-GetName().length()) << " ";              
84    }
85     
86    s << "[" << GetName()<< "]";
87
88    if (voidArea != NULL) {
89        s << " [gdcm::Non String Data Loaded in Unsecure Area (" 
90          << GetLength() << ") ]";
91    } 
92    
93    else {             
94       if( (GetLength()<MAX_SIZE_PRINT_ELEMENT_VALUE) || 
95           (printLevel>=3)  || 
96           (d2.find("gdcm::NotLoaded.") < d2.length()) )
97          s << " [" << d2 << "]";
98       else 
99          s << " [gdcm::too long for print (" << GetLength() << ") ]";
100    }
101    
102    // Display the UID value (instead of displaying the rough code)  
103    if (g == 0x0002) {  // Any more to be displayed ?
104       if ( (e == 0x0010) || (e == 0x0002) )
105          s << "  ==>\t[" << ts->GetValue(v) << "]";
106    } else {
107       if (g == 0x0008) {
108          if ( (e == 0x0016) || (e == 0x1150)  )
109             s << "  ==>\t[" << ts->GetValue(v) << "]";
110       } else {
111          if (g == 0x0004) {
112             if ( (e == 0x1510) || (e == 0x1512)  )
113                s << "  ==>\t[" << ts->GetValue(v) << "]";
114          }     
115       }
116    }
117    //if (e == 0x0000) {        // elem 0x0000 --> group length 
118    if ( (vr == "UL") || (vr == "US") || (vr == "SL") || (vr == "SS") ) {
119       if (v == "4294967295") // to avoid troubles in convertion 
120          sprintf (st," x(ffffffff)");
121       else      
122          sprintf(st," x(%x)",(unsigned long)atof(v.c_str()));
123       s << st;
124    }
125    s << std::endl;
126    os << s.str();
127 }
128
129 //-----------------------------------------------------------------------------
130 // Public
131
132 //-----------------------------------------------------------------------------
133 // Protected
134
135 //-----------------------------------------------------------------------------
136 // Private
137
138 //-----------------------------------------------------------------------------