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