HDTree  0.5.2
HDTree C++ API
hdtree::AbstractBranch< DataType > Class Template Referenceabstract

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

#include <AbstractBranch.h>

Inheritance diagram for hdtree::AbstractBranch< DataType >:
[legend]
Collaboration diagram for hdtree::AbstractBranch< DataType >:
[legend]

Public Member Functions

 AbstractBranch (const std::string &branch_name, DataType *handle=nullptr)
 Define the dataset branch_name and provide an optional handle. More...
 
virtual ~AbstractBranch ()
 Delete our object if we own it, otherwise do nothing. More...
 
virtual void attach (Reader &f)=0
 pure virtual method for loading data from the input file More...
 
virtual void load ()=0
 pure virtual method for loading data More...
 
virtual void save ()=0
 pure virtual method for saving data More...
 
virtual void attach (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...
 
DataType & operator* ()
 Access the in-memory data object.
 
const DataType & operator* () const
 Access the in-memory data opbject in a const manner.
 
DataType * operator-> ()
 Pointer access to the in-memory data type.
 
const DataType * operator-> () const
 Pointer access to the in-memory data type in a const manner.
 
- Public Member Functions inherited from hdtree::BaseBranch
 BaseBranch (const std::string &full_name)
 define the full name of the branch
 
virtual ~BaseBranch ()=default
 virtual destructor so inherited classes can be properly destructed.
 
 BaseBranch (const BaseBranch &)=delete
 no copying
 
BaseBranchoperator= (const BaseBranch &)=delete
 no copying
 

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 hdtree::BaseBranch
std::string name_
 name of branch
 

Detailed Description

template<typename DataType>
class hdtree::AbstractBranch< 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

◆ AbstractBranch()

template<typename DataType >
hdtree::AbstractBranch< DataType >::AbstractBranch ( const std::string &  branch_name,
DataType *  handle = nullptr 
)
inlineexplicit

Define the dataset branch_name and provide an optional handle.

Defines the branch_name 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]namefull in-file branch_name to the data set
[in]handleaddress of object already created (optional)

◆ ~AbstractBranch()

template<typename DataType >
virtual hdtree::AbstractBranch< DataType >::~AbstractBranch ( )
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 Branch specializations!

Member Function Documentation

◆ attach() [1/2]

◆ attach() [2/2]

◆ clear()

template<typename DataType >
virtual void hdtree::AbstractBranch< 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 hdtree::BaseBranch.

◆ get()

template<typename DataType >
virtual const DataType& hdtree::AbstractBranch< 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()

◆ update()

template<typename DataType >
virtual void hdtree::AbstractBranch< 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 hdtree::AbstractBranch< 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 file: