VRS
A file format for sensor data.
Loading...
Searching...
No Matches
vrs::DataPieceEnum< EnumType, StorageType > Class Template Reference

DataPieceValue specialization class to store enums more conveniently and safely. More...

#include <DataPieceValue.h>

Inheritance diagram for vrs::DataPieceEnum< EnumType, StorageType >:
vrs::DataPieceValue< StorageType > vrs::DataPiece

Public Member Functions

 DataPieceEnum (const string &label)
 DataPieceEnum (const string &label, EnumType defaultValue)
EnumType get () const
bool get (EnumType &e) const
bool set (const EnumType e)
void setDefault (const EnumType defaultValue)
EnumType getDefault () const
bool getDefault (EnumType &outDefault) const
Public Member Functions inherited from vrs::DataPieceValue< StorageType >
 DataPieceValue (string label, StorageType defaultValue={})
const string & getElementTypeName () const override
size_t getVariableSize () const override
size_t collectVariableData (int8_t *, size_t) override
StorageType get () const
bool set (const StorageType &value)
void setDefault (const StorageType &defaultValue)
const StorageType & getDefault () const
void initToDefault () override
 Initialize to default value.
bool getProperty (const string &propertyName, StorageType &outValue) const
void setProperty (const string &propertyName, StorageType value)
bool getMin (StorageType &outMin) const
bool getMax (StorageType &outMax) const
bool getMinIncrement (StorageType &outMinIncrement) const
bool getMaxIncrement (StorageType &outMaxIncrement) const
void setMin (StorageType min)
void setMax (StorageType max)
void setRange (StorageType min, StorageType max)
void setMinIncrement (StorageType minIncrement)
void setMaxIncrement (StorageType maxIncrement)
void setIncrement (StorageType minIncrement, StorageType maxIncrement)
bool patchValue (StorageType value) const
bool isAvailable () const override
void print (ostream &out, const string &indent) const override
void printCompact (ostream &out, const string &indent) const override
bool isSame (const DataPiece *rhs) const override
void serialize (JsonWrapper &jsonWrapper, const JsonFormatProfileSpec &profile) override
unique_ptr< DataPiece > clone () const override
Public Member Functions inherited from vrs::DataPiece
const DataLayout & getDataLayout () const
const string & getLabel () const
DataPieceType getPieceType () const
string getTypeName () const
size_t getPieceIndex () const
size_t getOffset () const
bool hasFixedSize () const
size_t getFixedSize () const
bool getTag (const string &tagName, string &outTag) const
void setTag (const string &tagName, const string &tag)
bool getUnit (string &outUnit) const
void setUnit (const string &unit)
bool getDescription (string &outDescription) const
void setDescription (const string &description)
void setRequired (bool required=true)
bool isRequired () const
bool isMapped () const
 Tells if the DataPiece is mapped to another DataPiece in a mapped DataLayout.
virtual bool stageCurrentValue ()

Additional Inherited Members

Protected Member Functions inherited from vrs::DataPieceValue< StorageType >
bool copyFrom (const DataPiece *original) override
 Set or stage value from another piece known to be of the same type.
Protected Member Functions inherited from vrs::DataPiece
 DataPiece (string label, DataPieceType type, size_t size)
bool isMatch (const DataPiece &rhs) const
 Match signature only.
void setIndexOffset (size_t pieceIndex, size_t offset)
Protected Attributes inherited from vrs::DataPiece
const string label_
const DataPieceType pieceType_
const size_t fixedSize_
size_t pieceIndex_
size_t offset_
DataLayout & layout_
map< string, string > tags_
bool required_
Static Protected Attributes inherited from vrs::DataPiece
static const string kUnit = "unit"
 Special tag name to specify a unit of the DataPiece.
static const string kDescription = "description"
 Special tag name to specify a human readable description the DataPiece.
static const string kMinValue = "min"
 Special property name for the minimum value of the DataPiece.
static const string kMaxValue = "max"
 Special property name for the maximum value of the DataPiece.
static const string kMinIncrement = "min_increment"
 Special property name for the minimum increment of the DataPiece.
static const string kMaxIncrement = "max_increment"
 Special property name for the maximum increment of the DataPiece.

Detailed Description

template<typename EnumType, typename StorageType>
class vrs::DataPieceEnum< EnumType, StorageType >

DataPieceValue specialization class to store enums more conveniently and safely.

This DataPiece type is very light layer on top of DataPieceValue. DataPieceEnum provides automatic casting between an enum type and an explicit POD type. DataPieceEnum is safer to use, because it gives explicit control over the numeric type used to store the enum in the file format.

ATTENTION! STORING ENUM VALUES IS RISKY!

  • It's very easy to change an enum definition and break compatibility with existing files. Be certain the enum's numeric values aren't changed, or shifted when the enum is modified, maybe by adding static asserts verifying enum numeric values are never changed. In particular, avoid storing enums which definition is maintained by other teams.
  • The underlying type is DataPieceValue<StorageType>, therefore labels must not collide.

Constructor & Destructor Documentation

◆ DataPieceEnum() [1/2]

template<typename EnumType, typename StorageType>
vrs::DataPieceEnum< EnumType, StorageType >::DataPieceEnum ( const string & label)
inlineexplicit
Parameters
labelName for the DataPiece.

◆ DataPieceEnum() [2/2]

template<typename EnumType, typename StorageType>
vrs::DataPieceEnum< EnumType, StorageType >::DataPieceEnum ( const string & label,
EnumType defaultValue )
inline
Parameters
labelName for the DataPiece.
defaultValueDefault value for the DataPiece.

Member Function Documentation

◆ get() [1/2]

template<typename EnumType, typename StorageType>
EnumType vrs::DataPieceEnum< EnumType, StorageType >::get ( ) const
inline

Get the value in enum form.

Returns
The value as an enum. If the DataPiece isn't mapped, returns the default value.

◆ get() [2/2]

template<typename EnumType, typename StorageType>
bool vrs::DataPieceEnum< EnumType, StorageType >::get ( EnumType & e) const
inline

Get the value in enum form, with test for availability.

Parameters
eA reference to the enum to get.
Returns
True if the value was set. If the DataPiece isn't mapped, returns false.

◆ getDefault() [1/2]

template<typename EnumType, typename StorageType>
EnumType vrs::DataPieceEnum< EnumType, StorageType >::getDefault ( ) const
inline

Get the default value returned by get() when the DataPiece is not mapped.

Returns
Default value if one was specified, or default value for the enum.

◆ getDefault() [2/2]

template<typename EnumType, typename StorageType>
bool vrs::DataPieceEnum< EnumType, StorageType >::getDefault ( EnumType & outDefault) const
inline

Get the default value returned by get() when the DataPiece is not mapped.

Parameters
referenceReference to the variable to set.
Returns
True if the value was set to an explicitly specified default value.

◆ set()

template<typename EnumType, typename StorageType>
bool vrs::DataPieceEnum< EnumType, StorageType >::set ( const EnumType e)
inline

Set value in enum form.

Parameters
valueValue to set the DataPiece to.
Returns
False if the DataLayout is mapped, but this DataPiece is not mapped.

◆ setDefault()

template<typename EnumType, typename StorageType>
void vrs::DataPieceEnum< EnumType, StorageType >::setDefault ( const EnumType defaultValue)
inline

Specify a default value returned by get() when the DataPiece is not mapped. This value is not automatically used as an initialization value for the DataPiece.

Parameters
defaultValueValue to use as default.

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