forked from LLNL/libROM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database.h
222 lines (200 loc) · 5.85 KB
/
Database.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
/******************************************************************************
*
* 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 abstract database class defines interface for databases.
#ifndef included_Database_h
#define included_Database_h
#include <string>
namespace CAROM {
/**
* Class Database is an abstract base class that provides basic ability to
* write to and read from a file. It's capabilities are limited to what the
* SVD algorithm needs to read and write its basis vectors.
*/
class Database
{
public:
/**
* @brief Default constructor.
*/
Database();
/**
* @brief Destructor.
*/
virtual
~Database();
/**
* @brief Creates a new database file with the supplied name.
*
* @param[in] file_name Name of database file to create.
*
* @return true if file create was successful.
*/
virtual
bool
create(
const std::string& file_name) = 0;
/**
* @brief Opens an existing database file with the supplied name.
*
* @param[in] file_name Name of existing database file to open.
*
* @return true if file open was successful.
*/
virtual
bool
open(
const std::string& file_name) = 0;
/**
* @brief Closes the currently open database file.
*
* @return true if the file close was successful.
*/
virtual
bool
close() = 0;
/**
* @brief Writes an integer associated with the supplied key to currently
* open database file.
*
* @param[in] key The key associated with the value to be written.
* @param[in] data The integer value to be written.
*/
void
putInteger(
const std::string& key,
int data)
{
putIntegerArray(key, &data, 1);
}
/**
* @brief Writes an array of integers associated with the supplied key to
* the currently open database file.
*
* @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) = 0;
/**
* @brief Writes a double associated with the supplied key to currently
* open database file.
*
* @param[in] key The key associated with the value to be written.
* @param[in] data The double value to be written.
*/
void
putDouble(
const std::string& key,
double data)
{
putDoubleArray(key, &data, 1);
}
/**
* @brief Writes an array of doubles associated with the supplied key to
* the currently open database file.
*
* @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) = 0;
/**
* @brief Reads an integer associated with the supplied key from the
* currently open database file.
*
* @param[in] key The key associated with the value to be read.
* @param[out] data The integer value read.
*/
void
getInteger(
const std::string& key,
int& data)
{
getIntegerArray(key, &data, 1);
}
/**
* @brief Reads an array of integers associated with the supplied key
* from the currently open database file.
*
* @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) = 0;
/**
* @brief Reads a double associated with the supplied key from the
* currently open database file.
*
* @param[in] key The key associated with the value to be read.
* @param[out] data The double value read.
*/
void
getDouble(
const std::string& key,
double& data)
{
getDoubleArray(key, &data, 1);
}
/**
* @brief Reads an array of doubles associated with the supplied key
* from the currently open database file.
*
* @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) = 0;
/**
* @brief Implemented database file formats.
*
* Add to this enum each time a new database format is implemented.
*/
enum formats {
HDF5
};
private:
/**
* @brief Unimplemented copy constructor.
*/
Database(
const Database& other);
/**
* @brief Unimplemented assignment operator.
*/
Database&
operator = (
const Database& rhs);
};
}
#endif