TBTK
TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable > Class Template Reference

Abstract Property class. More...

#include <AbstractProperty.h>

Inheritance diagram for TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >:
TBTK::Serializable

Public Member Functions

unsigned int getBlockSize () const
 
unsigned int getSize () const
 
const std::vector< DataType > & getData () const
 
std::vector< DataType > & getDataRW ()
 
unsigned int getDimensions () const
 
std::vector< int > getRanges () const
 
int getOffset (const Index &index) const
 
const IndexDescriptorgetIndexDescriptor () const
 
bool contains (const Index &index) const
 
virtual const DataType & operator() (const Index &index, unsigned int offset=0) const
 
virtual DataType & operator() (const Index &index, unsigned int offset=0)
 
DataType & operator() (const std::initializer_list< int > &index)
 
const DataType & operator() (const std::initializer_list< int > &index) const
 
DataType & operator() (const std::initializer_list< unsigned int > &index)
 
const DataType & operator() (const std::initializer_list< unsigned int > &index) const
 
virtual const DataType & operator() (unsigned int offset) const
 
virtual DataType & operator() (unsigned int offset)
 
void setAllowIndexOutOfBoundsAccess (bool allowIndexOutOfBoundsAccess)
 
void setDefaultValue (const DataType &defaultValue)
 
virtual std::string serialize (Mode mode) const
 
template<>
std::string serialize (Mode mode) const
 
template<>
std::string serialize (Mode mode) const
 
template<>
std::string serialize (Mode mode) const
 
template<>
std::string serialize (Mode mode) const
 
template<>
std::string serialize (Mode mode) const
 
template<>
std::string serialize (Mode mode) const
 
template<>
std::string serialize (Mode mode) const
 

Protected Member Functions

 AbstractProperty ()
 
 AbstractProperty (unsigned int blockSize)
 
 AbstractProperty (unsigned int blockSize, const DataType *data)
 
 AbstractProperty (unsigned int dimensions, const int *ranges, unsigned int blockSize)
 
 AbstractProperty (unsigned int dimensions, const int *ranges, unsigned int blockSize, const DataType *data)
 
 AbstractProperty (const IndexTree &indexTree, unsigned int blockSize)
 
 AbstractProperty (const IndexTree &indexTree, unsigned int blockSize, const DataType *data)
 
 AbstractProperty (const AbstractProperty &abstractProperty)
 
 AbstractProperty (AbstractProperty &&abstractProperty)
 
 AbstractProperty (const std::string &serialization, Mode mode)
 
virtual ~AbstractProperty ()
 
AbstractPropertyoperator= (const AbstractProperty &abstractProperty)
 
AbstractPropertyoperator= (AbstractProperty &&abstractProperty)
 
template<>
 AbstractProperty (const std::string &serialization, Mode mode)
 
template<>
 AbstractProperty (const std::string &serialization, Mode mode)
 
template<>
 AbstractProperty (const std::string &serialization, Mode mode)
 
template<>
 AbstractProperty (const std::string &serialization, Mode mode)
 

Additional Inherited Members

- Public Types inherited from TBTK::Serializable
enum  Mode { Debug, Binary, XML, JSON }
 
- Static Public Member Functions inherited from TBTK::Serializable
static bool hasID (const std::string &serialization, Mode mode)
 
static std::string getID (const std::string &serialization, Mode mode)
 
static std::string extractComponent (const std::string &serialization, const std::string &containerID, const std::string &componentID, const std::string &componentName, Mode mode)
 
- Static Protected Member Functions inherited from TBTK::Serializable
static bool validate (const std::string &serialization, const std::string &id, Mode mode)
 
static std::string getContent (const std::string &serialization, Mode mode)
 
static std::vector< std::string > split (const std::string &content, Mode mode)
 
static std::string serialize (bool b, Mode mode)
 
static void deserialize (const std::string &serialization, bool *b, Mode mode)
 
static std::string serialize (int i, Mode mode)
 
static void deserialize (const std::string &serialization, int *i, Mode mode)
 
static std::string serialize (unsigned int u, Mode mode)
 
static void deserialize (const std::string &serialization, unsigned int *u, Mode mode)
 
static std::string serialize (double d, Mode mode)
 
static void deserialize (const std::string &serialization, double *d, Mode mode)
 
static std::string serialize (std::complex< double > c, Mode mode)
 
static void deserialize (const std::string &serialization, std::complex< double > *c, Mode mode)
 
static std::string serialize (Statistics s, Mode mode)
 
static void deserialize (const std::string &serialization, Statistics *s, Mode mode)
 
static std::string extract (const std::string &serialization, Mode mode, std::string component)
 

Detailed Description

template<typename DataType, bool isFundamental = std::is_fundamental<DataType>::value, bool isSerializable = std::is_base_of<Serializable, DataType>::value>
class TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >

Abstract Property class.

The AbstractProperty provides a generic storage for data of different type and storage structure and enables the implementation of specific Properties. To understand the storage structure, it is important to know that the Property structures data in several layers and that each layer is customizeable to allow for Properties with relatively different structure to be stored.

DataType:
The first layer allows for the data type of the individual data elements to be customized through the template argument DataType.

Block:
In the next layer data is grouped into blocks of N elements. This allows for Properties to be grouped without specific knowledge about what the group structure originates from. It is up to the individual Properties to give meaning to the internal structure of the block, but a common usage case is to store an energy resolved property for a number of energies.

Index structure:
In the third layer data blocks are given Indices . For flexibility and the ability to optimize for different use cases, several different storage formats are available for the Index structure and internally an IndexDescriptor is used to handle the differnt formats. These formats are:

IndexDescriptor::Format::None:
Used when the Property has no Index structure.

IndexDescriptor::Format::Ranges:
Used to store a Property for a (possibly multi-dimensional) range of Indices . The Ranges format is particularly efficient and imposes a regular grid structure on the data that sometimes can be required to for example plotting the Property. However, it has the limitation that it cannot be used to store Properties for a few select points on a grid, or for an Index strcucture that does not have a particular grid structure.

IndexDescriptor::Format::Custom:
The Custom format has the benefit of being able to store the Property for a custom selected set of Indices . It also allows the value of the Property to be accessed using the function notation property(index) or property(index, n). Where index is and Index and n is a number indexing into the data block for the given Index. To achieve this flexibility the Custom format comes with a slightly larger overhead than the Ranges format.

Sometimes it is usefull to input or access data in raw format, especially when writing custom Property classes or PropertyExtractors. In this case it is important to know that internally the data is stored in a single continous DataType array with blocks stored sequentially. The order the blocks are stored in when containing data for multiple Indices is such that if the Indices are added to an IndexTree, they appear in the order of the corresponding linear indices obtained from the IndexTree.

Constructor & Destructor Documentation

template<typename DataType , bool isFundamental, bool isSerializable>
TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::AbstractProperty ( )
protected

Constructs an uninitialized AbstractProperty.

template<typename DataType , bool isFundamental, bool isSerializable>
TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::AbstractProperty ( unsigned int  blockSize)
protected

Constructs an AbstractProperty with a single data block (i.e. no Index structure).

Parameters
blockSizeThe number of data elements in the block.
template<typename DataType, bool isFundamental, bool isSerializable>
TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::AbstractProperty ( unsigned int  blockSize,
const DataType *  data 
)
protected

Constructs an AbstractProperty with a single data block (i.e. no Index structure) and fills the internal memory with the data provided as input.

Parameters
blockSizeThe number of data elements in the block.
dataThe data stored on the raw format described in the detailed description of the class.
template<typename DataType, bool isFundamental, bool isSerializable>
TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::AbstractProperty ( unsigned int  dimensions,
const int *  ranges,
unsigned int  blockSize 
)
protected

Constructs an AbstractProperty with the Ranges format.

Parameters
dimensionsNumber of dimensons for the grid.
rangesA list of upper limits for the ranges of the different dimensions. The nth dimension will have the range [0, ranges[n]).
blockSizeThe number of data elements per block.
template<typename DataType, bool isFundamental, bool isSerializable>
TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::AbstractProperty ( unsigned int  dimensions,
const int *  ranges,
unsigned int  blockSize,
const DataType *  data 
)
protected

Constructs an AbstractProperty with the Ranges format and fills the internal memory with the data provided as input.

Parameters
dimensionsNumber of dimensons for the grid.
rangesA list of upper limits for the ranges of the different dimensions. The nth dimension will have the range [0, ranges[n]).
blockSizeThe number of data elements per block.
dataThe data stored on the raw format described in the detailed description of the class.
template<typename DataType, bool isFundamental, bool isSerializable>
TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::AbstractProperty ( const IndexTree indexTree,
unsigned int  blockSize 
)
protected

Constructs and AbstractProperty with the Custom format.

Parameters
indexTreeIndexTree containing the Indices that the AbstractProperty should contain data for.
blockSizeThe number of data elements per block.
template<typename DataType, bool isFundamental, bool isSerializable>
TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::AbstractProperty ( const IndexTree indexTree,
unsigned int  blockSize,
const DataType *  data 
)
protected

Constructs and AbstractProperty with the Custom format.

Parameters
indexTreeIndexTree containing the Indices that the AbstractProperty should contain data for.
blockSizeThe number of data elements per block.
dataThe data stored on the raw format described in the detailed description of the class.
template<typename DataType, bool isFundamental, bool isSerializable>
TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::AbstractProperty ( const AbstractProperty< DataType, isFundamental, isSerializable > &  abstractProperty)
protected

Copy constructor.

Parameters
abstractPropertyAbstractProperty to copy.
template<typename DataType, bool isFundamental, bool isSerializable>
TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::AbstractProperty ( AbstractProperty< DataType, isFundamental, isSerializable > &&  abstractProperty)
protected

Move constructor.

Parameters
abstractPropertyAbstractProperty to move.
template<typename DataType, bool isFundamental = std::is_fundamental<DataType>::value, bool isSerializable = std::is_base_of<Serializable, DataType>::value>
TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::AbstractProperty ( const std::string &  serialization,
Mode  mode 
)
protected

Constructor. Constructs the AbstractProperty from a serialization string.

Parameters
serializationSerialization string from which to construct the AbstractProperty.
modeMode with which the string has been serialized.
template<typename DataType , bool isFundamental, bool isSerializable>
TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::~AbstractProperty ( )
inlineprotectedvirtual

Destructor.

Member Function Documentation

template<typename DataType , bool isFundamental, bool isSerializable>
bool TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::contains ( const Index index) const
inline

Returns true if the property contains data for the given index. [Only works for the Custom format.]

Parameters
indexIndex to check.

True if the Property contains data for the given Index.

template<typename DataType , bool isFundamental, bool isSerializable>
unsigned int TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::getBlockSize ( ) const
inline

Get block size.

Returns
The size per block.
template<typename DataType , bool isFundamental, bool isSerializable>
const std::vector< DataType > & TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::getData ( ) const
inline

Get data.

Returns
The data on the raw format described in the detailed description.
template<typename DataType , bool isFundamental, bool isSerializable>
std::vector< DataType > & TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::getDataRW ( )
inline

Get data. Same as AbstractProperty::getData(), but with write access.

Returns
The data on the raw format described in the detailed description.
template<typename DataType , bool isFundamental, bool isSerializable>
unsigned int TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::getDimensions ( ) const
inline

Get the dimension of the data. [Only works for the Ranges format.]

Returns
The dimension of the grid that the data is calculated on.
template<typename DataType , bool isFundamental, bool isSerializable>
const IndexDescriptor & TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::getIndexDescriptor ( ) const
inline

Get IndexDescriptor.

Returns
The IndexDescriptor that is used internally to handle the different formats.
template<typename DataType , bool isFundamental, bool isSerializable>
int TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::getOffset ( const Index index) const
inline

Get the memory offset that should be used to access the raw data for the given Index. [Only works for the Custom format.]

Parameters
indexIndex for which to get the offset.
Returns
The memory offset for the given Index.
template<typename DataType , bool isFundamental, bool isSerializable>
std::vector< int > TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::getRanges ( ) const
inline

Get the ranges for the dimensions of the density. [Only works for the Ranges format.]

Returns
A list of ranges for the different dimensions of the grid the data is calculated on.
template<typename DataType , bool isFundamental, bool isSerializable>
unsigned int TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::getSize ( ) const
inline

Get size.

Returns
The total number of data elements in the Property. I.e. the number of blocks times the block size.
template<typename DataType , bool isFundamental, bool isSerializable>
const DataType & TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::operator() ( const Index index,
unsigned int  offset = 0 
) const
inlinevirtual

Function call operator. Returns the data element for the given Index and offset. By default the Property does not accept Indices that are not contained in the Property. However, AbstractProperty::setAllowIndexOutOfBounds(true) is called the Property will return the value set by a call to AbstractProperty::setDefaultVlue(). [Only works for the Custom format.]

Parameters
indexThe Index to get the data for.
offsetThe offset to apply inside the block for the given Index. If not specified, the first element is returned. The function can therefore be used without specifying the offset when Properties with only a single element per block. [Only works for the Custom format.]
Returns
The data element for the given Index and offset.

Reimplemented in TBTK::Property::WaveFunctions.

template<typename DataType , bool isFundamental, bool isSerializable>
DataType & TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::operator() ( const Index index,
unsigned int  offset = 0 
)
inlinevirtual

Function call operator. Returns the data element for the given Index and offset. By default the Property does not accept Indices that are not contained in the Property. However, AbstractProperty::setAllowIndexOutOfBounds(true) is called the Property will return the value set by a call to AbstractProperty::setDefaultVlue(). Note that although it is safe to write to out of bounds elements, doing so does not result in the value being stored in the Property. [Only works for Format::Custom].

Parameters
indexThe Index to get the data for.
offsetThe offset to apply inside the block for the given Index. If not specified, the first element is returned. The function can therefore be used without specifying the offset when Properties with only a single element per block. [Only works for the Custom format.]
Returns
The data element for the given Index and offset.

Reimplemented in TBTK::Property::WaveFunctions.

template<typename DataType , bool isFundamental, bool isSerializeable>
DataType & TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializeable >::operator() ( const std::initializer_list< int > &  index)
inline

Alias for operator()(const Index &index, unsigned int offset = 0). Ensures that operator()(unsigned int offset) is not called when calling the function operator default offset and a single subindex index operator()({1}). Without this {1} would be cast to 1 instead of Index({1}).

Parameters
indexThe Index to get the data for.
Returns
The data element for the given Index.
template<typename DataType , bool isFundamental, bool isSerializeable>
const DataType & TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializeable >::operator() ( const std::initializer_list< int > &  index) const
inline

Alias for operator()(const Index &index, unsigned int offset = 0). Ensures that operator()(unsigned int offset) is not called when calling the function operator default offset and a single subindex index operator()({1}). Without this {1} would be cast to 1 instead of Index({1}).

Parameters
indexThe Index to get the data for.
Returns
The data element for the given Index.
template<typename DataType , bool isFundamental, bool isSerializeable>
DataType & TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializeable >::operator() ( const std::initializer_list< unsigned int > &  index)
inline

Alias for operator()(const Index &index, unsigned int offset = 0). Ensures that operator()(unsigned int offset) is not called when calling the function operator default offset and a single subindex index operator()({1}). Without this {1} would be cast to 1 instead of Index({1}).

Parameters
indexThe Index to get the data for.
Returns
The data element for the given Index.
template<typename DataType , bool isFundamental, bool isSerializeable>
const DataType & TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializeable >::operator() ( const std::initializer_list< unsigned int > &  index) const
inline

Alias for operator()(const Index &index, unsigned int offset = 0). Ensures that operator()(unsigned int offset) is not called when calling the function operator default offset and a single subindex index operator()({1}). Without this {1} would be cast to 1 instead of Index({1}).

Parameters
indexThe Index to get the data for.
Returns
The data element for the given Index.
template<typename DataType , bool isFundamental, bool isSerializable>
const DataType & TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::operator() ( unsigned int  offset) const
inlinevirtual

Function call operator. Returns the data element for the given offset.

Parameters
offsetThe offset to apply. The offset is an index into the raw data.
Returns
The data element for the given offset.
template<typename DataType , bool isFundamental, bool isSerializable>
DataType & TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::operator() ( unsigned int  offset)
inlinevirtual

Function call operator. Returns the data element for the given offset.

Parameters
offsetThe offset to apply. The offset is an index into the raw data.
Returns
The data element for the given offset.
template<typename DataType , bool isFundamental, bool isSerializable>
AbstractProperty< DataType, isFundamental, isSerializable > & TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::operator= ( const AbstractProperty< DataType, isFundamental, isSerializable > &  abstractProperty)
protected

Assignment operator.

Parameters
rhsAbstractProperty to assign to the left hand side.
Returns
Reference to the assigned AbstractProperty.
template<typename DataType , bool isFundamental, bool isSerializable>
AbstractProperty< DataType, isFundamental, isSerializable > & TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::operator= ( AbstractProperty< DataType, isFundamental, isSerializable > &&  abstractProperty)
protected

Move assignment operator.

Parameters
rhsAbstractProperty to assign to the left hand side.
Returns
Reference to the assigned AbstractProperty.
template<typename DataType, bool isFundamental = std::is_fundamental<DataType>::value, bool isSerializable = std::is_base_of<Serializable, DataType>::value>
virtual std::string TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::serialize ( Mode  mode) const
virtual
template<>
std::string TBTK::Property::AbstractProperty< bool, true, false >::serialize ( Mode  mode) const
inlinevirtual

Serialize object.

Implements TBTK::Serializable.

template<>
std::string TBTK::Property::AbstractProperty< char, true, false >::serialize ( Mode  mode) const
inlinevirtual

Serialize object.

Implements TBTK::Serializable.

template<>
std::string TBTK::Property::AbstractProperty< int, true, false >::serialize ( Mode  mode) const
inlinevirtual

Serialize object.

Implements TBTK::Serializable.

template<>
std::string TBTK::Property::AbstractProperty< float, true, false >::serialize ( Mode  mode) const
inlinevirtual

Serialize object.

Implements TBTK::Serializable.

template<>
std::string TBTK::Property::AbstractProperty< double, true, false >::serialize ( Mode  mode) const
inlinevirtual

Serialize object.

Implements TBTK::Serializable.

template<>
std::string TBTK::Property::AbstractProperty< std::complex< double >, false, false >::serialize ( Mode  mode) const
inlinevirtual

Serialize object.

Implements TBTK::Serializable.

template<>
std::string TBTK::Property::AbstractProperty< SpinMatrix, false, false >::serialize ( Mode  mode) const
inlinevirtual

Serialize object.

Implements TBTK::Serializable.

template<typename DataType , bool isFundamental, bool isSerializable>
void TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::setAllowIndexOutOfBoundsAccess ( bool  allowIndexOutOfBoundsAccess)
inline

Set whether the access of data elements for Indices that are not contained in the Property is allowed or not when using the function operator AbstractProperty::operator(). If enabled, remember to also initialize the value that is used for out of bounds access using AbstractProperty::setDefaultValue(). [Only meaningful for the Custom format.]

Parameters
allowIndexOutOfBoundsAccessTrue to enable out of bounds access.
template<typename DataType, bool isFundamental, bool isSerializable>
void TBTK::Property::AbstractProperty< DataType, isFundamental, isSerializable >::setDefaultValue ( const DataType &  defaultValue)
inline

Set the value that is returned when accessing indices not contained in the Property using the function operator AbstractProperty::operator(). Only used if AbstractProperty::setAllowIndexOutOfBoundsAccess(true) is called. [Only meaningful for the Custom format.]

Parameters
defaultValueThe value that will be returned for out of bounds access.

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