]> Creatis software - gdcm.git/blob - src/gdcmBinEntry.cxx
d382e73ccfe09446eb5685fdcf62fdd3f5259954
[gdcm.git] / src / gdcmBinEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmBinEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/06 20:03:26 $
7   Version:   $Revision: 1.43 $
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    //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::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