]> Creatis software - gdcm.git/blob - src/gdcmDocEntry.cxx
Still in a debugging status.
[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 /**
28  * \ingroup gdcmDocEntry
29  * \brief   Canonical Printer
30  * @param   os ostream we want to print in
31  */
32 void gdcmDocEntry::Print(std::ostream & os) {
33    std::ostringstream s;
34    s << std::endl;
35    PrintCommonPart(os);
36    os << s.str();
37 }
38
39 //-----------------------------------------------------------------------------
40 // Print
41 /**
42  * \ingroup gdcmDocEntry
43  * \brief   Prints the common part of gdcmValEntry, gdcmBinEntry, gdcmSeqEntry
44  */
45 void gdcmDocEntry::PrintCommonPart(std::ostream & os) {
46
47    printLevel=2; // FIXME
48    
49    size_t o;
50    unsigned short int g, e;
51    char st[20];
52    TSKey v;
53    std::string d2, vr;
54    std::ostringstream s;
55    guint32 lgth;
56    char greltag[10];  //group element tag
57
58    g  = GetGroup();
59    e  = GetElement();
60    o  = GetOffset();
61    vr = GetVR();
62    sprintf(greltag,"%04x|%04x ",g,e);           
63    s << greltag ;
64        
65    if (printLevel>=2) { 
66       s << "lg : ";
67       lgth = GetReadLength(); // ReadLength, as opposed to UsableLength
68       if (lgth == 0xffffffff) {
69          sprintf(st,"x(ffff)");  // I said : "x(ffff)" !
70          s.setf(std::ios::left);
71          s << std::setw(10-strlen(st)) << " ";  
72          s << st << " ";
73          s.setf(std::ios::left);
74          s << std::setw(8) << "-1";      
75       } else {
76          sprintf(st,"x(%x)",lgth);
77          s.setf(std::ios::left);
78          s << std::setw(10-strlen(st)) << " ";  
79          s << st << " ";
80          s.setf(std::ios::left);
81          s << std::setw(8) << lgth; 
82       }
83       s << " Off.: ";
84       sprintf(st,"x(%x)",o); 
85       s << std::setw(10-strlen(st)) << " ";
86       s << st << " ";
87       s << std::setw(8) << o; 
88    }
89
90    s << "[" << vr  << "] ";
91
92    if (printLevel>=1) {      
93       s.setf(std::ios::left);
94       s << std::setw(66-GetName().length()) << " ";
95    }
96     
97    s << "[" << GetName()<< "]";
98    os << s.str();      
99 }
100
101 //-----------------------------------------------------------------------------
102 // Public
103
104 /**
105  * \ingroup gdcmDocEntry
106  * \brief   Gets the full length of the elementary DocEntry (not only value length)
107  */
108 guint32 gdcmDocEntry::GetFullLength(void) {
109    guint32 l;
110    l = GetReadLength();
111    if ( IsImplicitVR() ) 
112       l = l + 8;  // 2 (gr) + 2 (el) + 4 (lgth) 
113    else    
114       if ( GetVR()=="OB" || GetVR()=="OW" || GetVR()=="SQ" )
115          l = l + 12; // 2 (gr) + 2 (el) + 2 (vr) + 2 (unused) + 4 (lgth)
116       else
117          l = l + 8;  // 2 (gr) + 2 (el) + 2 (vr) + 2 (lgth)
118    return(l);
119 }
120
121 /**
122  * \ingroup gdcmDocEntry
123  * \brief   Copies all the attributes from an other DocEntry 
124  */
125 void gdcmDocEntry::Copy (gdcmDocEntry* e) {
126    this->entry        = e->entry;
127    this->UsableLength = e->UsableLength;
128    this->ReadLength   = e->ReadLength;
129    this->ImplicitVR   = e->ImplicitVR;
130    this->Offset       = e->Offset;
131    this->printLevel   = e->printLevel;
132    // TODO : remove gdcmDocEntry SQDepth
133 }
134
135 /**
136  * \ingroup gdcmDocEntry
137  * \brief   tells us if entry is the first one of a Sequence Item (fffe,e00d) 
138  */
139 bool gdcmDocEntry::isItemDelimitor() {
140    if ( (GetGroup() == 0xfffe) && (GetElement() == 0xe00d) )
141       return true;
142    else
143       return false;      
144 }
145 /**
146  * \ingroup gdcmDocEntry
147  * \brief   tells us if entry is the last one of a 'no length' Sequence fffe,e0dd) 
148  */
149 bool gdcmDocEntry::isSequenceDelimitor() {
150    if (GetGroup() == 0xfffe && GetElement() == 0xe0dd)
151       return true;
152    else
153       return false; 
154 }
155
156 //-----------------------------------------------------------------------------
157 // Protected
158
159
160 //-----------------------------------------------------------------------------
161 // Private
162
163 //-----------------------------------------------------------------------------