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