LRAUV  revA
HDF5.h
Go to the documentation of this file.
1 
9 #ifndef HDF5_H_
10 #define HDF5_H_
11 
12 #include "data/BlobValue.h"
13 #include "data/ElementURI.h"
14 #include "utils/FastMap.h"
15 #include "utils/FlexArray.h"
16 #include "units/Units.h"
17 #include "utils/Str.h"
18 
19 class DataValue;
20 class Unit;
21 
22 class HDF5Group;
23 class HDF5Dataset;
24 
25 class HDF5Item
26 {
27 
28 public:
29  virtual ~HDF5Item() {}
30 
31  int getId()
32  {
33  return id_;
34  }
35 
36  virtual bool writeHeader() = 0;
37 
38  virtual bool finalize();
39 
40 protected:
41 
43  : id_( -1 ),
44  typeId_( -1 ),
45  spaceId_( -1 )
46  {}
47 
48  int id_;
49  int typeId_;
50  int spaceId_;
51 
52 private:
53  // Note that the copy constructor below is private and not given a body.
54  // Any attempt to call it will return a compiler error.
55  HDF5Item( const HDF5Item& old ); // disallow copy constructor
56 
57 };
58 
59 
60 class HDF5Attribute: public HDF5Item
61 {
62 public:
63  HDF5Attribute( HDF5Item* parent, const char* name, const char* value );
64 
65  HDF5Attribute( HDF5Item* parent, const char* name, const int value );
66 
67  HDF5Attribute( HDF5Item* parent, const char* name, FlexArray<Str*>& fields );
68 
69  virtual ~HDF5Attribute();
70 
71  virtual bool writeHeader();
72 
73  virtual bool finalize();
74 
75 protected:
76 
77  void* value_;
79 
80 private:
81  // Note that the copy constructor below is private and not given a body.
82  // Any attempt to call it will return a compiler error.
83  HDF5Attribute( const HDF5Attribute& old ); // disallow copy constructor
84 
85 };
86 
88 {
89 
90 public:
92  : HDF5Item(),
93  parent_( parent ),
94  attributes_( true )
95  {}
96 
97  virtual ~HDF5HasAttributes() {}
98 
99  int getId()
100  {
101  return id_;
102  }
103 
104  virtual HDF5Group* getParent()
105  {
106  return parent_;
107  }
108 
109  virtual bool isMatlab()
110  {
111  return NULL == parent_ ? false : ( ( HDF5HasAttributes* )parent_ )->isMatlab();
112  }
113 
114  virtual HDF5Group* getRoot()
115  {
116  return NULL == parent_ ? NULL : ( ( HDF5HasAttributes* )parent_ )->getRoot();
117  }
118 
119  void addAttribute( const char* name, const char* value );
120 
121  void addAttribute( const char* name, const int value );
122 
123  virtual bool writeHeader();
124 
125  virtual bool finalize();
126 
127 protected:
128 
131 
132 private:
133  // Note that the copy constructor below is private and not given a body.
134  // Any attempt to call it will return a compiler error.
135  HDF5HasAttributes( const HDF5HasAttributes& old ); // disallow copy constructor
136 
137 };
138 
140 {
141 public:
142  HDF5Group( HDF5Group* parent, const char* name, bool useMetadata );
143 
144  virtual ~HDF5Group();
145 
146  HDF5Group* findGroup( const char* name );
147 
148  HDF5Group* addGroup( const char* name, bool useMetadata = true );
149 
150  HDF5Dataset* findDataset( const char* name );
151 
152  HDF5Dataset* addScalarDataset( const char* name, const char* value, size_t length, const Unit& unit );
153 
154  HDF5Dataset* addDataset( const char* name, BinaryDataType binaryType,
155  const Unit& unit, bool useChunks,
156  BlobType blobType = NOT_BLOB,
157  int rank = 1, unsigned short m = 0, unsigned short n = 0, unsigned short o = 0 );
158 
159  virtual bool writeHeader();
160 
161  virtual bool finalize();
162 
163  unsigned int getDatasetCount()
164  {
165  return datasetMap_.size();
166  }
167 
168 protected:
169 
174 
175 private:
176  // Note that the copy constructor below is private and not given a body.
177  // Any attempt to call it will return a compiler error.
178  HDF5Group( const HDF5Group& old ); // disallow copy constructor
179 
180 };
181 
182 class HDF5File: public HDF5Group
183 {
184 public:
185  HDF5File( const char* fileName, bool matlab );
186  virtual ~HDF5File() {}
187 
188  virtual bool isMatlab()
189  {
190  return matlab_;
191  }
192 
193  virtual HDF5Group* getRoot()
194  {
195  return this;
196  }
197 
198  virtual bool finalize();
199 
200 protected:
201  bool matlab_;
204 
205 private:
206  // Note that the copy constructor below is private and not given a body.
207  // Any attempt to call it will return a compiler error.
208  HDF5File( const HDF5File& old ); // disallow copy constructor
209 
210 };
211 
213 {
214 public:
215  HDF5Dataset( HDF5Group* parent, const char* name, BinaryDataType binaryType,
216  const Unit& unit, bool useChunks,
217  BlobType blobType = NOT_BLOB,
218  int rank = 1, unsigned short m = 0, unsigned short n = 0, unsigned short o = 0 );
219 
220  HDF5Dataset( HDF5Group* parent, const char* name, const char* value, size_t length, const Unit& unit );
221 
222  virtual ~HDF5Dataset();
223 
225 
226  bool writeDataValue();
227 
228  bool finalize();
229 
230  static int TypeIdFromBlobType( BlobType blobType );
231 
232  static const char* MatlabClassFromBlobType( BlobType blobType );
233 
234 protected:
237  int rank_;
238  unsigned short m_, n_, o_;
239  int propsId_;
240  size_t numRecs_;
241 
242  static const int MAX_RANK = 4;
243 
244 private:
245  // Note that the copy constructor below is private and not given a body.
246  // Any attempt to call it will return a compiler error.
247  HDF5Dataset( const HDF5Dataset& old ); // disallow copy constructor
248 
249 };
250 
251 #endif /*HDF5_H_*/
FlexArray< Str * > fields_
Definition: HDF5.h:172
virtual HDF5Group * getParent()
Definition: HDF5.h:104
Definition: HDF5.h:139
BinaryDataType
These are binary type identifiers for serializing and unserializing The syntax below handles up to 16...
Definition: BinaryDataType.h:39
DataValue * dataValue_
Definition: HDF5.h:235
HDF5File(const char *fileName, bool matlab)
Definition: HDF5.cpp:269
FastMap< const Str, HDF5Group * > groupMap_
Definition: HDF5.h:170
virtual bool finalize()
Definition: HDF5.cpp:28
Str tempFilename_
Definition: HDF5.h:203
static const int MAX_RANK
Definition: HDF5.h:242
virtual ~HDF5Group()
Definition: HDF5.cpp:166
virtual bool isMatlab()
Definition: HDF5.h:109
void * value_
Definition: HDF5.h:77
virtual ~HDF5File()
Definition: HDF5.h:186
unsigned short n_
Definition: HDF5.h:238
Definition: HDF5.h:182
virtual bool writeHeader()=0
int rank_
Definition: HDF5.h:237
int id_
Definition: HDF5.h:48
virtual bool finalize()
Definition: HDF5.cpp:192
unsigned int size()
Definition: FastMap.h:159
A DataValue is an abstract base class for a data value and associated engineering units of the value...
Definition: DataValue.h:35
size_t numRecs_
Definition: HDF5.h:240
HDF5HasAttributes(HDF5Group *parent)
Definition: HDF5.h:91
virtual ~HDF5Dataset()
Definition: HDF5.cpp:509
HDF5Item()
Definition: HDF5.h:42
Contains the FlexArrayBase and FlexArray class declarations.
HDF5Dataset * findDataset(const char *name)
Definition: HDF5.cpp:231
HDF5Dataset(HDF5Group *parent, const char *name, BinaryDataType binaryType, const Unit &unit, bool useChunks, BlobType blobType=NOT_BLOB, int rank=1, unsigned short m=0, unsigned short n=0, unsigned short o=0)
Definition: HDF5.cpp:406
static const char * MatlabClassFromBlobType(BlobType blobType)
Definition: HDF5.cpp:753
void addAttribute(const char *name, const char *value)
Definition: HDF5.cpp:120
int getId()
Definition: HDF5.h:31
DataValue * getDataValue()
Definition: HDF5.cpp:517
Str filename_
Definition: HDF5.h:202
BlobType
Definition: BlobType.h:13
virtual bool isMatlab()
Definition: HDF5.h:188
virtual ~HDF5Item()
Definition: HDF5.h:29
virtual HDF5Group * getRoot()
Definition: HDF5.h:114
HDF5Group * parent_
Definition: HDF5.h:129
bool vlArrayDelete_
Definition: HDF5.h:78
Definition: HDF5.h:60
Replacement for standard template class string.
Definition: Str.h:12
bool matlab_
Definition: HDF5.h:201
virtual bool writeHeader()
Definition: HDF5.cpp:172
Definition: BlobType.h:15
HDF5Dataset * addDataset(const char *name, BinaryDataType binaryType, const Unit &unit, bool useChunks, BlobType blobType=NOT_BLOB, int rank=1, unsigned short m=0, unsigned short n=0, unsigned short o=0)
Definition: HDF5.cpp:251
HDF5Group * addGroup(const char *name, bool useMetadata=true)
Definition: HDF5.cpp:216
virtual HDF5Group * getRoot()
Definition: HDF5.h:193
int typeId_
Definition: HDF5.h:49
FastMap< const Str, HDF5Dataset * > datasetMap_
Definition: HDF5.h:171
unsigned short m_
Definition: HDF5.h:238
int getId()
Definition: HDF5.h:99
Contains the ElementURI class definition.
virtual bool finalize()
Definition: HDF5.cpp:111
Definition: HDF5.h:212
virtual ~HDF5Attribute()
Definition: HDF5.cpp:88
unsigned short o_
Definition: HDF5.h:238
bool useMetadata_
Definition: HDF5.h:173
Contains the Units class declaration.
int spaceId_
Definition: HDF5.h:50
Contains the FastMap class declaration.
HDF5Attribute(HDF5Item *parent, const char *name, const char *value)
Definition: HDF5.cpp:41
virtual bool finalize()
Definition: HDF5.cpp:140
bool writeDataValue()
Definition: HDF5.cpp:538
Definition: HDF5.h:87
virtual bool writeHeader()
Definition: HDF5.cpp:96
BlobType blobType_
Definition: HDF5.h:236
virtual bool finalize()
Definition: HDF5.cpp:303
HDF5Group(HDF5Group *parent, const char *name, bool useMetadata)
Definition: HDF5.cpp:150
HDF5Dataset * addScalarDataset(const char *name, const char *value, size_t length, const Unit &unit)
Definition: HDF5.cpp:236
FlexArray< HDF5Attribute * > attributes_
Definition: HDF5.h:130
unsigned int getDatasetCount()
Definition: HDF5.h:163
bool finalize()
Definition: HDF5.cpp:794
Code that represents an engineering unit.
Definition: Unit.h:24
Contains the BlobValue class definition.
static int TypeIdFromBlobType(BlobType blobType)
Definition: HDF5.cpp:704
virtual bool writeHeader()
Definition: HDF5.cpp:130
virtual ~HDF5HasAttributes()
Definition: HDF5.h:97
Definition: HDF5.h:25
int propsId_
Definition: HDF5.h:239
HDF5Group * findGroup(const char *name)
Definition: HDF5.cpp:211