libdoip  0.1.0
DoIP (Diagnostics over Internet Protocol) ISO 13400 C++17 Library
doip::GenericFixedId< IdLength, zeroPadding, padChar > Class Template Reference

Generic fixed-length identifier class template. More...

#include <DoIPIdentifiers.h>

Inheritance diagram for doip::GenericFixedId< IdLength, zeroPadding, padChar >:
Collaboration diagram for doip::GenericFixedId< IdLength, zeroPadding, padChar >:

Public Types

using value_type = uint8_t
 
using size_type = size_t
 
using difference_type = std::ptrdiff_t
 
using reference = uint8_t &
 
using const_reference = const uint8_t &
 
using iterator = typename std::array< uint8_t, IdLength >::iterator
 
using const_iterator = typename std::array< uint8_t, IdLength >::const_iterator
 

Public Member Functions

 GenericFixedId ()
 Default constructor - creates an identifier filled with zeros. More...
 
 GenericFixedId (const std::string &id_string)
 Construct from string. More...
 
 GenericFixedId (const char *id_cstr)
 Construct from C-style string. More...
 
 GenericFixedId (const uint8_t *data, size_t length)
 Construct from byte sequence. More...
 
 GenericFixedId (const ByteArray &byte_array)
 Construct from ByteArray. More...
 
template<typename integral , typename = std::enable_if_t<std::is_integral_v<integral>>>
 GenericFixedId (integral id_value)
 Construct a new Generic Fixed Id object. More...
 
 GenericFixedId (const GenericFixedId &other)=default
 Copy constructor. More...
 
GenericFixedIdoperator= (const GenericFixedId &other)=default
 Copy assignment operator. More...
 
 GenericFixedId (GenericFixedId &&other) noexcept=default
 Move constructor. More...
 
GenericFixedIdoperator= (GenericFixedId &&other) noexcept=default
 Move assignment operator. More...
 
 ~GenericFixedId ()=default
 Destructor. More...
 
std::string toString () const
 Get identifier as string. More...
 
std::string toHexString () const
 Get identifier as hex string, bytes separated by '. More...
 
ByteArrayRef asByteArray () const
 Get identifier as ByteArray with exactly IdLength bytes. More...
 
const std::array< uint8_t, ID_LENGTH > & getArray () const
 Get direct access to the underlying array. More...
 
const uint8_t * data () const
 Get pointer to raw data. More...
 
ByteArrayappendTo (ByteArray &bytes) const
 Appends this identifier to the given byte array. More...
 
constexpr size_t size () const
 Get the size (always IdLength) More...
 
bool isEmpty () const
 Check if identifier is all zeros or all padding characters. More...
 
bool operator== (const GenericFixedId &other) const
 Equality operator. More...
 
bool operator!= (const GenericFixedId &other) const
 Inequality operator. More...
 
const uint8_t & operator[] (size_t index) const
 Array subscript operator (const) More...
 
constexpr char getPadChar ()
 Get the char used to pad shorter identifiers. More...
 
constexpr uint8_t getPadByte ()
 Get the byte used to pad shorter identifiers. More...
 
auto begin () noexcept
 Iterator support - begin. More...
 
auto begin () const noexcept
 Iterator support - begin (const) More...
 
auto cbegin () const noexcept
 Iterator support - cbegin. More...
 
auto end () noexcept
 Iterator support - end. More...
 
auto end () const noexcept
 Iterator support - end (const) More...
 
auto cend () const noexcept
 Iterator support - cend. More...
 

Static Public Attributes

static constexpr size_t ID_LENGTH = IdLength
 Length of the identifier in bytes. More...
 
static const GenericFixedId Zero {}
 Static instance containing only zeros. More...
 

Detailed Description

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
class doip::GenericFixedId< IdLength, zeroPadding, padChar >

Generic fixed-length identifier class template.

Template Parameters
IdLengthThe length of the identifier in bytes.
zeroPaddingWhether to use zero-padding (true) or character-padding (false).
padCharThe character to use for padding (default is null byte).

Definition at line 22 of file DoIPIdentifiers.h.

Member Typedef Documentation

◆ const_iterator

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
using doip::GenericFixedId< IdLength, zeroPadding, padChar >::const_iterator = typename std::array<uint8_t, IdLength>::const_iterator

Definition at line 36 of file DoIPIdentifiers.h.

◆ const_reference

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
using doip::GenericFixedId< IdLength, zeroPadding, padChar >::const_reference = const uint8_t&

Definition at line 34 of file DoIPIdentifiers.h.

◆ difference_type

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
using doip::GenericFixedId< IdLength, zeroPadding, padChar >::difference_type = std::ptrdiff_t

Definition at line 32 of file DoIPIdentifiers.h.

◆ iterator

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
using doip::GenericFixedId< IdLength, zeroPadding, padChar >::iterator = typename std::array<uint8_t, IdLength>::iterator

Definition at line 35 of file DoIPIdentifiers.h.

◆ reference

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
using doip::GenericFixedId< IdLength, zeroPadding, padChar >::reference = uint8_t&

Definition at line 33 of file DoIPIdentifiers.h.

◆ size_type

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
using doip::GenericFixedId< IdLength, zeroPadding, padChar >::size_type = size_t

Definition at line 31 of file DoIPIdentifiers.h.

◆ value_type

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
using doip::GenericFixedId< IdLength, zeroPadding, padChar >::value_type = uint8_t

Definition at line 30 of file DoIPIdentifiers.h.

Constructor & Destructor Documentation

◆ GenericFixedId() [1/8]

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
doip::GenericFixedId< IdLength, zeroPadding, padChar >::GenericFixedId ( )
inline

Default constructor - creates an identifier filled with zeros.

Definition at line 41 of file DoIPIdentifiers.h.

◆ GenericFixedId() [2/8]

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
doip::GenericFixedId< IdLength, zeroPadding, padChar >::GenericFixedId ( const std::string &  id_string)
inlineexplicit

Construct from string.

Parameters
id_stringThe identifier as string. If shorter than IdLength, padded with zeros. If longer, truncated.

Definition at line 48 of file DoIPIdentifiers.h.

References doip::GenericFixedId< IdLength, zeroPadding, padChar >::ID_LENGTH.

◆ GenericFixedId() [3/8]

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
doip::GenericFixedId< IdLength, zeroPadding, padChar >::GenericFixedId ( const char *  id_cstr)
inlineexplicit

Construct from C-style string.

Parameters
id_cstrThe identifier as C-string. If shorter than IdLength, padded with zeros. If longer, truncated.

Definition at line 59 of file DoIPIdentifiers.h.

References doip::GenericFixedId< IdLength, zeroPadding, padChar >::ID_LENGTH.

◆ GenericFixedId() [4/8]

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
doip::GenericFixedId< IdLength, zeroPadding, padChar >::GenericFixedId ( const uint8_t *  data,
size_t  length 
)
inline

Construct from byte sequence.

Parameters
dataPointer to byte data
lengthLength of the byte data. If shorter than IdLength, padded with zeros. If longer, truncated.

Definition at line 75 of file DoIPIdentifiers.h.

References doip::GenericFixedId< IdLength, zeroPadding, padChar >::data(), and doip::GenericFixedId< IdLength, zeroPadding, padChar >::ID_LENGTH.

◆ GenericFixedId() [5/8]

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
doip::GenericFixedId< IdLength, zeroPadding, padChar >::GenericFixedId ( const ByteArray byte_array)
inlineexplicit

Construct from ByteArray.

Parameters
byte_arrayThe identifier as ByteArray. If shorter than IdLength, padded with zeros. If longer, truncated.

Definition at line 90 of file DoIPIdentifiers.h.

References doip::GenericFixedId< IdLength, zeroPadding, padChar >::ID_LENGTH.

◆ GenericFixedId() [6/8]

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
template<typename integral , typename = std::enable_if_t<std::is_integral_v<integral>>>
doip::GenericFixedId< IdLength, zeroPadding, padChar >::GenericFixedId ( integral  id_value)
inlineexplicit

Construct a new Generic Fixed Id object.

Template Parameters
integralthe integral type
Parameters
id_valuethe identifier value as integral type

Definition at line 104 of file DoIPIdentifiers.h.

References doip::GenericFixedId< IdLength, zeroPadding, padChar >::ID_LENGTH.

◆ GenericFixedId() [7/8]

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
doip::GenericFixedId< IdLength, zeroPadding, padChar >::GenericFixedId ( const GenericFixedId< IdLength, zeroPadding, padChar > &  other)
default

Copy constructor.

◆ GenericFixedId() [8/8]

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
doip::GenericFixedId< IdLength, zeroPadding, padChar >::GenericFixedId ( GenericFixedId< IdLength, zeroPadding, padChar > &&  other)
defaultnoexcept

Move constructor.

◆ ~GenericFixedId()

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
doip::GenericFixedId< IdLength, zeroPadding, padChar >::~GenericFixedId ( )
default

Destructor.

Member Function Documentation

◆ appendTo()

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
ByteArray& doip::GenericFixedId< IdLength, zeroPadding, padChar >::appendTo ( ByteArray bytes) const
inline

Appends this identifier to the given byte array.

Parameters
bytesthe byte array to append to
Returns
ByteArray& the modified byte array

Definition at line 207 of file DoIPIdentifiers.h.

◆ asByteArray()

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
ByteArrayRef doip::GenericFixedId< IdLength, zeroPadding, padChar >::asByteArray ( ) const
inline

Get identifier as ByteArray with exactly IdLength bytes.

Returns
ByteArray The identifier as byte array (always IdLength bytes)

Definition at line 179 of file DoIPIdentifiers.h.

References doip::GenericFixedId< IdLength, zeroPadding, padChar >::ID_LENGTH.

◆ begin() [1/2]

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
auto doip::GenericFixedId< IdLength, zeroPadding, padChar >::begin ( ) const
inlinenoexcept

Iterator support - begin (const)

Returns
auto Const iterator to the beginning of the identifier data

Definition at line 296 of file DoIPIdentifiers.h.

◆ begin() [2/2]

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
auto doip::GenericFixedId< IdLength, zeroPadding, padChar >::begin ( )
inlinenoexcept

Iterator support - begin.

Returns
auto Iterator to the beginning of the identifier data

Definition at line 289 of file DoIPIdentifiers.h.

Referenced by doip::message::makeVehicleIdentificationResponse().

◆ cbegin()

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
auto doip::GenericFixedId< IdLength, zeroPadding, padChar >::cbegin ( ) const
inlinenoexcept

Iterator support - cbegin.

Returns
auto Const iterator to the beginning of the identifier data

Definition at line 303 of file DoIPIdentifiers.h.

◆ cend()

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
auto doip::GenericFixedId< IdLength, zeroPadding, padChar >::cend ( ) const
inlinenoexcept

Iterator support - cend.

Returns
auto Const iterator to the end of the identifier data

Definition at line 324 of file DoIPIdentifiers.h.

◆ data()

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
const uint8_t* doip::GenericFixedId< IdLength, zeroPadding, padChar >::data ( ) const
inline

Get pointer to raw data.

Returns
const uint8_t* Pointer to the identifier data

Definition at line 197 of file DoIPIdentifiers.h.

Referenced by doip::GenericFixedId< IdLength, zeroPadding, padChar >::GenericFixedId().

◆ end() [1/2]

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
auto doip::GenericFixedId< IdLength, zeroPadding, padChar >::end ( ) const
inlinenoexcept

Iterator support - end (const)

Returns
auto Const iterator to the end of the identifier data

Definition at line 317 of file DoIPIdentifiers.h.

◆ end() [2/2]

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
auto doip::GenericFixedId< IdLength, zeroPadding, padChar >::end ( )
inlinenoexcept

Iterator support - end.

Returns
auto Iterator to the end of the identifier data

Definition at line 310 of file DoIPIdentifiers.h.

Referenced by doip::message::makeVehicleIdentificationResponse().

◆ getArray()

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
const std::array<uint8_t, ID_LENGTH>& doip::GenericFixedId< IdLength, zeroPadding, padChar >::getArray ( ) const
inline

Get direct access to the underlying array.

Returns
const std::array<uint8_t, ID_LENGTH>& Reference to the internal array

Definition at line 188 of file DoIPIdentifiers.h.

◆ getPadByte()

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
constexpr uint8_t doip::GenericFixedId< IdLength, zeroPadding, padChar >::getPadByte ( )
inlineconstexpr

Get the byte used to pad shorter identifiers.

Returns
uint8_t constexpr the padding byte

Definition at line 280 of file DoIPIdentifiers.h.

◆ getPadChar()

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
constexpr char doip::GenericFixedId< IdLength, zeroPadding, padChar >::getPadChar ( )
inlineconstexpr

Get the char used to pad shorter identifiers.

Returns
char constexpr the padding character

Definition at line 271 of file DoIPIdentifiers.h.

◆ isEmpty()

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
bool doip::GenericFixedId< IdLength, zeroPadding, padChar >::isEmpty ( ) const
inline

Check if identifier is all zeros or all padding characters.

Returns
bool True if all bytes are zero or all bytes are the padding character

Definition at line 226 of file DoIPIdentifiers.h.

◆ operator!=()

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
bool doip::GenericFixedId< IdLength, zeroPadding, padChar >::operator!= ( const GenericFixedId< IdLength, zeroPadding, padChar > &  other) const
inline

Inequality operator.

Parameters
otherThe other identifier to compare with
Returns
bool True if identifiers are different

Definition at line 252 of file DoIPIdentifiers.h.

◆ operator=() [1/2]

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
GenericFixedId& doip::GenericFixedId< IdLength, zeroPadding, padChar >::operator= ( const GenericFixedId< IdLength, zeroPadding, padChar > &  other)
default

Copy assignment operator.

◆ operator=() [2/2]

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
GenericFixedId& doip::GenericFixedId< IdLength, zeroPadding, padChar >::operator= ( GenericFixedId< IdLength, zeroPadding, padChar > &&  other)
defaultnoexcept

Move assignment operator.

◆ operator==()

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
bool doip::GenericFixedId< IdLength, zeroPadding, padChar >::operator== ( const GenericFixedId< IdLength, zeroPadding, padChar > &  other) const
inline

Equality operator.

Parameters
otherThe other identifier to compare with
Returns
bool True if both identifiers are identical

Definition at line 242 of file DoIPIdentifiers.h.

◆ operator[]()

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
const uint8_t& doip::GenericFixedId< IdLength, zeroPadding, padChar >::operator[] ( size_t  index) const
inline

Array subscript operator (const)

Parameters
indexIndex (0 to IdLength-1)
Returns
const uint8_t& Reference to the byte at the given index

Definition at line 262 of file DoIPIdentifiers.h.

◆ size()

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
constexpr size_t doip::GenericFixedId< IdLength, zeroPadding, padChar >::size ( ) const
inlineconstexpr

Get the size (always IdLength)

Returns
constexpr size_t Always returns ID_LENGTH (IdLength)

Definition at line 217 of file DoIPIdentifiers.h.

Referenced by doip::message::makeVehicleIdentificationResponse().

◆ toHexString()

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
std::string doip::GenericFixedId< IdLength, zeroPadding, padChar >::toHexString ( ) const
inline

Get identifier as hex string, bytes separated by '.

'

Returns
std::string Hex representation (e.g. "01.02.0A")

Definition at line 162 of file DoIPIdentifiers.h.

References doip::GenericFixedId< IdLength, zeroPadding, padChar >::ID_LENGTH.

Referenced by doip::operator<<().

◆ toString()

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
std::string doip::GenericFixedId< IdLength, zeroPadding, padChar >::toString ( ) const
inline

Get identifier as string.

Returns
std::string The identifier as string (may contain null bytes if identifier was shorter than IdLength)

Definition at line 145 of file DoIPIdentifiers.h.

References doip::GenericFixedId< IdLength, zeroPadding, padChar >::ID_LENGTH.

Referenced by doip::operator<<().

Member Data Documentation

◆ ID_LENGTH

template<size_t IdLength, bool zeroPadding = false, char padChar = 0>
constexpr size_t doip::GenericFixedId< IdLength, zeroPadding, padChar >::ID_LENGTH = IdLength
staticconstexpr

◆ Zero

template<size_t IdLength, bool zeroPadding, char padChar>
const GenericFixedId< IdLength, zeroPadding, padChar > doip::GenericFixedId< IdLength, zeroPadding, padChar >::Zero {}
inlinestatic

Static instance containing only zeros.

Definition at line 329 of file DoIPIdentifiers.h.


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