]> Creatis software - gdcm.git/blob - src/gdcmDataEntry.h
* Fix some bugs
[gdcm.git] / src / gdcmDataEntry.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDataEntry.h,v $
5   Language:  C++
6   Date:      $Date: 2005/10/19 08:06:45 $
7   Version:   $Revision: 1.2 $
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) 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 public:
39    DataEntry(DictEntry *e);
40    DataEntry(DocEntry *d); 
41    ~DataEntry();
42
43 // Print
44    void Print(std::ostream &os = std::cout, std::string const &indent = "");
45
46 // Write
47    virtual void WriteContent(std::ofstream *fp, FileType filetype);
48
49 // Set/Get datas
50    /// Sets the value (string) of the current Dicom entry
51    //virtual void SetValue(std::string const &val);
52    /// \brief Returns the 'Value' (e.g. "Dupond^Marcel") converted 
53    /// into a 'string', event if it's physically stored on disk as an integer
54    /// (e.g. : 0x000c returned as "12")
55    //virtual std::string const &GetValue() const { return Value; }
56
57    /// \brief Returns the area value of the current Dicom Entry
58    ///  when it's not string-translatable (e.g : LUT table, overlay, icon)         
59    uint8_t *GetBinArea()  { return BinArea; }
60    void SetBinArea( uint8_t *area, bool self = true );
61    void CopyBinArea( uint8_t *area, uint32_t length );
62
63    void SetValue(const uint32_t &id,const double &val);
64    double GetValue(const uint32_t &id) const;
65    uint32_t GetValueCount(void) const;
66
67    void SetString(std::string const &value);
68    std::string const &GetString() const;
69
70    /// \brief Sets SelfArea
71    void SetSelfArea(bool area) { SelfArea = area; }
72    /// \brief Returns SelfArea
73    bool IsSelfArea() { return SelfArea; }
74
75    // State
76    void SetState(const char &state) { State = state; }
77    const char &GetState() const { return State; }
78    bool IsNotLoaded() { return State == STATE_NOTLOADED; }
79    bool IsUnfound()   { return State == STATE_UNFOUND; }
80    bool IsUnread()    { return State == STATE_UNREAD; }
81    bool IsGoodValue() { return State == 0; }
82
83    // Flags
84    void SetFlag(const char &flag) { Flag = flag; }
85    const char &GetFlag() const { return Flag; }
86    bool IsPixelData() { return (Flag & FLAG_PIXELDATA) != 0; }
87
88    void Copy(DocEntry *doc);
89
90    /// \brief returns the size threshold above which an element value 
91    ///        will NOT be *printed* in order no to polute the screen output
92    static const uint32_t &GetMaxSizePrintEntry() { return MaxSizePrintEntry; }
93    /// \brief Header Elements too long will not be printed
94    static void SetMaxSizePrintEntry(const uint32_t &size) { MaxSizePrintEntry = size; }
95
96    typedef enum
97    {
98       STATE_LOADED    = 0x00,
99       STATE_NOTLOADED = 0x01,
100       STATE_UNFOUND   = 0x02,
101       STATE_UNREAD    = 0x03
102    } TValueState;
103
104    typedef enum
105    {
106       FLAG_NONE       = 0x00,
107       FLAG_PIXELDATA  = 0x01
108    } TValueFlag;
109
110 protected:
111 // Methods :
112    void NewBinArea(void);
113    void DeleteBinArea(void);
114
115 // Members :
116    /// \brief memory area to hold 'non std::string' representable values 
117    ///       (ie : Lookup Tables, overlays, icons)   
118    uint8_t *BinArea;
119    /// \brief Whether DataEntry has its own BinArea or not
120    bool SelfArea;
121
122    mutable std::string StrArea;
123
124 private:
125    char Flag;
126    char State;
127
128    /// \brief Size threshold above which an element val
129    ///        By default, this upper bound is fixed to 64 bytes.
130    static uint32_t MaxSizePrintEntry;   
131 };
132
133 } // end namespace gdcm
134
135 //-----------------------------------------------------------------------------
136 #endif
137