Privacy
An open-source, flexible 3D physical simulation framework
mars::data_broker::DataPackageMapping Class Reference

A DataPackageMapping can be used by a Receiver to more conveniently retrieve values from a DataPackage. More...

#include <DataPackageMapping.h>

Public Member Functions

 DataPackageMapping ()
 
 ~DataPackageMapping ()
 
template<typename T >
void add (const std::string &itemName, T *var)
 Add a mapping from a DataItem::name to a variable. More...
 
bool readPackage (const DataPackage &package)
 Writes the values from the package to the mapped variables. More...
 
bool writePackage (DataPackage *package)
 
void clear ()
 

Private Member Functions

 DataPackageMapping (const DataPackageMapping &dpm)
 
DataPackageMappingoperator= (const DataPackageMapping &dpm)
 

Private Attributes

bool first
 
std::vector< DataItemAccessorBase * > accessors
 

Detailed Description

A DataPackageMapping can be used by a Receiver to more conveniently retrieve values from a DataPackage.

The DataPackageMapping is used to map certain DataItem::names to variables. This is done by calling add and giving the DataItem::name and a pointer to a variable of the appropriate type. The user is responsible for making sure the pointer is valid during the lifetime of the DataPackageMapping object. When a new DataPackage is received it can be passed to the DataPackageMapping's update method and it will retrieve the values from the DataPackage and write them to the variables.

Definition at line 100 of file DataPackageMapping.h.

Constructor & Destructor Documentation

◆ DataPackageMapping() [1/2]

mars::data_broker::DataPackageMapping::DataPackageMapping ( const DataPackageMapping dpm)
private

◆ DataPackageMapping() [2/2]

mars::data_broker::DataPackageMapping::DataPackageMapping ( )

Definition at line 27 of file DataPackageMapping.cpp.

◆ ~DataPackageMapping()

mars::data_broker::DataPackageMapping::~DataPackageMapping ( )

Definition at line 31 of file DataPackageMapping.cpp.

Member Function Documentation

◆ add()

template<typename T >
void mars::data_broker::DataPackageMapping::add ( const std::string &  itemName,
T *  var 
)
inline

Add a mapping from a DataItem::name to a variable.

Parameters
itemNameThe name of a DataItem in the DataPackage that should be mapped.
varA pointer to variable that belongs to the DataItem. The user is responsible for making sure the pointer is valid during the lifetime of the DataPackageMapping object.

Definition at line 117 of file DataPackageMapping.h.

◆ clear()

void mars::data_broker::DataPackageMapping::clear ( )

Definition at line 73 of file DataPackageMapping.cpp.

◆ operator=()

DataPackageMapping& mars::data_broker::DataPackageMapping::operator= ( const DataPackageMapping dpm)
private

◆ readPackage()

bool mars::data_broker::DataPackageMapping::readPackage ( const DataPackage package)

Writes the values from the package to the mapped variables.

Parameters
packageThe DataPackage whose DataItems should be retrieved. This will retrieve all DataItems for which there is a mapping and write the value to the corresponding variable.

Definition at line 35 of file DataPackageMapping.cpp.

◆ writePackage()

bool mars::data_broker::DataPackageMapping::writePackage ( DataPackage package)

Definition at line 54 of file DataPackageMapping.cpp.

Member Data Documentation

◆ accessors

std::vector<DataItemAccessorBase*> mars::data_broker::DataPackageMapping::accessors
private

Definition at line 134 of file DataPackageMapping.h.

◆ first

bool mars::data_broker::DataPackageMapping::first
private

Definition at line 133 of file DataPackageMapping.h.


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