]> Creatis software - gdcm.git/blob - src/gdcmBinEntry.cxx
ENH: Apply patch from ITK back to main CVS. Fix problem with gcc2.95, we may need...
[gdcm.git] / src / gdcmBinEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmBinEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/11/30 16:24:31 $
7   Version:   $Revision: 1.40 $
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.html 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 "gdcmBinEntry.h"
20 #include "gdcmDebug.h"
21 #include <fstream>
22 #include <iostream> // for std::ios_base, since <ios> does not exist on gcc/Solaris
23
24 namespace gdcm 
25 {
26
27 //-----------------------------------------------------------------------------
28 // Constructor / Destructor
29
30 /**
31  * \brief   Constructor from a given BinEntry
32  */
33 BinEntry::BinEntry(DictEntry* e) : ValEntry(e)
34 {
35    BinArea = 0;
36    SelfArea = true;
37 }
38
39 /**
40  * \brief   Constructor from a given BinEntry
41  * @param   e Pointer to existing Doc entry
42  */
43 BinEntry::BinEntry(DocEntry* e) : ValEntry(e->GetDictEntry())
44 {
45    UsableLength = e->GetLength();
46    ReadLength   = e->GetReadLength();
47    ImplicitVR   = e->IsImplicitVR();
48    Offset       = e->GetOffset();
49    PrintLevel   = e->GetPrintLevel();
50    //FIXME
51    //SQDepthLevel = e->GetDepthLevel();
52
53    BinArea = 0; // let's be carefull !
54    SelfArea = true;
55 }
56
57 /**
58  * \brief   Canonical destructor.
59  */
60 BinEntry::~BinEntry()
61 {
62    if (BinArea && SelfArea)
63    {
64       delete[] BinArea;
65       BinArea = 0; // let's be carefull !
66    }
67 }
68
69
70 //-----------------------------------------------------------------------------
71 // Print
72 /*
73  * \brief   canonical Printer
74  */
75  
76 void BinEntry::Print(std::ostream &os)
77 {
78    os << "B ";
79    DocEntry::Print(os);
80    std::ostringstream s;
81    void* binArea = GetBinArea();
82    if (binArea)
83    {
84       //s << " [" << GDCM_BINLOADED 
85       s << " [" << GetValue()
86         << "; length = " << GetLength() << "]";
87    }
88    else
89    {
90       if ( GetLength() == 0 )
91       {
92          s << " []";
93       }
94       else 
95       {
96          //s << " [gdcm::Binary data NOT loaded]";
97          s << " [" <<GetValue() << "]";
98       }
99          
100    }
101    os << s.str();
102 }
103
104 /*
105  * \brief   canonical Writer
106  * @param fp already open file pointer
107  * @param filetype type of the file to be written
108 */
109 void BinEntry::WriteContent(std::ofstream* fp, FileType filetype)
110 {
111    DocEntry::WriteContent(fp, filetype);
112    void* binArea = GetBinArea();
113    int lgr = GetLength();
114    if (binArea)
115    {
116       // there is a 'non string' LUT, overlay, etc
117       fp->write ( (char*)binArea, lgr ); // Elem value
118       //assert( strlen((char*)binArea) == lgr );
119
120    }
121    else
122    {
123     // nothing was loaded, but we need to skip space on disc
124       fp->seekp(lgr, std::ios_base::cur);
125    }
126 }
127 //-----------------------------------------------------------------------------
128 // Public
129
130
131 /// \brief Sets the value (non string) of the current Dicom Header Entry
132 void BinEntry::SetBinArea( uint8_t* area, bool self )  
133
134    if (BinArea && SelfArea)
135       delete[] BinArea;
136
137    BinArea = area;
138    SelfArea=self;
139 }
140
141 //-----------------------------------------------------------------------------
142 // Protected
143
144 //-----------------------------------------------------------------------------
145 // Private
146    
147 //-----------------------------------------------------------------------------
148 } // end namespace gdcm