]> Creatis software - gdcm.git/blob - src/gdcmValEntry.cxx
PLEASE : keep on waiting for the final version !
[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
36 /**
37  * \ingroup gdcmValEntry
38  * \brief   canonical Printer
39  */
40 void gdcmValEntry::Print(std::ostream & os) { 
41
42    std::ostringstream s; 
43    size_t o;
44    unsigned short int g, e;
45    char st[20];
46    TSKey v;
47    std::string d2, vr;
48      
49    PrintCommonPart(os); 
50
51    g  = GetGroup();
52    
53    if (g == 0xfffe) {
54       s << std::endl;
55       os << s.str(); 
56       return;  // just to avoid identing all the remaining code     
57    }
58    
59    e  = GetElement();
60    vr = GetVR();
61    gdcmTS * ts = gdcmGlobal::GetTS();
62     
63    if (voidArea != NULL) { // should be moved in gdcmBinEntry Printer (when any)
64        s << " [gdcm::Non String Data Loaded in Unsecure Area (" 
65          << GetLength() << ") ]";
66    } 
67    
68    else {
69       v  = GetValue();  // not applicable for SQ ...     
70       d2 = CreateCleanString(v);  // replace non printable characters by '.'            
71       if( (GetLength()<=MAX_SIZE_PRINT_ELEMENT_VALUE) || 
72           (printLevel>=3)  || 
73           (d2.find("gdcm::NotLoaded.") < d2.length()) )
74          s << " [" << d2 << "]";
75       else 
76          s << " [gdcm::too long for print (" << GetLength() << ") ]";
77    }
78    
79    // Display the UID value (instead of displaying only the rough code)  
80    if (g == 0x0002) {  // Any more to be displayed ?
81       if ( (e == 0x0010) || (e == 0x0002) )
82          s << "  ==>\t[" << ts->GetValue(v) << "]";
83    } else {
84       if (g == 0x0008) {
85          if ( (e == 0x0016) || (e == 0x1150)  )
86             s << "  ==>\t[" << ts->GetValue(v) << "]";
87       } else {
88          if (g == 0x0004) {
89             if ( (e == 0x1510) || (e == 0x1512)  )
90                s << "  ==>\t[" << ts->GetValue(v) << "]";
91          }     
92       }
93    }
94    //if (e == 0x0000) {        // elem 0x0000 --> group length 
95    if ( (vr == "UL") || (vr == "US") || (vr == "SL") || (vr == "SS") ) {
96       if (v == "4294967295") // to avoid troubles in convertion 
97          sprintf (st," x(ffffffff)");
98       else {
99          if ( GetLength() !=0 )        
100             sprintf(st," x(%x)", atoi(v.c_str()));//FIXME
101          else
102           sprintf(st," "); 
103       }
104       s << st;
105    }
106         
107    s << std::endl;
108    os << s.str();   
109 }
110  
111
112 //-----------------------------------------------------------------------------
113 // Public
114
115 //-----------------------------------------------------------------------------
116 // Protected
117
118 //-----------------------------------------------------------------------------
119 // Private
120
121 //-----------------------------------------------------------------------------