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

Extracts data from a Conversation without modifying the Conversation or copying from it. More...

#include <ConversationExtractor.hpp>

Collaboration diagram for duds::hardware::interface::ConversationExtractor:

Public Member Functions

 ConversationExtractor ()
 Constructs with nothing to extract. More...
 
 ConversationExtractor (const Conversation &con)
 Constructs to extract from the given Conversation. More...
 
 ConversationExtractor (const ConversationPart &cp)
 Must use functions that specifiy either big or little endian. More...
 
void advance (std::size_t bytes)
 Advance the given number of bytes within the current conversation part. More...
 
bool end () const
 Returns true when all the extractible conversation data has been extracted. More...
 
void nextPart ()
 Advances to the next extractible part. More...
 
template<typename Int >
void read (Int &i)
 Reads an integer in the endianess flagged in the conversation part. More...
 
template<typename Int >
void read (Int *a, std::size_t count)
 Reads an array of integers in the endianess flagged in the conversation part. More...
 
template<typename Int , std::size_t N>
void read (Int(&a)[N])
 Reads an array of integers in the endianess flagged in the conversation part. More...
 
void read (char *dest, std::size_t len)
 Reads by using std::memcpy() to copy data. More...
 
template<class Cont , typename Iter >
void read (Cont &cont, Iter &start, std::size_t len)
 Reads by inserting bytes into a container. More...
 
template<typename Int >
void readBe (Int &i)
 Reads an integer in big-endian form. More...
 
template<typename Int >
void readBe (Int *a, std::size_t count)
 Reads an array of integers in big-endian form. More...
 
template<typename Int , std::size_t N>
void readBe (Int(&a)[N])
 Reads an array of integers in big-endian form. More...
 
template<typename Int >
void readLe (Int &i)
 Reads an integer in little-endian form. More...
 
template<typename Int >
void readLe (Int *a, std::size_t count)
 Reads an array of integers in little-endian form. More...
 
template<typename Int , std::size_t N>
void readLe (Int(&a)[N])
 Reads an array of integers in little-endian form. More...
 
std::size_t remaining () const
 Returns the number of bytes remaining in the current conversation part. More...
 
void reset ()
 Prepares the object to extract another time from the same Conversation object used previously. More...
 
void reset (const Conversation &con)
 Prepares the object to extract from the given Conversation. More...
 
void reset (const ConversationPart &cp)
 Must use functions that specify either big or little endian. More...
 

Private Member Functions

void set ()
 Sets internal data to read from the begining of extractible data stored in Conversation c. More...
 

Private Attributes

const Conversationc
 The Conversation object with the parts to read. More...
 
Conversation::PartVector::const_iterator piter
 Iterator to the current part being read. More...
 
const char * pos
 Pointer to the next byte to read. More...
 
std::size_t remain
 The remaining number of bytes to read in the part referenced by piter. More...
 

Related Functions

(Note that these are not member functions.)

template<typename Int >
ConversationExtractoroperator>> (ConversationExtractor &ce, Int &i)
 Extraction operator to read an integer from a Conversation through a ConversationExtractor object. More...
 
template<typename Int , std::size_t N>
ConversationExtractoroperator>> (ConversationExtractor &ce, Int(&a)[N])
 Extraction operator to read an array of integers from a Conversation through a ConversationExtractor object. More...
 

Detailed Description

Extracts data from a Conversation without modifying the Conversation or copying from it.

All conversation parts flagged as extractible (see ConversationPart::MpfExtract) are visited in order. The conversation data is extracted directly from the ConversationPart objects in the originating Conversation object.

Warning
The Conversation object that holds the data to extract must not be modified or deallocated while an extractor object exists and is still being used for extracting the conversation. An extractor can be deallocated after its associated Conversation.
Author
Jeff Jackowski

Definition at line 49 of file ConversationExtractor.hpp.

Constructor & Destructor Documentation

◆ ConversationExtractor() [1/3]

duds::hardware::interface::ConversationExtractor::ConversationExtractor ( )
inline

Constructs with nothing to extract.

Use reset(const Conversation &) to to extract from a Conversation.

Postcondition
end() returns false, and remaining() returns zero.

Definition at line 77 of file ConversationExtractor.hpp.

◆ ConversationExtractor() [2/3]

duds::hardware::interface::ConversationExtractor::ConversationExtractor ( const Conversation con)
inline

Constructs to extract from the given Conversation.

Parameters
conThe Conversation to read.

Definition at line 82 of file ConversationExtractor.hpp.

◆ ConversationExtractor() [3/3]

duds::hardware::interface::ConversationExtractor::ConversationExtractor ( const ConversationPart cp)
inline

Must use functions that specifiy either big or little endian.

Definition at line 88 of file ConversationExtractor.hpp.

Member Function Documentation

◆ advance()

void duds::hardware::interface::ConversationExtractor::advance ( std::size_t  bytes)

Advance the given number of bytes within the current conversation part.

This can be used to skip data rather than read all extractible data. If the number of bytes to advance equals the number of bytes left in the part, it will advance to the begining of the next extractible part, or set the end conditions. It cannot be used in a single call to advance to the end of a part and past the begining of the next.

Parameters
bytesThe number of bytes to advance within the current part. It must not be greater than the value returned by remaining().
Exceptions
ConversationReadPastEndThe requested number of bytes is greater than the number left in the current part. The read position is left unchanged.

Definition at line 35 of file ConversationExtractor.cpp.

Referenced by read().

◆ end()

bool duds::hardware::interface::ConversationExtractor::end ( ) const
inline

Returns true when all the extractible conversation data has been extracted.

Definition at line 130 of file ConversationExtractor.hpp.

◆ nextPart()

void duds::hardware::interface::ConversationExtractor::nextPart ( )

Advances to the next extractible part.

If there isn't another extractible part, the end conditions will be set and end() will return true.

Exceptions
ConversationReadPastEndThe extractor is already at the end.
ConversationNotSetA Conversation was never set. This can happen if the default constructor was used.

Definition at line 68 of file ConversationExtractor.cpp.

◆ read() [1/5]

template<typename Int >
void duds::hardware::interface::ConversationExtractor::read ( Int &  i)
inline

Reads an integer in the endianess flagged in the conversation part.

The integer may not span conversation parts; it must be contained in a single part.

Precondition
The remaining bytes to read is at least the size of Int.
Postcondition
Advances the number of bytes in Int by calling advance().
Template Parameters
IntThe integer type.
Parameters
iThe integer that will receive the value.
Exceptions
ConversationReadPastEndThe integer type is too large to fit in the remaining bytes of the current part. The read position is left unchanged.

Definition at line 234 of file ConversationExtractor.hpp.

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

◆ read() [2/5]

template<typename Int >
void duds::hardware::interface::ConversationExtractor::read ( Int *  a,
std::size_t  count 
)
inline

Reads an array of integers in the endianess flagged in the conversation part.

The integer array may not span conversation parts; it must be contained in a single part.

Precondition
The remaining bytes to read is at least the size of the array.
Postcondition
Advances the number of bytes in the array by calling advance().
Template Parameters
IntThe integer type.
Parameters
aThe start of the destination integer array.
countThe number of elements in the array.
Exceptions
ConversationReadPastEndThe array is too large to fit in the remaining bytes of the current part. The read position is left unchanged.

Definition at line 359 of file ConversationExtractor.hpp.

◆ read() [3/5]

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

Reads an array of integers in the endianess flagged in the conversation part.

The integer array may not span conversation parts; it must be contained in a single part.

Precondition
The remaining bytes to read is at least the size of the array.
Postcondition
Advances the number of bytes in the array by calling advance().
Template Parameters
IntThe integer type.
NThe number of elements in the array.
Parameters
aThe start of the destination integer array.
Exceptions
ConversationReadPastEndThe array is too large to fit in the remaining bytes of the current part. The read position is left unchanged.

Definition at line 385 of file ConversationExtractor.hpp.

◆ read() [4/5]

void duds::hardware::interface::ConversationExtractor::read ( char *  dest,
std::size_t  len 
)

Reads by using std::memcpy() to copy data.

The data may not span conversation parts; it must be contained in a single part.

Precondition
The remaining bytes to read is at least len.
Postcondition
Advances len bytes by calling advance().
Parameters
destThe start of the destination buffer.
lenThe number of bytes to copy.
Exceptions
ConversationReadPastEndFewer than len bytes remain in the current part. The read position is left unchanged.

Definition at line 89 of file ConversationExtractor.cpp.

◆ read() [5/5]

template<class Cont , typename Iter >
void duds::hardware::interface::ConversationExtractor::read ( Cont &  cont,
Iter &  start,
std::size_t  len 
)
inline

Reads by inserting bytes into a container.

The data may not span conversation parts; it must be contained in a single part.

Precondition
The remaining bytes to read is at least len.
Postcondition
Advances len bytes by calling advance().
Template Parameters
ContThe destination container type.
IterThe iterator type of the container.
Parameters
contThe destination container.
startThe insertion position for cont.
lenThe number of bytes to insert into cont.
Exceptions
ConversationReadPastEndFewer than len bytes remain in the current part. The read position is left unchanged.

Definition at line 425 of file ConversationExtractor.hpp.

◆ readBe() [1/3]

template<typename Int >
void duds::hardware::interface::ConversationExtractor::readBe ( Int &  i)
inline

Reads an integer in big-endian form.

The integer may not span conversation parts; it must be contained in a single part.

Precondition
The remaining bytes to read is at least the size of Int.
Postcondition
Advances the number of bytes in Int by calling advance().
Template Parameters
IntThe integer type.
Parameters
iThe integer that will receive the value.
Exceptions
ConversationReadPastEndThe integer type is too large to fit in the remaining bytes of the current part. The read position is left unchanged.

Definition at line 208 of file ConversationExtractor.hpp.

◆ readBe() [2/3]

template<typename Int >
void duds::hardware::interface::ConversationExtractor::readBe ( Int *  a,
std::size_t  count 
)
inline

Reads an array of integers in big-endian form.

The integer array may not span conversation parts; it must be contained in a single part.

Precondition
The remaining bytes to read is at least the size of the array.
Postcondition
Advances the number of bytes in the array by calling advance().
Template Parameters
IntThe integer type.
Parameters
aThe start of the destination integer array.
countThe number of elements in the array.
Exceptions
ConversationReadPastEndThe array is too large to fit in the remaining bytes of the current part. The read position is left unchanged.

Definition at line 293 of file ConversationExtractor.hpp.

◆ readBe() [3/3]

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

Reads an array of integers in big-endian form.

The integer array may not span conversation parts; it must be contained in a single part.

Precondition
The remaining bytes to read is at least the size of the array.
Postcondition
Advances the number of bytes in the array by calling advance().
Template Parameters
IntThe integer type.
NThe number of elements in the array.
Parameters
aThe start of the destination integer array.
Exceptions
ConversationReadPastEndThe array is too large to fit in the remaining bytes of the current part. The read position is left unchanged.

Definition at line 341 of file ConversationExtractor.hpp.

◆ readLe() [1/3]

template<typename Int >
void duds::hardware::interface::ConversationExtractor::readLe ( Int &  i)
inline

Reads an integer in little-endian form.

The integer may not span conversation parts; it must be contained in a single part.

Precondition
The remaining bytes to read is at least the size of Int.
Postcondition
Advances the number of bytes in Int by calling advance().
Template Parameters
IntThe integer type.
Parameters
iThe integer that will receive the value.
Exceptions
ConversationReadPastEndThe integer type is too large to fit in the remaining bytes of the current part. The read position is left unchanged.

Definition at line 179 of file ConversationExtractor.hpp.

◆ readLe() [2/3]

template<typename Int >
void duds::hardware::interface::ConversationExtractor::readLe ( Int *  a,
std::size_t  count 
)
inline

Reads an array of integers in little-endian form.

The integer array may not span conversation parts; it must be contained in a single part.

Precondition
The remaining bytes to read is at least the size of the array.
Postcondition
Advances the number of bytes in the array by calling advance().
Template Parameters
IntThe integer type.
Parameters
aThe start of the destination integer array.
countThe number of elements in the array.
Exceptions
ConversationReadPastEndThe array is too large to fit in the remaining bytes of the current part. The read position is left unchanged.

Definition at line 260 of file ConversationExtractor.hpp.

◆ readLe() [3/3]

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

Reads an array of integers in little-endian form.

The integer array may not span conversation parts; it must be contained in a single part.

Precondition
The remaining bytes to read is at least the size of the array.
Postcondition
Advances the number of bytes in the array by calling advance().
Template Parameters
IntThe integer type.
NThe number of elements in the array.
Parameters
aThe start of the destination integer array.
Exceptions
ConversationReadPastEndThe array is too large to fit in the remaining bytes of the current part. The read position is left unchanged.

Definition at line 323 of file ConversationExtractor.hpp.

◆ remaining()

std::size_t duds::hardware::interface::ConversationExtractor::remaining ( ) const
inline

Returns the number of bytes remaining in the current conversation part.

A conversation may have multiple extractible parts, so this value can be different from the total extractible bytes across all parts.

Definition at line 139 of file ConversationExtractor.hpp.

◆ reset() [1/3]

void duds::hardware::interface::ConversationExtractor::reset ( )
inline

Prepares the object to extract another time from the same Conversation object used previously.

This may be called before extracting all data from the conversation. It allows the same data to be re-extracted, or to extract new data if the Conversation was reused since the last extraction.

Postcondition
The given Conversation must not change before this object is used to extract all the data that will be extracted.
Exceptions
ConversationNotSetA Conversation was never set. This can happen if the default constructor was used.

Definition at line 101 of file ConversationExtractor.hpp.

Referenced by duds::hardware::devices::instruments::LSM9DS1AccelGyro::sample(), duds::hardware::devices::instruments::LSM9DS1Mag::sample(), and duds::hardware::devices::instruments::FXOS8700CQ::suspend().

◆ reset() [2/3]

void duds::hardware::interface::ConversationExtractor::reset ( const Conversation con)
inline

Prepares the object to extract from the given Conversation.

This may be called before extracting all data from a previous conversation, or after the previous conversation no longer exists. It allows a single ConversationExtractor object to be used multiple times, and it can make use of an extractor made using the default constructor.

Postcondition
The given Conversation must not change before this object is used to extract all the data that will be extracted.
Parameters
conThe conversation to extract.

Definition at line 114 of file ConversationExtractor.hpp.

◆ reset() [3/3]

void duds::hardware::interface::ConversationExtractor::reset ( const ConversationPart cp)
inline

Must use functions that specify either big or little endian.

Definition at line 121 of file ConversationExtractor.hpp.

◆ set()

void duds::hardware::interface::ConversationExtractor::set ( )
private

Sets internal data to read from the begining of extractible data stored in Conversation c.

Definition at line 15 of file ConversationExtractor.cpp.

Friends And Related Function Documentation

◆ operator>>() [1/2]

template<typename Int >
ConversationExtractor & operator>> ( ConversationExtractor ce,
Int &  i 
)
related

Extraction operator to read an integer from a Conversation through a ConversationExtractor object.

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

Precondition
The remaining bytes to read is at least the size of Int.
Template Parameters
IntThe integer type.
Parameters
ceThe source ConversationExtractor object.
iThe integer to that will receive the extracted value.
Exceptions
ConversationReadPastEndThe integer type is too large to fit in the remaining bytes of the current part. The read position is left unchanged.
Returns
A reference to ce.

Definition at line 450 of file ConversationExtractor.hpp.

◆ operator>>() [2/2]

template<typename Int , std::size_t N>
ConversationExtractor & operator>> ( ConversationExtractor ce,
Int(&)  a[N] 
)
related

Extraction operator to read an array of integers from a Conversation through a ConversationExtractor object.

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

Precondition
The remaining bytes to read is at least the size of the array.
Template Parameters
IntThe integer type.
NThe number of elements in the array.
Parameters
ceThe source ConversationExtractor object.
aThe start of the destination integer array.
Exceptions
ConversationReadPastEndThe integer type is too large to fit in the remaining bytes of the current part. The read position is left unchanged.
Returns
A reference to ce.

Definition at line 472 of file ConversationExtractor.hpp.

Member Data Documentation

◆ c

const Conversation* duds::hardware::interface::ConversationExtractor::c
private

The Conversation object with the parts to read.

Definition at line 57 of file ConversationExtractor.hpp.

Referenced by advance(), nextPart(), and set().

◆ piter

Conversation::PartVector::const_iterator duds::hardware::interface::ConversationExtractor::piter
private

Iterator to the current part being read.

Definition at line 53 of file ConversationExtractor.hpp.

Referenced by advance(), nextPart(), and set().

◆ pos

const char* duds::hardware::interface::ConversationExtractor::pos
private

Pointer to the next byte to read.

Definition at line 61 of file ConversationExtractor.hpp.

Referenced by advance(), nextPart(), read(), and set().

◆ remain

std::size_t duds::hardware::interface::ConversationExtractor::remain
private

The remaining number of bytes to read in the part referenced by piter.

Definition at line 65 of file ConversationExtractor.hpp.

Referenced by advance(), nextPart(), read(), and set().


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