COMMS
Template library intended to help with implementation of communication protocols.
Public Types | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Related Functions | List of all members
comms::field::FloatValue< TFieldBase, T, TOptions > Class Template Reference

#include "comms/field/FloatValue.h"

Detailed Description

template<typename TFieldBase, typename T, typename... TOptions>
class comms::field::FloatValue< TFieldBase, T, TOptions >

Field that represent floating point value.

Represents IEEE 754 floating point value, which means the value is serialised as is (consumes 4 bytes for float, and 8 bytes for double), using big or little endian.

Template Parameters
TFieldBaseBase class for this field, expected to be a variant of comms::Field.
TBasic underlying floating point type, must be either float or double.
TOptionsZero or more options that modify/refine default behaviour of the field. If no option is provided The field's value is serialised as is.
Base class to all the field classes.
Definition: Field.h:33
Field that represent floating point value.
Definition: FloatValue.h:60
In the example above it will consume 4 bytes (because sizeof(float) == 4) and will be serialised using big endian notation.
Supported options are:
Inheritance diagram for comms::field::FloatValue< TFieldBase, T, TOptions >:
comms::Field< TOptions >

Public Types

using CommsTag = typename BaseImpl::CommsTag
 Tag indicating type of the field.
 
using Endian = typename BaseImpl::Endian
 Endian used for serialisation.
 
using FieldBase = TFieldBase
 Base class provided in the first template parameter.
 
using FieldType = typename ParsedOptions::FieldType
 Type of actual extending field specified via comms::option::def::FieldType. More...
 
using ParsedOptions = details::OptionsParser< TOptions... >
 All the options provided to this class bundled into struct.
 
using UnitsRatio = typename ParsedOptions::UnitsRatio
 Scaling ratio determined by the forced units via the comms::option::def::Units* option. More...
 
using UnitsType = typename ParsedOptions::UnitsType
 Units type defined by any of the comms::option::def::Units* option. More...
 
using ValueType = typename BaseImpl::ValueType
 Type of underlying floating point value. More...
 
using VersionType = typename BaseImpl::VersionType
 Version type.
 

Public Member Functions

 FloatValue ()=default
 Default constructor. More...
 
 FloatValue (const ValueType &val)
 Constructor.
 
bool canWrite () const
 Check of whether the field has a consistent value for writing.
 
const ValueTypegetValue () const
 Get value. More...
 
VersionType getVersion () const
 Get version of the field. More...
 
constexpr std::size_t length () const
 Get length required to serialise the current field value. More...
 
template<typename TIter >
ErrorStatus read (TIter &iter, std::size_t size)
 Read field value from input data sequence. More...
 
template<typename TIter >
void readNoStatus (TIter &iter)
 Read field value from input data sequence without error check and status report. More...
 
bool refresh ()
 Refresh the field's value. More...
 
template<typename U >
void setValue (U &&val)
 Set value. More...
 
bool setVersion (VersionType version)
 Default implementation of version update. More...
 
bool valid () const
 Check validity of the field value.
 
ValueTypevalue ()
 Get access to floating point value storage.
 
const ValueTypevalue () const
 Get access to floating point value storage.
 
template<typename TIter >
ErrorStatus write (TIter &iter, std::size_t size) const
 Write current field value to output data sequence. More...
 
template<typename TIter >
void writeNoStatus (TIter &iter) const
 Write current field value to output data sequence without error check and status report. More...
 

Static Public Member Functions

static constexpr bool canWrite ()
 Default check of whether the field has a consistent value for writing. More...
 
static constexpr bool hasEmptySerialization ()
 Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
 
static constexpr bool hasFailOnInvalid ()
 Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
 
static constexpr bool hasFieldType ()
 Compile time inquiry of whether comms::option::def::FieldType option has been used.
 
static constexpr bool hasIgnoreInvalid ()
 Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
 
static constexpr bool hasNonDefaultRefresh ()
 Compile time check if this class has non-default refresh functionality.
 
static constexpr bool hasReadNoStatus ()
 Compile time check of whether the field has proper readNoStatus() member function.
 
static constexpr bool hasUnits ()
 Compile type inquiry of whether units have been set via any of the comms::option::def::Units* options.
 
static constexpr bool hasVarLength ()
 Default check of whether the field has variable length definition via comms::option::def::VarLength option. More...
 
static constexpr bool hasWriteNoStatus ()
 Compile time check of whether the field has proper writeNoStatus() member function.
 
static constexpr bool isVersionDependent ()
 Compile time check if this class is version dependent.
 
static constexpr std::size_t maxLength ()
 Get maximal length that is required to serialise field of this type. More...
 
static constexpr std::size_t minLength ()
 Get minimal length that is required to serialise field of this type. More...
 
static constexpr bool valid ()
 Default validity check. More...
 

Static Protected Member Functions

template<typename T , typename TIter >
static T readData (TIter &iter)
 Read data from input buffer. More...
 
template<typename T , std::size_t TSize, typename TIter >
static T readData (TIter &iter)
 Read partial data from input buffer. More...
 
template<typename T , typename TIter >
static void writeData (T value, TIter &iter)
 Write data into the output buffer. More...
 
template<std::size_t TSize, typename T , typename TIter >
static void writeData (T value, TIter &iter)
 Write partial data into the output buffer. More...
 

Related Functions

(Note that these are not member functions.)

template<typename T >
constexpr bool isFloatValue ()
 Compile time check function of whether a provided type is any variant of comms::field::FloatValue. More...
 
template<typename TFieldBase , typename T , typename... TOptions>
bool operator!= (const FloatValue< TFieldBase, T, TOptions... > &field1, const FloatValue< TFieldBase, T, TOptions... > &field2) noexcept
 Non-equality comparison operator. More...
 
template<typename TFieldBase , typename T , typename... TOptions>
bool operator< (const FloatValue< TFieldBase, T, TOptions... > &field1, const FloatValue< TFieldBase, T, TOptions... > &field2) noexcept
 Equivalence comparison operator. More...
 
template<typename TFieldBase , typename T , typename... TOptions>
bool operator== (const FloatValue< TFieldBase, T, TOptions... > &field1, const FloatValue< TFieldBase, T, TOptions... > &field2) noexcept
 Equality comparison operator. More...
 
template<typename TFieldBase , typename T , typename... TOptions>
const FloatValue< TFieldBase, T, TOptions... > & toFieldBase (const FloatValue< TFieldBase, T, TOptions... > &field)
 Upcast type of the field definition to its parent comms::field::FloatValue type in order to have access to its internal types.
 
template<typename TFieldBase , typename T , typename... TOptions>
FloatValue< TFieldBase, T, TOptions... > & toFieldBase (FloatValue< TFieldBase, T, TOptions... > &field)
 Upcast type of the field definition to its parent comms::field::FloatValue type in order to have access to its internal types.
 

Member Typedef Documentation

◆ FieldType

template<typename TFieldBase , typename T , typename... TOptions>
using comms::field::FloatValue< TFieldBase, T, TOptions >::FieldType = typename ParsedOptions::FieldType

Type of actual extending field specified via comms::option::def::FieldType.

void if comms::option::def::FieldType hasn't been applied.

◆ UnitsRatio

template<typename TFieldBase , typename T , typename... TOptions>
using comms::field::FloatValue< TFieldBase, T, TOptions >::UnitsRatio = typename ParsedOptions::UnitsRatio

Scaling ratio determined by the forced units via the comms::option::def::Units* option.

Equals to std::ratio<1, 1> if the option hasn't been used.

◆ UnitsType

template<typename TFieldBase , typename T , typename... TOptions>
using comms::field::FloatValue< TFieldBase, T, TOptions >::UnitsType = typename ParsedOptions::UnitsType

Units type defined by any of the comms::option::def::Units* option.

Aliased to void if no relevant options is used.

◆ ValueType

template<typename TFieldBase , typename T , typename... TOptions>
using comms::field::FloatValue< TFieldBase, T, TOptions >::ValueType = typename BaseImpl::ValueType

Type of underlying floating point value.

Same as template parameter T to this class.

Constructor & Destructor Documentation

◆ FloatValue()

template<typename TFieldBase , typename T , typename... TOptions>
comms::field::FloatValue< TFieldBase, T, TOptions >::FloatValue ( )
default

Default constructor.

Initialises internal value to 0.

Member Function Documentation

◆ canWrite()

template<typename... TOptions>
static constexpr bool comms::Field< TOptions >::canWrite ( )
staticconstexprinherited

Default check of whether the field has a consistent value for writing.

Returns
Always true.

◆ getValue()

template<typename TFieldBase , typename T , typename... TOptions>
const ValueType& comms::field::FloatValue< TFieldBase, T, TOptions >::getValue ( ) const

Get value.

Implemented by calling value(), but can be overriden in the derived class

◆ getVersion()

template<typename TFieldBase , typename T , typename... TOptions>
VersionType comms::field::FloatValue< TFieldBase, T, TOptions >::getVersion ( ) const

Get version of the field.

Exists only if comms::option::def::VersionStorage option has been provided.

◆ hasVarLength()

template<typename... TOptions>
static constexpr bool comms::Field< TOptions >::hasVarLength ( )
staticconstexprinherited

Default check of whether the field has variable length definition via comms::option::def::VarLength option.

Returns
Always false.

◆ length()

template<typename TFieldBase , typename T , typename... TOptions>
constexpr std::size_t comms::field::FloatValue< TFieldBase, T, TOptions >::length ( ) const
constexpr

Get length required to serialise the current field value.

Returns
Number of bytes it will take to serialise the field value.

◆ maxLength()

template<typename TFieldBase , typename T , typename... TOptions>
static constexpr std::size_t comms::field::FloatValue< TFieldBase, T, TOptions >::maxLength ( )
staticconstexpr

Get maximal length that is required to serialise field of this type.

Returns
Maximal number of bytes required serialise the field value.

◆ minLength()

template<typename TFieldBase , typename T , typename... TOptions>
static constexpr std::size_t comms::field::FloatValue< TFieldBase, T, TOptions >::minLength ( )
staticconstexpr

Get minimal length that is required to serialise field of this type.

Returns
Minimal number of bytes required serialise the field value.

◆ read()

template<typename TFieldBase , typename T , typename... TOptions>
template<typename TIter >
ErrorStatus comms::field::FloatValue< TFieldBase, T, TOptions >::read ( TIter &  iter,
std::size_t  size 
)

Read field value from input data sequence.

Parameters
[in,out]iterIterator to read the data.
[in]sizeNumber of bytes available for reading.
Returns
Status of read operation.
Postcondition
Iterator is advanced.

◆ readData() [1/2]

template<typename... TOptions>
template<typename T , typename TIter >
static T comms::Field< TOptions >::readData ( TIter &  iter)
staticprotectedinherited

Read data from input buffer.

Use this function to read data from the intput buffer maintained by the caller. The endianness of the data will be as specified in options of the class.

Template Parameters
TReturn type
TIterType of input iterator
Parameters
[in,out]iterInput iterator.
Returns
The integral type value.
Precondition
TSize <= sizeof(T)
The iterator must be valid and can be successfully dereferenced and incremented at least sizeof(T) times.
Postcondition
The iterator is advanced.
Note
Thread safety: Safe for distinct stream buffers, unsafe otherwise.

◆ readData() [2/2]

template<typename... TOptions>
template<typename T , std::size_t TSize, typename TIter >
static T comms::Field< TOptions >::readData ( TIter &  iter)
staticprotectedinherited

Read partial data from input buffer.

Use this function to read data from the intput buffer maintained by the caller. The endianness of the data will be as specified in options of the class.

Template Parameters
TReturn type
TSizenumber of bytes to read
TIterType of input iterator
Parameters
[in,out]iterInput iterator.
Returns
The integral type value.
Precondition
TSize <= sizeof(T)
The iterator must be valid and can be successfully dereferenced and incremented at least TSize times.
Postcondition
The internal pointer of the stream buffer is advanced.
Note
Thread safety: Safe for distinct stream buffers, unsafe otherwise.

◆ readNoStatus()

template<typename TFieldBase , typename T , typename... TOptions>
template<typename TIter >
void comms::field::FloatValue< TFieldBase, T, TOptions >::readNoStatus ( TIter &  iter)

Read field value from input data sequence without error check and status report.

Similar to read(), but doesn't perform any correctness checks and doesn't report any failures.

Parameters
[in,out]iterIterator to read the data.
Postcondition
Iterator is advanced.

◆ refresh()

template<typename TFieldBase , typename T , typename... TOptions>
bool comms::field::FloatValue< TFieldBase, T, TOptions >::refresh ( )

Refresh the field's value.

Returns
true if the value has been updated, false otherwise

◆ setValue()

template<typename TFieldBase , typename T , typename... TOptions>
template<typename U >
void comms::field::FloatValue< TFieldBase, T, TOptions >::setValue ( U &&  val)

Set value.

Implemented as re-assigning to value(), but can be overriden in the derived class.

◆ setVersion()

template<typename TFieldBase , typename T , typename... TOptions>
bool comms::field::FloatValue< TFieldBase, T, TOptions >::setVersion ( VersionType  version)

Default implementation of version update.

Returns
true in case the field contents have changed, false otherwise

◆ valid()

template<typename... TOptions>
static constexpr bool comms::Field< TOptions >::valid ( )
staticconstexprinherited

Default validity check.

Always returns true, can be overriden by the derived class

Returns
Always true

◆ write()

template<typename TFieldBase , typename T , typename... TOptions>
template<typename TIter >
ErrorStatus comms::field::FloatValue< TFieldBase, T, TOptions >::write ( TIter &  iter,
std::size_t  size 
) const

Write current field value to output data sequence.

Parameters
[in,out]iterIterator to write the data.
[in]sizeMaximal number of bytes that can be written.
Returns
Status of write operation.
Postcondition
Iterator is advanced.

◆ writeData() [1/2]

template<typename... TOptions>
template<typename T , typename TIter >
static void comms::Field< TOptions >::writeData ( value,
TIter &  iter 
)
staticprotectedinherited

Write data into the output buffer.

Use this function to write data to the the buffer maintained by the caller. The endianness of the data will be as specified in the options provided to the class.

Template Parameters
TType of the value to write. Must be integral.
Typeof output iterator
Parameters
[in]valueIntegral type value to be written.
[in,out]iterOutput iterator.
Precondition
The iterator must be valid and can be successfully dereferenced and incremented at least sizeof(T) times.
Postcondition
The iterator is advanced.
Note
Thread safety: Safe for distinct buffers, unsafe otherwise.

◆ writeData() [2/2]

template<typename... TOptions>
template<std::size_t TSize, typename T , typename TIter >
static void comms::Field< TOptions >::writeData ( value,
TIter &  iter 
)
staticprotectedinherited

Write partial data into the output buffer.

Use this function to write partial data to the buffer maintained by the caller. The endianness of the data will be as specified the class options.

Template Parameters
TSizeLength of the value in bytes known in compile time.
TType of the value to write. Must be integral.
TIterType of output iterator
Parameters
[in]valueIntegral type value to be written.
[in,out]iterOutput iterator.
Precondition
TSize <= sizeof(T)
The iterator must be valid and can be successfully dereferenced and incremented at least TSize times.
Postcondition
The iterator is advanced.
Note
Thread safety: Safe for distinct buffers, unsafe otherwise.

◆ writeNoStatus()

template<typename TFieldBase , typename T , typename... TOptions>
template<typename TIter >
void comms::field::FloatValue< TFieldBase, T, TOptions >::writeNoStatus ( TIter &  iter) const

Write current field value to output data sequence without error check and status report.

Similar to write(), but doesn't perform any correctness checks and doesn't report any failures.

Parameters
[in,out]iterIterator to write the data.
Postcondition
Iterator is advanced.

Friends And Related Function Documentation

◆ isFloatValue()

template<typename T >
constexpr bool isFloatValue ( )
related

Compile time check function of whether a provided type is any variant of comms::field::FloatValue.

Template Parameters
TAny type.
Returns
true in case provided type is any variant of FloatValue

◆ operator!=()

template<typename TFieldBase , typename T , typename... TOptions>
bool operator!= ( const FloatValue< TFieldBase, T, TOptions... > &  field1,
const FloatValue< TFieldBase, T, TOptions... > &  field2 
)
related

Non-equality comparison operator.

Parameters
[in]field1First field.
[in]field2Second field.
Returns
true in case fields are NOT equal, false otherwise.

◆ operator<()

template<typename TFieldBase , typename T , typename... TOptions>
bool operator< ( const FloatValue< TFieldBase, T, TOptions... > &  field1,
const FloatValue< TFieldBase, T, TOptions... > &  field2 
)
related

Equivalence comparison operator.

Parameters
[in]field1First field.
[in]field2Second field.
Returns
true in case value of the first field is lower than than the value of the second.

◆ operator==()

template<typename TFieldBase , typename T , typename... TOptions>
bool operator== ( const FloatValue< TFieldBase, T, TOptions... > &  field1,
const FloatValue< TFieldBase, T, TOptions... > &  field2 
)
related

Equality comparison operator.

Parameters
[in]field1First field.
[in]field2Second field.
Returns
true in case fields are equal, false otherwise.

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