DUDS
Distributed Update of Data from Something
duds::hardware::interface::ConversationVector Class Reference

Holds a conversation part inside a vector. More...

#include <ConversationVector.hpp>

Inheritance diagram for duds::hardware::interface::ConversationVector:
Collaboration diagram for duds::hardware::interface::ConversationVector:

Classes

struct  BigEndian
 Use with the insertion operator to specify big-endian data will follow. More...
 
struct  FixedLength
 Used as a parameter to constructors to specify that communication will not change the length of the conversation part. More...
 
struct  Input
 Used as a parameter to constructors to specify an input conversation part. More...
 
struct  LittleEndian
 Use with the insertion operator to specify little-endian data will follow. More...
 
struct  Output
 Used as a parameter to constructors to specify an output conversation part. More...
 
struct  Reserve
 Use with the insertion operator to reserve space in the vector. More...
 
struct  VaribleLength
 Used as a parameter to constructors to specify that communication may change the length of the part. More...
 

Public Member Functions

 ConversationVector (const ConversationVector &)=default
 Copies are OK. More...
 
 ConversationVector (Input)
 Construct for fixed-length input without allocating space for the input. More...
 
 ConversationVector (Output)
 Construct for output. More...
 
 ConversationVector (bool input)
 Construct for either output or fixed-length input. More...
 
 ConversationVector (const std::vector< char > &v)
 Construct for output and copy the given vector into this object. More...
 
 ConversationVector (std::vector< char > &&v)
 Construct for output and move the given vector into this object. More...
 
 ConversationVector (std::size_t length, FixedLength)
 Construct for fixed-length input and allocate space for the input. More...
 
 ConversationVector (std::size_t length, VaribleLength)
 Construct for variable-length input and allocate space for the input. More...
 
 ConversationVector (std::size_t length, bool varlen=false)
 Construct for fixed or variable-length input and allocate space for the input. More...
 
 ConversationVector (std::size_t length, Output)
 Construct for output and reserve the given length within the internal vector. More...
 
void add (char i)
 Adds a byte to an output part. More...
 
template<typename Int >
void add (Int i)
 Adds an integer to the end an output part. More...
 
void add (const std::string &str)
 Adds a string as binary data to the end an output part. More...
 
void add (std::int8_t *a, std::size_t l)
 Adds binary data to the end of an output part. More...
 
template<std::size_t N>
void add (std::int8_t(&a)[N])
 Adds an array to the end an output part. More...
 
template<typename Int >
void add (const Int *a, std::size_t count)
 Adds an array of integers to the end of an output part. More...
 
template<typename Int , std::size_t N>
void add (const Int(&a)[N])
 Adds an array of integers to the end of an output part. More...
 
template<typename Int >
void addBe (Int i)
 Adds an integer in big-endian form to an output part. More...
 
void addBe (std::int8_t i)
 Adds a byte to an output part. More...
 
template<typename Int >
void addBe (const Int *a, std::size_t count)
 Adds an array of integers to the end of an output part in big-endian form. More...
 
template<typename Int , std::size_t N>
void addBe (const Int(&a)[N])
 Adds an array of integers to the end of an output part in big-endian form. More...
 
template<typename Int >
void addLe (Int i)
 Adds an integer in little-endian form to an output part. More...
 
void addLe (std::int8_t i)
 Adds a byte to an output part. More...
 
template<typename Int >
void addLe (const Int *a, std::size_t count)
 Adds an array of integers to the end of an output part in little-endian form. More...
 
template<typename Int , std::size_t N>
void addLe (const Int(&a)[N])
 Adds an array of integers to the end of an output part in little-endian form. More...
 
std::vector< char >::const_iterator begin () const
 Begining iterator to inspect the contained data. More...
 
std::vector< char >::const_iterator end () const
 Ending iterator to inspect the contained data. More...
 
virtual std::size_t length () const
 Returns the length of the buffer following the start pointer. More...
 
void reserve (std::size_t len)
 Reserves space in the internal vector. More...
 
void setLength (std::size_t len)
 Sets a new length, including the data prior to the start pointer, for a conversation part with a varying length. More...
 
void setStartOffset (std::int16_t offset)
 Sets a new start offset, in bytes, for a variable length input part. More...
 
virtual char * start () const
 Returns a pointer to the begining of the conversation part's buffer. More...
 
- Public Member Functions inherited from duds::hardware::interface::ConversationPart
 ConversationPart (const ConversationPart &)=default
 Copies are OK. More...
 
virtual ~ConversationPart ()
 
bool bigEndian () const
 True if this part is flagged as having data in big-endian form. More...
 
ConversationPartbigEndian (bool big)
 Changes the flagged endianess of this part. More...
 
ConversationPartbreakBefore ()
 Flags the conversation part to have a break before this part is sent. More...
 
bool extract () const
 True if this part is flagged for extraction by ConversationExtractor. More...
 
ConversationPartextract (bool ex)
 Changes the extraction flag for this part. More...
 
Flags flags () const
 Returns the flags. More...
 
bool input () const
 True if this part is flagged for input use. More...
 
bool littleEndian () const
 True if this part is flagged as having data in little-endian form. More...
 
ConversationPartlittleEndian (bool little)
 Changes the flagged endianess of this part. More...
 
bool output () const
 True if this part is flagged for output use. More...
 
bool varyingLength () const
 True if this part is flagged as having a variable length. More...
 

Private Attributes

std::vector< char > data
 The internal buffer. More...
 

Related Functions

(Note that these are not member functions.)

template<typename Int >
ConversationVectoroperator<< (ConversationVector &cv, const Int &i)
 Insertion operator to add an integer to a ConversationVector object. More...
 
template<typename Int , std::size_t N>
ConversationVectoroperator<< (ConversationVector &cv, const Int(&a)[N])
 Insertion operator to add an array of integers to a ConversationVector object. More...
 
ConversationVectoroperator<< (ConversationVector &cv, const ConversationVector::Reserve &cvr)
 Insertion operator to reserve space in a ConversationVector. More...
 
ConversationVectoroperator<< (ConversationVector &cv, const ConversationVector::BigEndian)
 Insertion operator to make the ConversationVector handle any following adds using big-endian format. More...
 
ConversationVectoroperator<< (ConversationVector &cv, const ConversationVector::LittleEndian)
 Insertion operator to make the ConversationVector handle any following adds using little-endian format. More...
 
ConversationVectoroperator<< (ConversationVector &cv, const std::string &str)
 Insertion operator to add a string as binary data to the end of an output ConversationVector. More...
 

Additional Inherited Members

- Public Types inherited from duds::hardware::interface::ConversationPart
typedef duds::general::BitFlags< struct ConversationPartFlags, std::uint16_t > Flags
 The type used to store flags that modify the operation of the classes derived from this class, or how the objects are used. More...
 
- Static Public Attributes inherited from duds::hardware::interface::ConversationPart
static constexpr Flags MpfBigendian = Flags::Bit(3)
 True/set to expect data to be big-endian. More...
 
static constexpr Flags MpfBreak = Flags::Bit(4)
 True/set to indicate that any kind of selection signal should be toggled, or a stop condition should occur, before communicating the part with this flag. More...
 
static constexpr Flags MpfExtract = Flags::Bit(1)
 True/set to extract message part contents with the ConversationExtractor. More...
 
static constexpr Flags MpfInput = Flags::Bit(0)
 True/set for input; false for output. More...
 
static constexpr Flags MpfVarlen = Flags::Bit(2)
 True/set for a varying length; valid only for input. More...
 
- Protected Member Functions inherited from duds::hardware::interface::ConversationPart
 ConversationPart (Flags f)
 Construct with the given flags. More...
 
 ConversationPart (Flags f, std::int16_t v)
 Construct with the given flags and an initial value for val16. More...
 
- Protected Attributes inherited from duds::hardware::interface::ConversationPart
std::int16_t val16
 A small integer for derived classes to use. More...
 

Detailed Description

Holds a conversation part inside a vector.

Output data can be placed in the part using the various add() functions. Templates are used to avoid the need to specify the data size when arrays are used. addBe() functions will put the given data in big-endian form, while addLe() functions will use little-endian. Other add functions will use the endianess indicated in the part flags (ConversationPart::flags()). None of the add functions modify the endianess flag. The default endianess is little-endian.

The insertion operator is defined for this class and uses the add functions. It is also defined to use structs within this class to modify the part in other ways. The BigEndian struct will set the big-endian flag and affect data added later using means other than the addLe() functions. LittleEndian does the same, but selects little-endian data. The Reserve struct will cause reserve() to be called.

Variable length inputs are implemented by allowing resizing of the internal vector. The start pointer can be offset from the start of the vector using setStartOffset(). The offset is stored in val16. This allows input using a large enough vector (defined by communication protocol) that starts with the size of the input.

Author
Jeff Jackowski

Definition at line 64 of file ConversationVector.hpp.

Constructor & Destructor Documentation

◆ ConversationVector() [1/10]

duds::hardware::interface::ConversationVector::ConversationVector ( const ConversationVector )
default

Copies are OK.

◆ ConversationVector() [2/10]

duds::hardware::interface::ConversationVector::ConversationVector ( Input  )
inline

Construct for fixed-length input without allocating space for the input.

Definition at line 102 of file ConversationVector.hpp.

◆ ConversationVector() [3/10]

duds::hardware::interface::ConversationVector::ConversationVector ( Output  )
inline

Construct for output.

Definition at line 106 of file ConversationVector.hpp.

◆ ConversationVector() [4/10]

duds::hardware::interface::ConversationVector::ConversationVector ( bool  input)
inline

Construct for either output or fixed-length input.

Parameters
inputTrue for input.

Definition at line 111 of file ConversationVector.hpp.

◆ ConversationVector() [5/10]

duds::hardware::interface::ConversationVector::ConversationVector ( const std::vector< char > &  v)
inline

Construct for output and copy the given vector into this object.

Definition at line 117 of file ConversationVector.hpp.

◆ ConversationVector() [6/10]

duds::hardware::interface::ConversationVector::ConversationVector ( std::vector< char > &&  v)
inline

Construct for output and move the given vector into this object.

Definition at line 122 of file ConversationVector.hpp.

◆ ConversationVector() [7/10]

duds::hardware::interface::ConversationVector::ConversationVector ( std::size_t  length,
FixedLength   
)
inline

Construct for fixed-length input and allocate space for the input.

Parameters
lengthThe number of bytes to allocate for the input.

Definition at line 130 of file ConversationVector.hpp.

◆ ConversationVector() [8/10]

duds::hardware::interface::ConversationVector::ConversationVector ( std::size_t  length,
VaribleLength   
)
inline

Construct for variable-length input and allocate space for the input.

Parameters
lengthThe number of bytes to allocate for the input. It should be the maximum size possible for the input.

Definition at line 139 of file ConversationVector.hpp.

◆ ConversationVector() [9/10]

duds::hardware::interface::ConversationVector::ConversationVector ( std::size_t  length,
bool  varlen = false 
)
inline

Construct for fixed or variable-length input and allocate space for the input.

Parameters
lengthThe number of bytes to allocate for the input.
varlenTrue for a variable-length input; false for fixed-length.

Definition at line 149 of file ConversationVector.hpp.

◆ ConversationVector() [10/10]

duds::hardware::interface::ConversationVector::ConversationVector ( std::size_t  length,
Output   
)
inline

Construct for output and reserve the given length within the internal vector.

Parameters
lengthThe number of bytes to reserve.

Definition at line 159 of file ConversationVector.hpp.

Member Function Documentation

◆ add() [1/7]

void duds::hardware::interface::ConversationVector::add ( char  i)

Adds a byte to an output part.

Parameters
iThe character to add to the end of the part.
Exceptions
ConversationBadAddThe part is flagged for input.

Definition at line 15 of file ConversationVector.cpp.

Referenced by duds::hardware::interface::operator<<().

◆ add() [2/7]

template<typename Int >
void duds::hardware::interface::ConversationVector::add ( Int  i)
inline

Adds an integer to the end an output part.

The endianess is chosen based on the part's MpfBigendian flag.

Template Parameters
IntThe integer type.
Parameters
iThe integer value to add to the end of the part.
Exceptions
ConversationBadAddThe part is flagged for input.

Definition at line 243 of file ConversationVector.hpp.

◆ add() [3/7]

void duds::hardware::interface::ConversationVector::add ( const std::string &  str)

Adds a string as binary data to the end an output part.

Parameters
strThe string to add to the end of the part.
Exceptions
ConversationBadAddThe part is flagged for input.

Definition at line 22 of file ConversationVector.cpp.

◆ add() [4/7]

void duds::hardware::interface::ConversationVector::add ( std::int8_t *  a,
std::size_t  l 
)

Adds binary data to the end of an output part.

Parameters
aThe start of the binary data to add to the end of the part.
lThe number of bytes to copy.
Exceptions
ConversationBadAddThe part is flagged for input.

Definition at line 29 of file ConversationVector.cpp.

◆ add() [5/7]

template<std::size_t N>
void duds::hardware::interface::ConversationVector::add ( std::int8_t(&)  a[N])
inline

Adds an array to the end an output part.

Template Parameters
NThe length of the array.
Parameters
aThe array to add to the end of the part.
Exceptions
ConversationBadAddThe part is flagged for input.

Definition at line 270 of file ConversationVector.hpp.

◆ add() [6/7]

template<typename Int >
void duds::hardware::interface::ConversationVector::add ( const Int *  a,
std::size_t  count 
)
inline

Adds an array of integers to the end of an output part.

The endianess is chosen based on the part's MpfBigendian flag.

Template Parameters
IntThe integer type.
Parameters
aThe start of the array to add to the end of the part.
countThe number of items to copy.
Exceptions
ConversationBadAddThe part is flagged for input.

Definition at line 354 of file ConversationVector.hpp.

◆ add() [7/7]

template<typename Int , std::size_t N>
void duds::hardware::interface::ConversationVector::add ( const Int(&)  a[N])
inline

Adds an array of integers to the end of an output part.

The endianess is chosen based on the part's MpfBigendian flag.

Template Parameters
IntThe integer type.
NThe length of the array.
Parameters
aThe array to add to the end of the part.
Exceptions
ConversationBadAddThe part is flagged for input.

Definition at line 370 of file ConversationVector.hpp.

◆ addBe() [1/4]

template<typename Int >
void duds::hardware::interface::ConversationVector::addBe ( Int  i)
inline

Adds an integer in big-endian form to an output part.

Template Parameters
IntThe integer type.
Parameters
iThe integer value to add to the end of the part.
Exceptions
ConversationBadAddThe part is flagged for input.

Definition at line 206 of file ConversationVector.hpp.

◆ addBe() [2/4]

void duds::hardware::interface::ConversationVector::addBe ( std::int8_t  i)
inline

Adds a byte to an output part.

Avoids extra endian code in cases where template code is given a byte type as a parameter.

Parameters
iThe character to add to the end of the part.
Exceptions
ConversationBadAddThe part is flagged for input.

Definition at line 232 of file ConversationVector.hpp.

◆ addBe() [3/4]

template<typename Int >
void duds::hardware::interface::ConversationVector::addBe ( const Int *  a,
std::size_t  count 
)
inline

Adds an array of integers to the end of an output part in big-endian form.

Template Parameters
IntThe integer type.
Parameters
aThe start of the array to add to the end of the part.
countThe number of items to copy.
Exceptions
ConversationBadAddThe part is flagged for input.

Definition at line 318 of file ConversationVector.hpp.

◆ addBe() [4/4]

template<typename Int , std::size_t N>
void duds::hardware::interface::ConversationVector::addBe ( const Int(&)  a[N])
inline

Adds an array of integers to the end of an output part in big-endian form.

Template Parameters
IntThe integer type.
NThe length of the array.
Parameters
aThe array to add to the end of the part.
Exceptions
ConversationBadAddThe part is flagged for input.

Definition at line 342 of file ConversationVector.hpp.

◆ addLe() [1/4]

template<typename Int >
void duds::hardware::interface::ConversationVector::addLe ( Int  i)
inline

Adds an integer in little-endian form to an output part.

Template Parameters
IntThe integer type.
Parameters
iThe integer value to add to the end of the part.
Exceptions
ConversationBadAddThe part is flagged for input.

Definition at line 188 of file ConversationVector.hpp.

◆ addLe() [2/4]

void duds::hardware::interface::ConversationVector::addLe ( std::int8_t  i)
inline

Adds a byte to an output part.

Avoids extra endian code in cases where template code is given a byte type as a parameter.

Parameters
iThe character to add to the end of the part.
Exceptions
ConversationBadAddThe part is flagged for input.

Definition at line 223 of file ConversationVector.hpp.

◆ addLe() [3/4]

template<typename Int >
void duds::hardware::interface::ConversationVector::addLe ( const Int *  a,
std::size_t  count 
)
inline

Adds an array of integers to the end of an output part in little-endian form.

Template Parameters
IntThe integer type.
Parameters
aThe start of the array to add to the end of the part.
countThe number of items to copy.
Exceptions
ConversationBadAddThe part is flagged for input.

Definition at line 282 of file ConversationVector.hpp.

◆ addLe() [4/4]

template<typename Int , std::size_t N>
void duds::hardware::interface::ConversationVector::addLe ( const Int(&)  a[N])
inline

Adds an array of integers to the end of an output part in little-endian form.

Template Parameters
IntThe integer type.
NThe length of the array.
Parameters
aThe array to add to the end of the part.
Exceptions
ConversationBadAddThe part is flagged for input.

Definition at line 306 of file ConversationVector.hpp.

◆ begin()

std::vector<char>::const_iterator duds::hardware::interface::ConversationVector::begin ( ) const
inline

Begining iterator to inspect the contained data.

Definition at line 166 of file ConversationVector.hpp.

◆ end()

std::vector<char>::const_iterator duds::hardware::interface::ConversationVector::end ( ) const
inline

Ending iterator to inspect the contained data.

Definition at line 172 of file ConversationVector.hpp.

◆ length()

std::size_t duds::hardware::interface::ConversationVector::length ( ) const
virtual

Returns the length of the buffer following the start pointer.

Implements duds::hardware::interface::ConversationPart.

Definition at line 62 of file ConversationVector.cpp.

◆ reserve()

void duds::hardware::interface::ConversationVector::reserve ( std::size_t  len)

Reserves space in the internal vector.

This can be used regardless of the part's flags, but makes much more sense for output parts.

Definition at line 54 of file ConversationVector.cpp.

Referenced by duds::hardware::interface::operator<<().

◆ setLength()

void duds::hardware::interface::ConversationVector::setLength ( std::size_t  len)

Sets a new length, including the data prior to the start pointer, for a conversation part with a varying length.

Precondition
The part is flagged for a varying length.
Parameters
lenThe new length for the part. The offset value is not used in this operation.
Exceptions
ConversationFixedLengthThis conversation part is not flagged as having a varying length.

Definition at line 46 of file ConversationVector.cpp.

◆ setStartOffset()

void duds::hardware::interface::ConversationVector::setStartOffset ( std::int16_t  offset)

Sets a new start offset, in bytes, for a variable length input part.

The pointer returned by start() will be offset bytes after the begining of the internal vector.

Precondition
The size of the internal vector is larger than offset bytes.
The part is flagged for a varying length.
Parameters
offsetThe number of bytes to reserve at the begining of the vector. It must be larger than the current size of the vector, and must not be negative.
Exceptions
ConversationBadOffsetThe offset value was invalid.
ConversationFixedLengthThis conversation part is not flagged as having a varying length.

Definition at line 36 of file ConversationVector.cpp.

◆ start()

char * duds::hardware::interface::ConversationVector::start ( ) const
virtual

Returns a pointer to the begining of the conversation part's buffer.

The return type is not const because use for input will require a write operation. The implementation must not make changes to the part object, so the function is const.

Implements duds::hardware::interface::ConversationPart.

Definition at line 58 of file ConversationVector.cpp.

Friends And Related Function Documentation

◆ operator<<() [1/6]

template<typename Int >
ConversationVector & operator<< ( ConversationVector cv,
const Int &  i 
)
related

Insertion operator to add an integer to a ConversationVector object.

The endianess is specified by the part's MpfBigendian flag.

Precondition
The conversation part is flagged for output.
Template Parameters
IntThe integer type.
Parameters
cvThe destination conversation part.
iThe integer to add to the end of cv.
Returns
A reference to cv.

Definition at line 440 of file ConversationVector.hpp.

◆ operator<<() [2/6]

template<typename Int , std::size_t N>
ConversationVector & operator<< ( ConversationVector cv,
const Int(&)  a[N] 
)
related

Insertion operator to add an array of integers to a ConversationVector object.

The endianess is specified by the part's MpfBigendian flag.

Precondition
The conversation part is flagged for output.
Template Parameters
IntThe integer type.
NThe length of the array.
Parameters
cvThe destination conversation part.
aThe array of integers to add to the end of cv.
Returns
A reference to cv.

Definition at line 457 of file ConversationVector.hpp.

◆ operator<<() [3/6]

ConversationVector & operator<< ( ConversationVector cv,
const ConversationVector::Reserve cvr 
)
related

Insertion operator to reserve space in a ConversationVector.

Parameters
cvThe conversation part to modify.
cvrThe object that specifies how much space to reserve.
Returns
A reference to cv.

Definition at line 469 of file ConversationVector.hpp.

◆ operator<<() [4/6]

ConversationVector & operator<< ( ConversationVector cv,
const ConversationVector::BigEndian   
)
related

Insertion operator to make the ConversationVector handle any following adds using big-endian format.

Parameters
cvThe conversation part to modify.
Returns
A reference to cv.

Definition at line 484 of file ConversationVector.hpp.

◆ operator<<() [5/6]

ConversationVector & operator<< ( ConversationVector cv,
const ConversationVector::LittleEndian   
)
related

Insertion operator to make the ConversationVector handle any following adds using little-endian format.

Parameters
cvThe conversation part to modify.
Returns
A reference to cv.

Definition at line 499 of file ConversationVector.hpp.

◆ operator<<() [6/6]

ConversationVector & operator<< ( ConversationVector cv,
const std::string &  str 
)
related

Insertion operator to add a string as binary data to the end of an output ConversationVector.

Parameters
cvThe conversation part to modify.
strThe string to add.
Returns
A reference to cv.

Definition at line 515 of file ConversationVector.hpp.

Member Data Documentation

◆ data

std::vector<char> duds::hardware::interface::ConversationVector::data
private

The internal buffer.

Definition at line 68 of file ConversationVector.hpp.

Referenced by add(), length(), reserve(), setLength(), setStartOffset(), and start().


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