]> Creatis software - gdcm.git/blob - src/gdcmDocEntry.cxx
PLEASE : keep on waiting for the final version !
[gdcm.git] / src / gdcmDocEntry.cxx
1 // gdcmDocEntry.cxx
2 //-----------------------------------------------------------------------------
3 //
4
5 #include "gdcmDocEntry.h"
6 #include "gdcmTS.h"
7 #include "gdcmGlobal.h"
8 #include "gdcmUtil.h"
9
10 #include <iomanip> // for std::ios::left, ...
11
12 // CLEAN ME
13 #define MAX_SIZE_PRINT_ELEMENT_VALUE 64
14
15 //-----------------------------------------------------------------------------
16 // Constructor / Destructor
17 /**
18  * \ingroup gdcmDocEntry
19  * \brief   Constructor from a given gdcmDictEntry
20  * @param   in Pointer to existing dictionary entry
21  */
22 gdcmDocEntry::gdcmDocEntry(gdcmDictEntry* in) {
23    ImplicitVR = false;
24    entry = in;
25 }
26
27 void gdcmDocEntry::Print(std::ostream & os) {
28    std::ostringstream s;
29    s << std::endl;
30    PrintCommonPart(os);
31    os << s.str();
32 }
33
34 //-----------------------------------------------------------------------------
35 // Print
36 /**
37  * \ingroup gdcmDocEntry
38  * \brief   Prints the common part of gdcmValEntry, gdcmBinEntry, gdcmSeqEntry
39  */
40 void gdcmDocEntry::PrintCommonPart(std::ostream & os) {
41
42    printLevel=2; // FIXME
43    
44    size_t o;
45    unsigned short int g, e;
46    char st[20];
47    TSKey v;
48    std::string d2, vr;
49    std::ostringstream s;
50    guint32 lgth;
51    char greltag[10];  //group element tag
52
53    g  = GetGroup();
54    e  = GetElement();
55    o  = GetOffset();
56    vr = GetVR();
57    sprintf(greltag,"%04x|%04x ",g,e);           
58    s << greltag ;
59        
60    if (printLevel>=2) { 
61       s << "lg : ";
62       lgth = GetReadLength(); // ReadLength, as opposed to UsableLength
63       if (lgth == 0xffffffff) {
64          sprintf(st,"x(ffff)");  // I said : "x(ffff)" !
65          s.setf(std::ios::left);
66          s << std::setw(10-strlen(st)) << " ";  
67          s << st << " ";
68          s.setf(std::ios::left);
69          s << std::setw(8) << "-1";      
70       } else {
71          sprintf(st,"x(%x)",lgth);
72          s.setf(std::ios::left);
73          s << std::setw(10-strlen(st)) << " ";  
74          s << st << " ";
75          s.setf(std::ios::left);
76          s << std::setw(8) << lgth; 
77       }
78       s << " Off.: ";
79       sprintf(st,"x(%x)",o); 
80       s << std::setw(10-strlen(st)) << " ";
81       s << st << " ";
82       s << std::setw(8) << o; 
83    }
84
85    s << "[" << vr  << "] ";
86
87    if (printLevel>=1) {      
88       s.setf(std::ios::left);
89       s << std::setw(66-GetName().length()) << " ";
90    }
91     
92    s << "[" << GetName()<< "]";
93    os << s.str();      
94 }
95
96 //-----------------------------------------------------------------------------
97 // Public
98
99 /**
100  * \ingroup gdcmDocEntry
101  * \brief   Gets the full length of the elementary DocEntry (not only value length)
102  */
103 guint32 gdcmDocEntry::GetFullLength(void) {
104    guint32 l;
105    l = GetReadLength();
106    if ( IsImplicitVR() ) 
107       l = l + 8;  // 2 (gr) + 2 (el) + 4 (lgth) 
108    else    
109       if ( GetVR()=="OB" || GetVR()=="OW" || GetVR()=="SQ" )
110          l = l + 12; // 2 (gr) + 2 (el) + 2 (vr) + 2 (unused) + 4 (lgth)
111       else
112          l = l + 8;  // 2 (gr) + 2 (el) + 2 (vr) + 2 (lgth)
113    return(l);
114 }
115
116 /**
117  * \ingroup gdcmDocEntry
118  * \brief   Copies all the attributes from an other DocEntry 
119  */
120
121 void gdcmDocEntry::Copy (gdcmDocEntry* e) {
122    this->entry        = e->entry;
123    this->UsableLength = e->UsableLength;
124    this->ReadLength   = e->ReadLength;
125    this->ImplicitVR   = e->ImplicitVR;
126    this->Offset       = e->Offset;
127    this->printLevel   = e->printLevel;
128    // TODO : remove gdcmDocEntry SQDepth
129 }
130
131 bool gdcmDocEntry::isItemDelimitor() {
132    if ( (GetGroup() == 0xfffe) && (GetElement() == 0xe00d) )
133       return true;
134    else
135       return false;      
136 }
137
138 bool gdcmDocEntry::isSequenceDelimitor() {
139    if (GetGroup() == 0xfffe && GetElement() == 0xe0dd)
140       return true;
141    else
142       return false; 
143 }
144
145 //-----------------------------------------------------------------------------
146 // Protected
147
148
149 //-----------------------------------------------------------------------------
150 // Private
151
152 //-----------------------------------------------------------------------------