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::BitmaskValue< TFieldBase, TOptions > Class Template Reference

#include "comms/field/BitmaskValue.h"

Detailed Description

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

Bitmask value field.

Quite often communication protocols specify bitmask values, where any bit has a specific meaning. Although such masks are can be handled as unsigned integer values using comms::field::IntValue field type, using comms::field::Bitmask may be a bit more convenient.

Template Parameters
TFieldBaseBase class for this field, expected to be a variant of comms::Field.
TOptionsZero or more options that modify/refine default behaviour of the field. If no option is provided, the underlying type is assumed to be "unsigned", which is usually 4 bytes long. To redefined the length of the bitmask field, use comms::option::def::FixedLength option. For example:
Base class to all the field classes.
Definition: Field.h:33
Enumerator value field.
Definition: EnumValue.h:73
The serialised value of the field in the example above will consume sizeof(unsigned) bytes, because the underlying type chosen to be "unsigned" by default. Example below specifies simple bitmask value field with 2 bytes serialisation length: Supported options are:
See also
COMMS_BITMASK_BITS()
COMMS_BITMASK_BITS_ACCESS()
COMMS_BITMASK_BITS_ACCESS_NOTEMPLATE()
COMMS_BITMASK_BITS_SEQ()
COMMS_BITMASK_BITS_SEQ_NOTEMPLATE()
Inheritance diagram for comms::field::BitmaskValue< TFieldBase, TOptions >:
comms::Field< TOptions >

Public Types

using CommsTag = tag::Bitmask
 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 = OptionsBundle
 All the options provided to this class bundled into struct.
 
using ValueType = typename IntValueField::ValueType
 Type of underlying integral value. More...
 
using VersionType = typename BaseImpl::VersionType
 Version type.
 

Public Member Functions

 BitmaskValue ()=default
 Default constructor. More...
 
 BitmaskValue (const BitmaskValue &)=default
 Copy constructor.
 
 BitmaskValue (const ValueType &val)
 Constructor. More...
 
 ~BitmaskValue () noexcept=default
 Destructor.
 
bool canWrite () const
 Check of whether the field has a consistent value for writing.
 
void clearBits (ValueType mask)
 Set all the provided bits. More...
 
bool getBitValue (unsigned bitNum) const
 Get bit value.
 
int getForcedLength () const
 Get forced serialization length. More...
 
const ValueTypegetValue () const
 Get value.
 
VersionType getVersion () const
 Get version of the field. More...
 
bool hasAllBitsSet (ValueType mask) const
 Check whether all bits from provided mask are set. More...
 
bool hasAnyBitsSet (ValueType mask) const
 Check whether any bits from provided mask are set. More...
 
constexpr std::size_t length () const
 Get length required to serialise the current field value. More...
 
BitmaskValueoperator= (const BitmaskValue &)=default
 Copy assignment.
 
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 contents of the field. More...
 
void setBits (ValueType mask)
 Set all the provided bits. More...
 
void setBitValue (unsigned bitNum, bool val)
 Set bit value.
 
void setForcedLength (int len)
 Force serialization length of the field. More...
 
template<typename U >
void setValue (U &&val)
 Set value.
 
bool setVersion (VersionType version)
 Default implementation of version update. More...
 
constexpr bool valid () const
 Check validity of the field value.
 
ValueTypevalue ()
 Get access to underlying mask value storage. More...
 
const ValueTypevalue () const
 Get access to underlying mask value storage. More...
 
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 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.)

#define COMMS_BITMASK_BITS(...)   COMMS_DEFINE_ENUM(BitIdx, __VA_ARGS__)
 Provide names for bits in comms::field::BitmaskValue field. More...
 
#define COMMS_BITMASK_BITS_ACCESS(...)
 Generate access functions for bits in comms::field::BitmaskValue field. More...
 
#define COMMS_BITMASK_BITS_ACCESS_NOTEMPLATE(...)    COMMS_DO_BIT_ACC_FUNC((*this), __VA_ARGS__)
 Similar to COMMS_BITMASK_BITS_ACCESS(), but dedicated for non-template classes. More...
 
#define COMMS_BITMASK_BITS_SEQ(...)
 Combine usage of COMMS_BITMASK_BITS() and COMMS_BITMASK_BITS_ACCESS(). More...
 
#define COMMS_BITMASK_BITS_SEQ_NOTEMPLATE(...)
 Similar to COMMS_BITMASK_BITS_SEQ(), but dedicated for non-template classes. More...
 
template<typename T >
constexpr bool isBitmaskValue ()
 Compile time check function of whether a provided type is any variant of comms::field::BitmaskValue. More...
 
template<typename TFieldBase , typename... TOptions>
bool operator!= (const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
 Non-equality comparison operator. More...
 
template<typename TFieldBase , typename... TOptions>
bool operator< (const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
 Equivalence comparison operator. More...
 
template<typename TFieldBase , typename... TOptions>
bool operator== (const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
 Equality comparison operator. More...
 
template<typename TFieldBase , typename... TOptions>
BitmaskValue< TFieldBase, TOptions... > & toFieldBase (BitmaskValue< TFieldBase, TOptions... > &field)
 Upcast type of the field definition to its parent comms::field::BitmaskValue type in order to have access to its internal types.
 
template<typename TFieldBase , typename... TOptions>
const BitmaskValue< TFieldBase, TOptions... > & toFieldBase (const BitmaskValue< TFieldBase, TOptions... > &field)
 Upcast type of the field definition to its parent comms::field::BitmaskValue type in order to have access to its internal types.
 

Member Typedef Documentation

◆ FieldType

template<typename TFieldBase , typename... TOptions>
using comms::field::BitmaskValue< TFieldBase, 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.

◆ ValueType

template<typename TFieldBase , typename... TOptions>
using comms::field::BitmaskValue< TFieldBase, TOptions >::ValueType = typename IntValueField::ValueType

Type of underlying integral value.

Unsigned integral type, which depends on the length of the mask determined by the comms::option::def::FixedLength option.

Constructor & Destructor Documentation

◆ BitmaskValue() [1/2]

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

Default constructor.

Initial bitmask has all bits cleared (equals 0)

◆ BitmaskValue() [2/2]

template<typename TFieldBase , typename... TOptions>
comms::field::BitmaskValue< TFieldBase, TOptions >::BitmaskValue ( const ValueType val)
explicit

Constructor.

Parameters
[in]valValue of the field to initialise it with.

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.

◆ clearBits()

template<typename TFieldBase , typename... TOptions>
void comms::field::BitmaskValue< TFieldBase, TOptions >::clearBits ( ValueType  mask)

Set all the provided bits.

Equivalent to

value() &= (~mask);
const ValueType & value() const
Get access to underlying mask value storage.
Definition: BitmaskValue.h:193
Parameters
[in]maskMask of bits to clear.

◆ getForcedLength()

template<typename TFieldBase , typename... TOptions>
int comms::field::BitmaskValue< TFieldBase, TOptions >::getForcedLength ( ) const

Get forced serialization length.

See also
setForcedLength()

◆ getVersion()

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

Get version of the field.

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

◆ hasAllBitsSet()

template<typename TFieldBase , typename... TOptions>
bool comms::field::BitmaskValue< TFieldBase, TOptions >::hasAllBitsSet ( ValueType  mask) const

Check whether all bits from provided mask are set.

Parameters
[in]maskMask to check against
Returns
true in case all the bits are set, false otherwise

◆ hasAnyBitsSet()

template<typename TFieldBase , typename... TOptions>
bool comms::field::BitmaskValue< TFieldBase, TOptions >::hasAnyBitsSet ( ValueType  mask) const

Check whether any bits from provided mask are set.

Parameters
[in]maskMask to check against
Returns
true in case at least one of the bits is set, false otherwise.

◆ 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... TOptions>
constexpr std::size_t comms::field::BitmaskValue< TFieldBase, 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... TOptions>
static constexpr std::size_t comms::field::BitmaskValue< TFieldBase, 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... TOptions>
static constexpr std::size_t comms::field::BitmaskValue< TFieldBase, 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... TOptions>
template<typename TIter >
ErrorStatus comms::field::BitmaskValue< TFieldBase, 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... TOptions>
template<typename TIter >
void comms::field::BitmaskValue< TFieldBase, 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... TOptions>
bool comms::field::BitmaskValue< TFieldBase, TOptions >::refresh ( )

Refresh contents of the field.

Returns
true in case the field's value has been updated, false otherwise

◆ setBits()

template<typename TFieldBase , typename... TOptions>
void comms::field::BitmaskValue< TFieldBase, TOptions >::setBits ( ValueType  mask)

Set all the provided bits.

Equivalent to

value() |= mask;
Parameters
[in]maskMask of bits to set.

◆ setForcedLength()

template<typename TFieldBase , typename... TOptions>
void comms::field::BitmaskValue< TFieldBase, TOptions >::setForcedLength ( int  len)

Force serialization length of the field.

Available only when comms::option::def::AvailableLengthLimit option is used for field definition.

Parameters
[in]lenForced serialization length.
  • 0 means default serialization length determined by the storage type
  • positive value means limit of the serialization length
  • negative value means the length is determined by the stored value

◆ setVersion()

template<typename TFieldBase , typename... TOptions>
bool comms::field::BitmaskValue< TFieldBase, 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

◆ value() [1/2]

template<typename TFieldBase , typename... TOptions>
ValueType& comms::field::BitmaskValue< TFieldBase, TOptions >::value ( )

Get access to underlying mask value storage.

Returns
Reference to the underlying stored value.

◆ value() [2/2]

template<typename TFieldBase , typename... TOptions>
const ValueType& comms::field::BitmaskValue< TFieldBase, TOptions >::value ( ) const

Get access to underlying mask value storage.

Returns
Const reference to the underlying stored value.

◆ write()

template<typename TFieldBase , typename... TOptions>
template<typename TIter >
ErrorStatus comms::field::BitmaskValue< TFieldBase, 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... TOptions>
template<typename TIter >
void comms::field::BitmaskValue< TFieldBase, 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

◆ COMMS_BITMASK_BITS

template<typename TFieldBase , typename... TOptions>
#define COMMS_BITMASK_BITS (   ...)    COMMS_DEFINE_ENUM(BitIdx, __VA_ARGS__)
related

Provide names for bits in comms::field::BitmaskValue field.

Defines BitIdx enum with all the provided values prefixed with "BitIdx_". For example usage of

COMMS_BITMASK_BITS(first, second, third, fourth);
#define COMMS_BITMASK_BITS(...)
Provide names for bits in comms::field::BitmaskValue field.
Definition: BitmaskValue.h:590

will generate the following enum type:

enum BitIdx
{
BitIdx_first,
BitIdx_second,
BitIdx_third,
BitIdx_fourth,
BitIdx_numOfValues
};

NOTE, that provided names first, second, third, and fourth have found their way to the enum BitIdx.
Also note, that there is automatically added BitIdx_numOfValues value to the end of BitIdx enum.

It is possible to assign values to the provided names. It could be useful when skipping some unused bits. For example

COMMS_BITMASK_BITS(first=1, third=3, fourth);

will generate the following enum type:

enum BitIdx
{
BitIdx_first=1,
BitIdx_third=3,
BitIdx_fourth,
BitIdx_numOfValues
};

The macro COMMS_BITMASK_BITS() should be used inside definition of the bitmask field to provide names for the bits for external use:

struct MyField : public comms::field::BitmaskValue<...>
{
COMMS_BITMASK_BITS(first, second, third, fourth);
}
Bitmask value field.
Definition: BitmaskValue.h:103
Note
Defined in "comms/field/BitmaskValue.h"

◆ COMMS_BITMASK_BITS_ACCESS

template<typename TFieldBase , typename... TOptions>
#define COMMS_BITMASK_BITS_ACCESS (   ...)
related
Value:
COMMS_AS_BITMASK_FUNC { \
return comms::field::toFieldBase(*this); \
}\
COMMS_AS_BITMASK_CONST_FUNC { \
return comms::field::toFieldBase(*this); \
} \
COMMS_DO_BIT_ACC_FUNC(asBitmask(), __VA_ARGS__)
Bundle< TFieldBase, TMembers, TOptions... > & toFieldBase(Bundle< TFieldBase, TMembers, TOptions... > &field)
Upcast type of the field definition to its parent comms::field::Bundle type in order to have access t...
Definition: Bundle.h:805

Generate access functions for bits in comms::field::BitmaskValue field.

The COMMS_BITMASK_BITS() macro defines BitIdx enum to be able to access internal bits. However, an ability to provide values to the enumeration values using =val suffixes doesn't allow generation of convenience access functions to the bits. That's why COMMS_BITMASK_BITS_ACCESS() macro was introduced. For every name listed in the parameters list, getBitValue_*() and setBitValue_*() functions will be generated. For example, having the following definition

struct MyField : public comms::field::BitmaskValue<...>
{
...
COMMS_BITMASK_BITS_ACCESS(first, third, fourth);
}
#define COMMS_BITMASK_BITS_ACCESS(...)
Generate access functions for bits in comms::field::BitmaskValue field.
Definition: BitmaskValue.h:684

is equivalent to having following functions defined:

struct MyField : public comms::field::BitmaskValue<...>
{
...
bool getBitValue_first() const {
return getBitValue(BitIdx_first);
}
void setBitValue_first(bool value) {
setBitValue(BitIdx_first, value);
}
bool getBitValue_third() const {
return getBitValue(BitIdx_third);
}
void setBitValue_third(bool value) {
setBitValue(BitIdx_third, value);
}
bool getBitValue_fourth() const {
return getBitValue(BitIdx_fourth);
}
void setBitValue_fourth(bool value) {
setBitValue(BitIdx_fourth, value);
}
}
bool getBitValue(unsigned bitNum) const
Get bit value.
Definition: BitmaskValue.h:349
void setBitValue(unsigned bitNum, bool val)
Set bit value.
Definition: BitmaskValue.h:356

NOTE, that generated getBitValue_*() and setBitValue_*() functions use BitIdx_* enum values generated by COMMS_BITMASK_BITS(). It means that COMMS_BITMASK_BITS_ACCESS() macro can NOT be used without COMMS_BITMASK_BITS().

struct MyField : public comms::field::BitmaskValue<...>
{
COMMS_BITMASK_BITS(first, third=2, fourth);
COMMS_BITMASK_BITS_ACCESS(first, third, fourth);
}
Precondition
Must be used together with COMMS_BITMASK_BITS()
Warning
Some compilers, such as clang or early versions of g++ may have problems compiling code generated by this macro even though it uses valid C++11 constructs in attempt to automatically identify the type of the base class. If the compilation fails, and this macro resides inside a NON-template class, please use COMMS_BITMASK_BITS_ACCESS_NOTEMPLATE() macro instead. In case this macro needs to reside inside a template class, then there is a need to define inner Base type, which specifies exact type of the comms::field::BitmaskValue class. For example:
template <typename... TExtraOptions>
class MyField : public
MyFieldBase,
comms::field::FixedLength<1>,
comms::field::BitmaskReservedBits<0xf2, 0>,
TExtraOptions...
>
{
// Duplicate definition of the base class
using Base =
MyFieldBase,
comms::field::FixedLength<1>,
scomms::field::BitmaskReservedBits<0xf2, 0>,
TExtraOptions...
>;
public:
COMMS_BITMASK_BITS(first, third=2, fourth);
COMMS_BITMASK_BITS_ACCESS(first, third, fourth);
}
Note
Defined in "comms/field/BitmaskValue.h"

◆ COMMS_BITMASK_BITS_ACCESS_NOTEMPLATE

template<typename TFieldBase , typename... TOptions>
#define COMMS_BITMASK_BITS_ACCESS_NOTEMPLATE (   ...)     COMMS_DO_BIT_ACC_FUNC((*this), __VA_ARGS__)
related

Similar to COMMS_BITMASK_BITS_ACCESS(), but dedicated for non-template classes.

The COMMS_BITMASK_BITS_ACCESS() macro is a generic one, which can be used in any class (template, or non-template). However, some compilers (such as g++-4.9 and below, clang-4.0 and below) may fail to compile it even though it uses valid C++11 constructs. If the compilation fails and the class it is being used in is NOT a template one, please use COMMS_BITMASK_BITS_ACCESS_NOTEMPLATE() instead.

◆ COMMS_BITMASK_BITS_SEQ

template<typename TFieldBase , typename... TOptions>
#define COMMS_BITMASK_BITS_SEQ (   ...)
related
Value:
COMMS_BITMASK_BITS(__VA_ARGS__) \
COMMS_BITMASK_BITS_ACCESS(__VA_ARGS__)

Combine usage of COMMS_BITMASK_BITS() and COMMS_BITMASK_BITS_ACCESS().

When assigned bit names start at bit 0 and go sequentially without any gaps in the middle, i.e. don't have any =val suffixes, then use COMMS_BITMASK_BITS_SEQ() macro to name the bits. It is defined to use COMMS_BITMASK_BITS() and COMMS_BITMASK_BITS_ACCESS() with the same bit names. For example

struct MyField : public comms::field::BitmaskValue<...>
{
COMMS_BITMASK_BITS_SEQ(first, second, third, fourth);
}
#define COMMS_BITMASK_BITS_SEQ(...)
Combine usage of COMMS_BITMASK_BITS() and COMMS_BITMASK_BITS_ACCESS().
Definition: BitmaskValue.h:776

is equivalent to having

struct MyField : public comms::field::BitmaskValue<...>
{
enum BitIdx
{
BitIdx_first,
BitIdx_second,
BitIdx_third,
BitIdx_fourth,
BitIdx_numOfValues
}
bool getBitValue_first() const {...}
void setBitValue_first(bool value) {...}
bool getBitValue_second() const {...}
void setBitValue_second(bool value) {...}
bool getBitValue_third() const {...}
void setBitValue_third(bool value) {...}
bool getBitValue_fourth() const {...}
void setBitValue_fourth(bool value) {...}
};
Warning
Some compilers, such as clang or early versions of g++ may have problems compiling code generated by this macro even though it uses valid C++11 constructs in attempt to automatically identify the type of the base class. If the compilation fails, and this macro resides inside a NON-template class, please use COMMS_BITMASK_BITS_SEQ_NOTEMPLATE() macro instead. In case this macro needs to reside inside a template class, then there is a need to define inner Base type, which specifies exact type of the comms::field::BitmaskValue class. For example:
template <typename... TExtraOptions>
class MyField : public
MyFieldBase,
comms::field::FixedLength<1>,
comms::field::BitmaskReservedBits<0xf0, 0>,
TExtraOptions...
>
{
// Duplicate definition of the base class
using Base =
MyFieldBase,
comms::field::FixedLength<1>,
scomms::field::BitmaskReservedBits<0xf0, 0>,
TExtraOptions...
>;
public:
COMMS_BITMASK_BITS_SEQ(first, second, third, fourth);
}
Note
Defined in "comms/field/BitmaskValue.h"

◆ COMMS_BITMASK_BITS_SEQ_NOTEMPLATE

template<typename TFieldBase , typename... TOptions>
#define COMMS_BITMASK_BITS_SEQ_NOTEMPLATE (   ...)
related
Value:
COMMS_BITMASK_BITS(__VA_ARGS__) \
COMMS_BITMASK_BITS_ACCESS_NOTEMPLATE(__VA_ARGS__)

Similar to COMMS_BITMASK_BITS_SEQ(), but dedicated for non-template classes.

The COMMS_BITMASK_BITS_SEQ() macro is a generic one, which can be used in any class (template, or non-template). However, some compilers (such as g++-4.9 and below, clang-4.0 and below) may fail to compile it even though it uses valid C++11 constructs. If the compilation fails and the class it is being used in is NOT a template one, please use COMMS_BITMASK_BITS_SEQ_NOTEMPLATE() instead.

Note
Defined in "comms/field/BitmaskValue.h"

◆ isBitmaskValue()

template<typename T >
constexpr bool isBitmaskValue ( )
related

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

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

◆ operator!=()

template<typename TFieldBase , typename... TOptions>
bool operator!= ( const BitmaskValue< TFieldBase, TOptions... > &  field1,
const BitmaskValue< TFieldBase, 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... TOptions>
bool operator< ( const BitmaskValue< TFieldBase, TOptions... > &  field1,
const BitmaskValue< TFieldBase, 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... TOptions>
bool operator== ( const BitmaskValue< TFieldBase, TOptions... > &  field1,
const BitmaskValue< TFieldBase, 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: