]> Creatis software - gdcm.git/blob - src/gdcmBinEntry.cxx
* src/gdcmDocEntry.[h|cxx] : now the ReadLength is the length of the datas
[gdcm.git] / src / gdcmBinEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmBinEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/07 16:45:51 $
7   Version:   $Revision: 1.44 $
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    Copy(e);
46 /*   Length     = e->GetLength();
47    ReadLength = e->GetReadLength();
48    ImplicitVR = e->IsImplicitVR();
49    Offset     = e->GetOffset();*/
50
51    //FIXME
52    //SQDepthLevel = e->GetDepthLevel();
53
54    BinArea = 0; // let's be carefull !
55    SelfArea = true;
56 }
57
58 /**
59  * \brief   Canonical destructor.
60  */
61 BinEntry::~BinEntry()
62 {
63    if (BinArea && SelfArea)
64    {
65       delete[] BinArea;
66       BinArea = 0; // let's be carefull !
67    }
68 }
69
70
71 //-----------------------------------------------------------------------------
72 // Print
73 /*
74  * \brief   canonical Printer
75  */
76  
77 void BinEntry::Print(std::ostream &os)
78 {
79    os << "B ";
80    DocEntry::Print(os);
81    std::ostringstream s;
82    void* binArea = GetBinArea();
83    if (binArea)
84    {
85       //s << " [" << GDCM_BINLOADED 
86       s << " [" << GetValue()
87         << "; length = " << GetLength() << "]";
88    }
89    else
90    {
91       if ( GetLength() == 0 )
92       {
93          s << " []";
94       }
95       else 
96       {
97          //s << " [gdcm::Binary data NOT loaded]";
98          s << " [" <<GetValue() << "]";
99       }
100          
101    }
102    os << s.str();
103 }
104
105 /*
106  * \brief   canonical Writer
107  * @param fp already open file pointer
108  * @param filetype type of the file to be written
109 */
110 void BinEntry::WriteContent(std::ofstream *fp, FileType filetype)
111 {
112    DocEntry::WriteContent(fp, filetype);
113    void* binArea = GetBinArea();
114    int lgr = GetLength();
115    if (binArea)
116    {
117       // there is a 'non string' LUT, overlay, etc
118       fp->write ( (char*)binArea, lgr ); // Elem value
119    }
120    else
121    {
122     // nothing was loaded, but we need to skip space on disc
123       fp->seekp(lgr, std::ios::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