fire v0.19.0
Framework for sImulation and Reconstruction of Events
fire::io::AbstractData< DataType > Class Template Referenceabstract

Type-specific base class to hold common data methods. More...

#include <AbstractData.h>

Inheritance diagram for fire::io::AbstractData< DataType >:
[legend]
Collaboration diagram for fire::io::AbstractData< DataType >:
[legend]

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
 

Detailed Description

template<typename DataType>
class fire::io::AbstractData< DataType >

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.

Template Parameters
DataTypetype of data being held in this set

Constructor & Destructor Documentation

◆ AbstractData()

template<typename DataType >
fire::io::AbstractData< DataType >::AbstractData ( const std::string path,
Reader input_file = nullptr,
DataType *  handle = nullptr 
)
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.

Parameters
[in]pathfull in-file path to the data set
[in]handleaddress of object already created (optional)

◆ ~AbstractData()

template<typename DataType >
virtual fire::io::AbstractData< DataType >::~AbstractData ( )
inlinevirtual

Delete our object if we own it, otherwise do nothing.

Note
This is virtual, but I can't think of a good reason to re-implement this function in downstream Data specializations!

Member Function Documentation

◆ clear()

template<typename DataType >
virtual void fire::io::AbstractData< DataType >::clear ( )
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.

  1. If the object is apart of 'numeric_limits', then we set it to the minimum.
  2. Otherwise, we assume the object has the 'clear' method defined.
    • This is where we require the user-defined classes to have a 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.

◆ get()

template<typename DataType >
virtual const DataType & fire::io::AbstractData< DataType >::get ( ) const
inlinevirtual

Get the current in-memory data.

Note
virtual so that derived data sets could specialize this, but I can't think of a reason to do so.
Returns
const reference to current data

◆ load()

◆ save()

template<typename DataType >
virtual void fire::io::AbstractData< DataType >::save ( Writer f)
pure virtual

◆ structure()

template<typename DataType >
virtual void fire::io::AbstractData< DataType >::structure ( Writer f)
pure virtual

◆ update()

template<typename DataType >
virtual void fire::io::AbstractData< DataType >::update ( const DataType &  val)
inlinevirtual

Update the in-memory data object with the passed value.

Note
virtual so that derived data sets could specialize this, but I can't think of a reason to do so.

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.

Parameters
[in]valnew value the in-memory object should be

◆ version()

template<typename DataType >
int fire::io::AbstractData< DataType >::version ( ) const
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.

Returns
version number

The documentation for this class was generated from the following files: