libROM  v1.0
Data-driven physical simulation library
CSVDatabase.h
1 
11 // Description: The concrete database implementation using CSV.
12 
13 #ifndef included_CSVDatabase_h
14 #define included_CSVDatabase_h
15 
16 #include "Database.h"
17 #include <string>
18 #include <fstream>
19 #include <complex>
20 
21 namespace CAROM {
22 
26 class CSVDatabase : public Database
27 {
28 public:
32  CSVDatabase();
33 
37  virtual
38  ~CSVDatabase();
39 
51  bool
52  create(
53  const std::string& file_name,
54  const MPI_Comm comm=MPI_COMM_NULL) override;
55 
68  bool
69  open(
70  const std::string& file_name,
71  const std::string& type,
72  const MPI_Comm comm=MPI_COMM_NULL) override;
73 
79  bool
80  close();
81 
96  void
98  const std::string& file_name,
99  const int* const data,
100  int nelements,
101  const bool distributed=false) override;
102 
117  void
119  const std::string& file_name,
120  const double* const data,
121  int nelements,
122  const bool distributed=false) override;
123 
139  void
141  const std::string& file_name,
142  const std::vector<double>& data,
143  int nelements,
144  const bool distributed=false) override;
145 
158  void
160  const std::string& file_name,
161  const std::vector<std::complex<double>>& data,
162  int nelements);
163 
176  void
178  const std::string& file_name,
179  const std::vector<std::string>& data,
180  int nelements);
181 
195  void
197  const std::string& file_name,
198  int* data,
199  int nelements,
200  const bool distributed=false) override;
201 
212  void
214  const std::string& file_name,
215  std::vector<int> &data,
216  bool append = false);
217 
227  int
228  getDoubleArraySize(const std::string& file_name) override
229  {
230  std::vector<double> tmp;
231  getDoubleVector(file_name, tmp);
232  return tmp.size();
233  }
234 
248  void
250  const std::string& file_name,
251  double* data,
252  int nelements,
253  const bool distributed=false) override;
254 
269  void
271  const std::string& file_name,
272  double* data,
273  int nelements,
274  const std::vector<int>& idx,
275  const bool distributed=false) override;
276 
293  void
295  const std::string& file_name,
296  double* data,
297  int nelements,
298  int offset,
299  int block_size,
300  int stride,
301  const bool distributed=false) override;
302 
313  void
315  const std::string& file_name,
316  std::vector<double> &data,
317  bool append = false);
318 
329  void
331  const std::string& file_name,
332  std::vector<std::string> &data,
333  bool append = false);
334 
343  int
344  getLineCount(
345  const std::string& file_name);
346 
347 private:
351  CSVDatabase(
352  const CSVDatabase& other);
353 
357  CSVDatabase&
358  operator = (
359  const CSVDatabase& rhs);
360 
361 };
362 
363 }
364 
365 #endif
void getIntegerVector(const std::string &file_name, std::vector< int > &data, bool append=false)
Reads a vector of integers associated with the supplied filename.
void putDoubleVector(const std::string &file_name, const std::vector< double > &data, int nelements, const bool distributed=false) override
Writes a vector of doubles associated with the supplied filename to the currently open CSV database f...
Definition: CSVDatabase.cpp:94
void putIntegerArray(const std::string &file_name, const int *const data, int nelements, const bool distributed=false) override
Writes an array of integers associated with the supplied filename.
Definition: CSVDatabase.cpp:55
void getIntegerArray(const std::string &file_name, int *data, int nelements, const bool distributed=false) override
Reads an array of integers associated with the supplied filename.
int getLineCount(const std::string &file_name)
Count the number of lines of CSV database file.
CSVDatabase()
Default constructor.
Definition: CSVDatabase.cpp:21
bool create(const std::string &file_name, const MPI_Comm comm=MPI_COMM_NULL) override
Creates a new CSV database file with the supplied name. NOTE: CSVDatabase does not actually create a ...
Definition: CSVDatabase.cpp:30
bool close()
Closes the currently open CSV database file.
Definition: CSVDatabase.cpp:49
virtual ~CSVDatabase()
Destructor.
Definition: CSVDatabase.cpp:25
int getDoubleArraySize(const std::string &file_name) override
Count the number of elements in an array of doubles associated with the supplied filename.
Definition: CSVDatabase.h:228
void getStringVector(const std::string &file_name, std::vector< std::string > &data, bool append=false)
Reads a vector of strings associated with the supplied filename.
void getDoubleVector(const std::string &file_name, std::vector< double > &data, bool append=false)
Reads a vector of doubles associated with the supplied filename.
void putDoubleArray(const std::string &file_name, const double *const data, int nelements, const bool distributed=false) override
Writes an array of doubles associated with the supplied filename.
Definition: CSVDatabase.cpp:74
void getDoubleArray(const std::string &file_name, double *data, int nelements, const bool distributed=false) override
Reads an array of doubles associated with the supplied filename.
void putStringVector(const std::string &file_name, const std::vector< std::string > &data, int nelements)
Writes a vector of strings associated with the supplied filename.
void putComplexVector(const std::string &file_name, const std::vector< std::complex< double >> &data, int nelements)
Writes a vector of complex doubles associated with the supplied filename.
bool open(const std::string &file_name, const std::string &type, const MPI_Comm comm=MPI_COMM_NULL) override
Opens an existing CSV database file with the supplied name. NOTE: CSVDatabase does not actually open ...
Definition: CSVDatabase.cpp:39