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