forked from LLNL/libROM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HDFDatabase.h
235 lines (210 loc) · 6.17 KB
/
HDFDatabase.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/******************************************************************************
*
* Copyright (c) 2013-2019, Lawrence Livermore National Security, LLC
* and other libROM project developers. See the top-level COPYRIGHT
* file for details.
*
* SPDX-License-Identifier: (Apache-2.0 OR MIT)
*
*****************************************************************************/
// Description: The concrete database implementation using HDF5.
#ifndef included_HDFDatabase_h
#define included_HDFDatabase_h
#include "Database.h"
#include "hdf5.h"
#include <string>
namespace CAROM {
/**
* HDFDatabase implements the interface of Database for HDF5 database files.
*/
class HDFDatabase : public Database
{
public:
/**
* @brief Default constructor.
*/
HDFDatabase();
/**
* @brief Destructor.
*/
virtual
~HDFDatabase();
/**
* @brief Creates a new HDF5 database file with the supplied name.
*
* @param[in] file_name Name of HDF5 database file to create.
*
* @return true if file create was successful.
*/
virtual
bool
create(
const std::string& file_name);
/**
* @brief Opens an existing HDF5 database file with the supplied name.
*
* @param[in] file_name Name of existing HDF5 database file to open.
*
* @return true if file open was successful.
*/
virtual
bool
open(
const std::string& file_name);
/**
* @brief Closes the currently open HDF5 database file.
*
* @return true if the file close was successful.
*/
virtual
bool
close();
/**
* @brief Writes an array of integers associated with the supplied key to
* the currently open HDF5 database file.
*
* @pre !key.empty()
* @pre data != 0
* @pre nelements > 0
*
* @param[in] key The key associated with the array of values to be
* written.
* @param[in] data The array of integer values to be written.
* @param[in] nelements The number of integers in the array.
*/
virtual
void
putIntegerArray(
const std::string& key,
const int* const data,
int nelements);
/**
* @brief Writes an array of doubles associated with the supplied key to
* the currently open HDF5 database file.
*
* @pre !key.empty()
* @pre data != 0
* @pre nelements > 0
*
* @param[in] key The key associated with the array of values to be
* written.
* @param[in] data The array of double values to be written.
* @param[in] nelements The number of doubles in the array.
*/
virtual
void
putDoubleArray(
const std::string& key,
const double* const data,
int nelements);
/**
* @brief Reads an array of integers associated with the supplied key
* from the currently open HDF5 database file.
*
* @pre !key.empty()
* @pre data != 0 || nelements == 0
*
* @param[in] key The key associated with the array of values to be
* read.
* @param[out] data The allocated array of integer values to be read.
* @param[in] nelements The number of integers in the array.
*/
virtual
void
getIntegerArray(
const std::string& key,
int* data,
int nelements);
/**
* @brief Reads an array of doubles associated with the supplied key
* from the currently open HDF5 database file.
*
* @pre !key.empty()
* @pre data != 0 || nelements == 0
*
* @param[in] key The key associated with the array of values to be
* read.
* @param[out] data The allocated array of double values to be read.
* @param[in] nelements The number of doubles in the array.
*/
virtual
void
getDoubleArray(
const std::string& key,
double* data,
int nelements);
private:
/**
* @brief Unimplemented copy constructor.
*/
HDFDatabase(
const HDFDatabase& other);
/**
* @brief Unimplemented assignment operator.
*/
HDFDatabase&
operator = (
const HDFDatabase& rhs);
/**
* @brief Returns true if the specified key represents an integer entry.
*
* If the key does not exist or if the string is empty then false is
* returned.
*
* @param[in] key The key associated with the data we are interested in.
*
* @return true if the data associated with key is an integer array.
*/
bool
isInteger(
const std::string& key);
/**
* @brief Returns true if the specified key represents a double entry.
*
* If the key does not exist or if the string is empty then false is
* returned.
*
* @param[in] key The key associated with the data we are interested in.
*
* @return true if the data associated with key is a double array.
*/
bool
isDouble(
const std::string& key);
/**
* @brief Write an attribute to the specified dataset.
*
* @param[in] type_key The attribute to be written.
* @param[in] dataset_id ID of the dataset key will be written to.
*/
void
writeAttribute(
int type_key,
hid_t dataset_id);
/**
* @brief Read an attribute from the specified dataset.
*
* @param[in] dataset_id ID of the dataset key will be written to.
*
* @return The attribute.
*/
int
readAttribute(
hid_t dataset_id);
/**
* @brief True if the HDF5 database is mounted to a file.
*/
bool d_is_file;
/**
* @brief ID of file attached to database or -1 if not mounted to a file.
*/
hid_t d_file_id;
/**
* @brief ID of the group attached to the database.
* */
hid_t d_group_id;
static const int KEY_DOUBLE_ARRAY;
static const int KEY_INT_ARRAY;
};
}
#endif