fire v0.19.0
Framework for sImulation and Reconstruction of Events
|
Type-specific base class to hold common data methods. More...
#include <AbstractData.h>
Public Member Functions | |
AbstractData (const std::string &path, Reader *input_file=nullptr, DataType *handle=nullptr) | |
Define the dataset path and provide an optional handle. More... | |
virtual | ~AbstractData () |
Delete our object if we own it, otherwise do nothing. More... | |
virtual void | load (h5::Reader &f)=0 |
pure virtual method for loading data More... | |
virtual void | save (Writer &f)=0 |
pure virtual method for saving data More... | |
virtual void | structure (Writer &f)=0 |
pure virtual method for saving structure More... | |
virtual void | clear () |
Define the clear function here to handle the most common cases. More... | |
virtual const DataType & | get () const |
Get the current in-memory data. More... | |
int | version () const |
Get the version number for the type we are loading from. More... | |
virtual void | update (const DataType &val) |
Update the in-memory data object with the passed value. More... | |
Public Member Functions inherited from fire::io::BaseData | |
BaseData (const std::string &path) | |
Define the full in-file path to the data set of this data. More... | |
virtual | ~BaseData ()=default |
virtual destructor so inherited classes can be properly destructed. | |
Protected Attributes | |
std::optional< std::pair< std::string, int > > | load_type_ |
type this data is loading from | |
std::pair< std::string, int > | save_type_ |
type this data that is being used to write | |
DataType * | handle_ |
handle on current object in memory | |
bool | owner_ |
we own the object in memory | |
Protected Attributes inherited from fire::io::BaseData | |
std::string | path_ |
path of data set | |
Type-specific base class to hold common data methods.
Most (all I can think of?) have a shared initialization, destruction, getting and setting procedure. We can house these procedures in an intermediary class in the inheritence tree.
DataType | type of data being held in this set |
|
explicit |
Define the dataset path and provide an optional handle.
Defines the path to the data set in the file and the handle to the current in-memory version of the data.
If the handle is a nullptr, then we will own our own dynamically created copy of the data. If the handle is not a nullptr, then we assume a parent data set is holding the full object and we are simply holding a member variable, so we just copy the address into our handle.
This is the location in the code where we require user-defined data classes to be default-constructible.
[in] | path | full in-file path to the data set |
[in] | handle | address of object already created (optional) |
|
inlinevirtual |
Delete our object if we own it, otherwise do nothing.
|
inlinevirtual |
Define the clear function here to handle the most common cases.
We 'clear' the object our handle points to. 'clear' means two different things depending on the object.
void clear()
method defined.Case (1) handles the common fundamental types listed in the reference Numeric Limits
Case (2) handles common STL containers as well as std::string and is a simple requirement on user classes.
The if constexpr
statement is a C++17 feature that allows this if/else branch to be decided at compile time.
Implements fire::io::BaseData.
|
inlinevirtual |
Get the current in-memory data.
|
pure virtual |
pure virtual method for loading data
[in] | f | h5::Reader to load from |
Implements fire::io::BaseData.
Implemented in fire::io::Data< DataType, Enable >, fire::io::Data< AtomicType, std::enable_if_t< is_atomic_v< AtomicType > > >, fire::io::Data< std::vector< ContentType > >, fire::io::Data< std::map< KeyType, ValType > >, and fire::io::Data< ParameterStorage >.
|
pure virtual |
pure virtual method for saving data
[in] | f | Writer to save to |
Implements fire::io::BaseData.
Implemented in fire::io::Data< DataType, Enable >, fire::io::Data< AtomicType, std::enable_if_t< is_atomic_v< AtomicType > > >, fire::io::Data< std::vector< ContentType > >, fire::io::Data< std::map< KeyType, ValType > >, and fire::io::Data< ParameterStorage >.
|
pure virtual |
pure virtual method for saving structure
[in] | f | Writer to write to |
Implements fire::io::BaseData.
Implemented in fire::io::Data< DataType, Enable >, fire::io::Data< AtomicType, std::enable_if_t< is_atomic_v< AtomicType > > >, fire::io::Data< std::vector< ContentType > >, fire::io::Data< std::map< KeyType, ValType > >, and fire::io::Data< ParameterStorage >.
|
inlinevirtual |
Update the in-memory data object with the passed value.
We require that all classes we wish to read/write can use the assignment operator void operator=(const DataType&)
. This requirement is not reported in the documentation of fire::h5 because it is implicitly defined by the compiler unless explicitly deleted by the definer.
We perform a deep copy in our handle to the data so that the input object can feel free to go out of scope.
[in] | val | new value the in-memory object should be |
|
inline |
Get the version number for the type we are loading from.
If we are not loading from anything, we just return the version number of the type we are saving to.