]> Creatis software - gdcm.git/blob - src/gdcmDocEntry.cxx
* Erroneous leading white fix:
[gdcm.git] / src / gdcmDocEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDocEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/06/20 18:08:47 $
7   Version:   $Revision: 1.7 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.htm for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19 #include "gdcmDocEntry.h"
20 #include "gdcmTS.h"
21 #include "gdcmGlobal.h"
22 #include "gdcmUtil.h"
23
24 #include <iomanip> // for std::ios::left, ...
25
26 // CLEAN ME
27 #define MAX_SIZE_PRINT_ELEMENT_VALUE 64
28
29 //-----------------------------------------------------------------------------
30 // Constructor / Destructor
31 /**
32  * \ingroup gdcmDocEntry
33  * \brief   Constructor from a given gdcmDictEntry
34  * @param   in Pointer to existing dictionary entry
35  */
36 gdcmDocEntry::gdcmDocEntry(gdcmDictEntry* in) {
37    ImplicitVR = false;
38    entry = in;
39 }
40
41 /**
42  * \ingroup gdcmDocEntry
43  * \brief   Canonical Printer
44  * @param   os ostream we want to print in
45  */
46 void gdcmDocEntry::Print(std::ostream & os) {
47    std::ostringstream s;
48    s << std::endl;
49    PrintCommonPart(os);
50    os << s.str();
51 }
52
53 //-----------------------------------------------------------------------------
54 // Print
55 /**
56  * \ingroup gdcmDocEntry
57  * \brief   Prints the common part of gdcmValEntry, gdcmBinEntry, gdcmSeqEntry
58  */
59 void gdcmDocEntry::PrintCommonPart(std::ostream & os) {
60
61    printLevel=2; // FIXME
62    
63    size_t o;
64    unsigned short int g, e;
65    char st[20];
66    TSKey v;
67    std::string d2, vr;
68    std::ostringstream s;
69    guint32 lgth;
70    char greltag[10];  //group element tag
71
72    g  = GetGroup();
73    e  = GetElement();
74    o  = GetOffset();
75    vr = GetVR();
76    sprintf(greltag,"%04x|%04x ",g,e);           
77    s << greltag ;
78        
79    if (printLevel>=2) { 
80       s << "lg : ";
81       lgth = GetReadLength(); // ReadLength, as opposed to UsableLength
82       if (lgth == 0xffffffff) {
83          sprintf(st,"x(ffff)");  // I said : "x(ffff)" !
84          s.setf(std::ios::left);
85          s << std::setw(10-strlen(st)) << " ";  
86          s << st << " ";
87          s.setf(std::ios::left);
88          s << std::setw(8) << "-1";      
89       } else {
90          sprintf(st,"x(%x)",lgth);
91          s.setf(std::ios::left);
92          s << std::setw(10-strlen(st)) << " ";  
93          s << st << " ";
94          s.setf(std::ios::left);
95          s << std::setw(8) << lgth; 
96       }
97       s << " Off.: ";
98       sprintf(st,"x(%x)",o); 
99       s << std::setw(10-strlen(st)) << " ";
100       s << st << " ";
101       s << std::setw(8) << o; 
102    }
103
104    s << "[" << vr  << "] ";
105
106    if (printLevel>=1) {      
107       s.setf(std::ios::left);
108       s << std::setw(66-GetName().length()) << " ";
109    }
110     
111    s << "[" << GetName()<< "]";
112    os << s.str();      
113 }
114
115 //-----------------------------------------------------------------------------
116 // Public
117
118 /**
119  * \ingroup gdcmDocEntry
120  * \brief   Gets the full length of the elementary DocEntry (not only value length)
121  */
122 guint32 gdcmDocEntry::GetFullLength(void) {
123    guint32 l;
124    l = GetReadLength();
125    if ( IsImplicitVR() ) 
126       l = l + 8;  // 2 (gr) + 2 (el) + 4 (lgth) 
127    else    
128       if ( GetVR()=="OB" || GetVR()=="OW" || GetVR()=="SQ" )
129          l = l + 12; // 2 (gr) + 2 (el) + 2 (vr) + 2 (unused) + 4 (lgth)
130       else
131          l = l + 8;  // 2 (gr) + 2 (el) + 2 (vr) + 2 (lgth)
132    return(l);
133 }
134
135 /**
136  * \ingroup gdcmDocEntry
137  * \brief   Copies all the attributes from an other DocEntry 
138  */
139 void gdcmDocEntry::Copy (gdcmDocEntry* e) {
140    this->entry        = e->entry;
141    this->UsableLength = e->UsableLength;
142    this->ReadLength   = e->ReadLength;
143    this->ImplicitVR   = e->ImplicitVR;
144    this->Offset       = e->Offset;
145    this->printLevel   = e->printLevel;
146    // TODO : remove gdcmDocEntry SQDepth
147 }
148
149 /**
150  * \ingroup gdcmDocEntry
151  * \brief   tells us if entry is the first one of a Sequence Item (fffe,e00d) 
152  */
153 bool gdcmDocEntry::isItemDelimitor() {
154    if ( (GetGroup() == 0xfffe) && (GetElement() == 0xe00d) )
155       return true;
156    else
157       return false;      
158 }
159 /**
160  * \ingroup gdcmDocEntry
161  * \brief   tells us if entry is the last one of a 'no length' Sequence fffe,e0dd) 
162  */
163 bool gdcmDocEntry::isSequenceDelimitor() {
164    if (GetGroup() == 0xfffe && GetElement() == 0xe0dd)
165       return true;
166    else
167       return false; 
168 }
169
170 //-----------------------------------------------------------------------------
171 // Protected
172
173
174 //-----------------------------------------------------------------------------
175 // Private
176
177 //-----------------------------------------------------------------------------