ocssw
V2022
|
#include <DatFile.hpp>
Public Member Functions | |
DatFile ()=default | |
DatFile (const std::string &file) | |
DatFile (const std::string &file, Callback callback) | |
bool | load (const std::string &file) |
bool | load (std::istream &in) |
bool | load_line (const std::string &line) |
bool | empty () |
std::unordered_map< std::string, std::vector< double > >::const_iterator | begin () const |
std::unordered_map< std::string, std::vector< double > >::const_iterator | end () const |
std::vector< double > & | operator[] (const std::string &k) |
std::vector< double > & | operator[] (std::string &&k) |
void | callback (Callback callback) |
Callback | callback () |
Friends | |
std::ostream & | operator<< (std::ostream &os, const DatFile &kv) |
Detailed Description
.dat file reader
.dat files are key-value stores primarily used to store arrays of values. Singular values are supported, but this implementation treats them as vectors with a single element. On top of that, the indices given in the file are honored, so most variable indices start at 1.
Format
Usage
Definition at line 29 of file DatFile.hpp.
Constructor & Destructor Documentation
◆ DatFile() [1/3]
|
default |
Default constructor, creates an empty object.
◆ DatFile() [2/3]
|
explicit |
Create a new object and load the given file upon creation.
- Parameters
-
file Path of file to load
◆ DatFile() [3/3]
DatFile | ( | const std::string & | file, |
Callback | callback | ||
) |
Load a file, calling a user function for each line read.
- Parameters
-
file Path of file to load callback User function to call
Member Function Documentation
◆ begin()
std::unordered_map<std::string, std::vector<double> >::const_iterator begin | ( | ) | const |
Iterator returning each variable read.
- Returns
- Beginning iterator
◆ callback() [1/2]
|
inline |
Return the user function to call for each line.
- Returns
- The currently set user function
Definition at line 130 of file DatFile.hpp.
◆ callback() [2/2]
|
inline |
Set the user function to call for each line.
- Parameters
-
callback User function to use
Definition at line 124 of file DatFile.hpp.
◆ empty()
|
inline |
Definition at line 73 of file DatFile.hpp.
◆ end()
std::unordered_map<std::string, std::vector<double> >::const_iterator end | ( | ) | const |
End variable iterator.
- Returns
- Ending iterator
◆ load() [1/2]
bool load | ( | const std::string & | file | ) |
Load dat file from path.
- Parameters
-
file Path of file to load
- Returns
- true on failure, false on success
◆ load() [2/2]
bool load | ( | std::istream & | in | ) |
Load dat file from input stream.
- Parameters
-
in stream from which to load data
- Returns
- true on failure, false on success
◆ load_line()
bool load_line | ( | const std::string & | line | ) |
Load a single line.
- Parameters
-
line key-value line to load
- Returns
- true on failure, false on success
◆ operator[]() [1/2]
std::vector<double>& operator[] | ( | const std::string & | k | ) |
Access a variable.
If the variable doesn't exist, it'll silently be created.
- Parameters
-
k name of vector
- Returns
- reference to variable's vector
◆ operator[]() [2/2]
std::vector<double>& operator[] | ( | std::string && | k | ) |
Access a variable.
If the variable doesn't exist, it'll silently be created.
- Parameters
-
k name of vector
- Returns
- reference to variable's vector
Friends And Related Function Documentation
◆ operator<<
Output dat file to stream.
- Parameters
-
os Target output stream kv DatFile object to print
- Returns
- Given output stream, for chaining
The documentation for this class was generated from the following file:
- /gfs-oceanweb/web/ocssw/ocssw_src/include/focs/DatFile.hpp