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