]> Creatis software - gdcm.git/blob - src/gdcmDataEntry.h
* Change the DocEntry inheritance to RefCounter
[gdcm.git] / src / gdcmDataEntry.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDataEntry.h,v $
5   Language:  C++
6   Date:      $Date: 2005/10/24 16:00:47 $
7   Version:   $Revision: 1.5 $
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 #ifndef GDCMDATAENTRY_H
20 #define GDCMDATAENTRY_H
21
22 #include "gdcmDocEntry.h"
23
24 #include <iostream>
25
26 namespace gdcm 
27 {
28 //-----------------------------------------------------------------------------
29 /**
30  * \brief   Any Dicom Document (File or DicomDir, or ...) contains 
31  *           a set of DocEntry  - Dicom entries -
32  *           (when successfuly parsed against a given Dicom dictionary)
33  *          DataEntry is an elementary DocEntry (as opposed to SeqEntry).
34  *          Depending on the type of its content,
35  */
36 class GDCM_EXPORT DataEntry  : public DocEntry
37 {
38    gdcmTypeMacro(DataEntry);
39
40 public:
41    static DataEntry *New(DictEntry *e) {return new DataEntry(e);}
42    static DataEntry *New(DocEntry *d) {return new DataEntry(d);}
43
44 // Print
45    void Print(std::ostream &os = std::cout, std::string const &indent = "");
46
47 // Write
48    virtual void WriteContent(std::ofstream *fp, FileType filetype);
49
50 // Set/Get data
51    /// Sets the value (string) of the current Dicom entry
52    //virtual void SetValue(std::string const &val);
53    /// \brief Returns the 'Value' (e.g. "Dupond^Marcel") converted 
54    /// into a 'string', event if it's physically stored on disk as an integer
55    /// (e.g. : 0x000c returned as "12")
56    //virtual std::string const &GetValue() const { return Value; }
57
58    /// \brief Returns the area value of the current Dicom Entry
59    ///  when it's not string-translatable (e.g : LUT table, overlay, icon)         
60    uint8_t *GetBinArea()  { return BinArea; }
61    void SetBinArea( uint8_t *area, bool self = true );
62    void CopyBinArea( uint8_t *area, uint32_t length );
63
64    void SetValue(const uint32_t &id,const double &val);
65    double GetValue(const uint32_t &id) const;
66    uint32_t GetValueCount(void) const;
67    bool IsValueCountValid() const;
68
69    void SetString(std::string const &value);
70    std::string const &GetString() const;
71
72    /// \brief Sets SelfArea
73    void SetSelfArea(bool area) { SelfArea = area; }
74    /// \brief True if Entry owns its BinArea
75    bool IsSelfArea() { return SelfArea; }
76
77    // State
78    void SetState(const char &state) { State = state; }
79    const char &GetState() const { return State; }
80    /// \brief true when value Entry not loaded  
81    bool IsNotLoaded() { return State == STATE_NOTLOADED; }
82    /// \brief true if Entry not found  
83    bool IsUnfound()   { return State == STATE_UNFOUND; }
84    /// \brief true if Entry not read    
85    bool IsUnread()    { return State == STATE_UNREAD; }
86    /// \brief true if Entry value properly loaded
87    bool IsGoodValue() { return State == 0; }
88
89    // Flags
90    /// \brief sets the 'pixel data flag'   
91    void SetFlag(const char &flag) { Flag = flag; }
92    /// \brief returns the 'pixel data flag'    
93    const char &GetFlag() const { return Flag; }
94    /// \brief true id Entry is a Pixel Data entry
95    bool IsPixelData() { return (Flag & FLAG_PIXELDATA) != 0; }
96
97    void Copy(DocEntry *doc);
98
99    /// \brief returns the size threshold above which an element value 
100    ///        will NOT be *printed* in order no to polute the screen output
101    static const uint32_t &GetMaxSizePrintEntry() { return MaxSizePrintEntry; }
102    /// \brief Header Elements too long will not be printed
103    static void SetMaxSizePrintEntry(const uint32_t &size) { MaxSizePrintEntry = size; }
104
105    ///\brief values for current state of a DataEntry (internal use only)
106    typedef enum
107    {
108       STATE_LOADED    = 0x00,
109       STATE_NOTLOADED = 0x01,
110       STATE_UNFOUND   = 0x02,
111       STATE_UNREAD    = 0x03
112    } TValueState;
113    
114    ///\brief values for current pixel status of a DataEntry (internal use only)
115    typedef enum
116    {
117       FLAG_NONE       = 0x00,
118       FLAG_PIXELDATA  = 0x01
119    } TValueFlag;
120
121 protected:
122    DataEntry(DictEntry *e);
123    DataEntry(DocEntry *d); 
124    ~DataEntry();
125
126 // Methods :
127    void NewBinArea(void);
128    void DeleteBinArea(void);
129
130 // Members :
131    /// \brief memory area to hold 'non std::string' representable values 
132    ///       (ie : Lookup Tables, overlays, icons)   
133    uint8_t *BinArea;
134    /// \brief Whether DataEntry has its own BinArea or not
135    bool SelfArea;
136    /// \brief  std::string representable value of the Entry. 
137    ///        Parts of a multivaluated data are separated by back-slash
138    mutable std::string StrArea;
139
140 private:
141    /// \brief 0 for straight entries, FLAG_PIXELDATA for Pixel Data entries
142    char Flag;
143    /// \brief Entry status : STATE_NOTLOADED,STATE_UNFOUND, STATE_UNREAD, 0
144    char State;
145
146    /// \brief Size threshold above which an element val
147    ///        By default, this upper bound is fixed to 64 bytes.
148    static uint32_t MaxSizePrintEntry;   
149 };
150
151 } // end namespace gdcm
152
153 //-----------------------------------------------------------------------------
154 #endif
155