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