]> Creatis software - gdcm.git/blob - src/gdcmBinEntry.cxx
d92bf991fad9f2e0a5af7755654300d52928e147
[gdcm.git] / src / gdcmBinEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmBinEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/11/25 15:46:10 $
7   Version:   $Revision: 1.39 $
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    os << "B ";
78    DocEntry::Print(os);
79    std::ostringstream s;
80    void* binArea = GetBinArea();
81    if (binArea)
82    {
83       //s << " [" << GDCM_BINLOADED 
84       s << " [" << GetValue()
85         << "; length = " << GetLength() << "]";
86    }
87    else
88    {
89       if ( GetLength() == 0 )
90       {
91          s << " []";
92       }
93       else 
94       {
95          //s << " [gdcm::Binary data NOT loaded]";
96          s << " [" <<GetValue() << "]";
97       }
98          
99    }
100    os << s.str();
101 }
102
103 /*
104  * \brief   canonical Writer
105  * @param fp already open file pointer
106  * @param filetype type of the file to be written
107 */
108 void BinEntry::WriteContent(std::ofstream* fp, FileType filetype)
109 {
110    DocEntry::WriteContent(fp, filetype);
111    void* binArea = GetBinArea();
112    int lgr = GetLength();
113    if (binArea)
114    {
115       // there is a 'non string' LUT, overlay, etc
116       fp->write ( (char*)binArea, lgr ); // Elem value
117       //assert( strlen((char*)binArea) == lgr );
118
119    }
120    else
121    {
122     // nothing was loaded, but we need to skip space on disc
123       fp->seekp(lgr, std::ios_base::cur);
124    }
125 }
126 //-----------------------------------------------------------------------------
127 // Public
128
129
130 /// \brief Sets the value (non string) of the current Dicom Header Entry
131 void BinEntry::SetBinArea( uint8_t* area, bool self )  
132
133    if (BinArea && SelfArea)
134       delete[] BinArea;
135
136    BinArea = area;
137    SelfArea=self;
138 }
139
140 //-----------------------------------------------------------------------------
141 // Protected
142
143 //-----------------------------------------------------------------------------
144 // Private
145    
146 //-----------------------------------------------------------------------------
147 } // end namespace gdcm