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