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