]> Creatis software - gdcm.git/blob - src/gdcmValEntry.cxx
e2579ee7cbb956c63dc57ba17b7d2945c7456c21
[gdcm.git] / src / gdcmValEntry.cxx
1 // gdcmValEntry.cxx
2 //-----------------------------------------------------------------------------
3 //
4 #include "gdcmValEntry.h"
5 #include "gdcmTS.h"
6 #include "gdcmGlobal.h"
7 #include "gdcmUtil.h"
8
9 // CLEAN ME
10 #define MAX_SIZE_PRINT_ELEMENT_VALUE 128
11
12 //-----------------------------------------------------------------------------
13 // Constructor / Destructor
14 /**
15  * \ingroup gdcmValEntry
16  * \brief   Constructor from a given gdcmDictEntry
17  * @param   e Pointer to existing dictionary entry
18  */
19 gdcmValEntry::gdcmValEntry(gdcmDictEntry* e) : gdcmDocEntry(e) {
20    voidArea = NULL;
21 }
22
23 /**
24  * \brief   Canonical destructor.
25  */
26 gdcmValEntry::~gdcmValEntry (void) {
27    if (!voidArea)  // will be in BinEntry
28       free(voidArea);
29 }
30
31
32 //-----------------------------------------------------------------------------
33 // Print
34 /**
35  * \ingroup gdcmValEntry
36  * \brief   canonical Printer
37  */
38 void gdcmValEntry::Print(std::ostream & os) { 
39
40    std::ostringstream s; 
41    size_t o;
42    unsigned short int g, e;
43    char st[20];
44    TSKey v;
45    std::string d2, vr;
46      
47    PrintCommonPart(os); 
48
49    g  = GetGroup();
50    
51    if (g == 0xfffe) {
52       s << std::endl;
53       os << s.str(); 
54       return;  // just to avoid identing all the remaining code     
55    }
56    
57    e  = GetElement();
58    vr = GetVR();
59    gdcmTS * ts = gdcmGlobal::GetTS();
60     
61    if (voidArea != NULL) { // should be moved in gdcmBinEntry Printer (when any)
62        s << " [gdcm::Non String Data Loaded in Unsecure Area (" 
63          << GetLength() << ") ]";
64    } 
65    
66    else {
67       v  = GetValue();  // not applicable for SQ ...     
68       d2 = CreateCleanString(v);  // replace non printable characters by '.'            
69       if( (GetLength()<=MAX_SIZE_PRINT_ELEMENT_VALUE) || 
70           (printLevel>=3)  || 
71           (d2.find("gdcm::NotLoaded.") < d2.length()) )
72          s << " [" << d2 << "]";
73       else 
74          s << " [gdcm::too long for print (" << GetLength() << ") ]";
75    }
76    
77    // Display the UID value (instead of displaying only the rough code)  
78    if (g == 0x0002) {  // Any more to be displayed ?
79       if ( (e == 0x0010) || (e == 0x0002) )
80          s << "  ==>\t[" << ts->GetValue(v) << "]";
81    } else {
82       if (g == 0x0008) {
83          if ( (e == 0x0016) || (e == 0x1150)  )
84             s << "  ==>\t[" << ts->GetValue(v) << "]";
85       } else {
86          if (g == 0x0004) {
87             if ( (e == 0x1510) || (e == 0x1512)  )
88                s << "  ==>\t[" << ts->GetValue(v) << "]";
89          }     
90       }
91    }
92    //if (e == 0x0000) {        // elem 0x0000 --> group length 
93    if ( (vr == "UL") || (vr == "US") || (vr == "SL") || (vr == "SS") ) {
94       if (v == "4294967295") // to avoid troubles in convertion 
95          sprintf (st," x(ffffffff)");
96       else {
97          if ( GetLength() !=0 )        
98             sprintf(st," x(%x)", atoi(v.c_str()));//FIXME
99          else
100           sprintf(st," "); 
101       }
102       s << st;
103    }
104         
105    s << std::endl;
106    os << s.str();   
107 }
108  
109
110 //-----------------------------------------------------------------------------
111 // Public
112
113 //-----------------------------------------------------------------------------
114 // Protected
115
116 //-----------------------------------------------------------------------------
117 // Private
118
119 //-----------------------------------------------------------------------------