10 #ifndef CONVERSATIONVECTOR_HPP 11 #define CONVERSATIONVECTOR_HPP 13 #include <type_traits> 17 namespace duds {
namespace hardware {
namespace interface {
112 input ? MpfInput | MpfExtract :
Flags::Zero(), 0
132 MpfInput | MpfExtract, 0
133 ), data(length + val16) { }
141 MpfInput | MpfExtract | MpfVarlen, sizeof(
std::size_t)
142 ), data(length + val16) { }
151 MpfInput | MpfExtract | (varlen ? MpfVarlen :
Flags::Zero()),
152 varlen ? sizeof(
std::size_t) : 0
153 ), data(length + val16) { }
161 data.reserve(length);
166 std::vector<char>::const_iterator
begin()
const {
172 std::vector<char>::const_iterator
end()
const {
187 template <
typename Int>
189 static_assert(std::is_integral<Int>::value,
190 "Only integer values can be added by this function.");
194 for (std::size_t loop =
sizeof(Int); loop; --loop) {
195 data.push_back((
char)(i & 0xFF));
205 template <
typename Int>
207 static_assert(std::is_integral<Int>::value,
208 "Only integer values can be added by this function.");
212 for (std::size_t loop =
sizeof(Int); loop; --loop) {
213 data.push_back((
char)(i >> (8 * (
sizeof(Int) - 1))));
242 template <
typename Int>
255 void add(
const std::string &str);
262 void add(std::int8_t *a, std::size_t l);
269 template <std::
size_t N>
270 void add(std::int8_t (&a)[N]) {
281 template <
typename Int>
282 void addLe(
const Int *a, std::size_t count) {
283 static_assert(std::is_integral<Int>::value,
284 "Only integer values can be added by this function.");
288 data.reserve(data.size() +
sizeof(Int) * count);
289 for (; count; --count) {
291 for (std::size_t loop =
sizeof(Int); loop; --loop) {
292 data.push_back((
char)(i & 0xFF));
305 template <
typename Int, std::
size_t N>
317 template <
typename Int>
318 void addBe(
const Int *a, std::size_t count) {
319 static_assert(std::is_integral<Int>::value,
320 "Only integer values can be added by this function.");
324 data.reserve(data.size() +
sizeof(Int) * count);
325 for (; count; --count) {
327 for (std::size_t loop =
sizeof(Int); loop; --loop) {
328 data.push_back((
char)(i >> (8 * (
sizeof(Int) - 1))));
341 template <
typename Int, std::
size_t N>
353 template <
typename Int>
354 void add(
const Int *a, std::size_t count) {
369 template <
typename Int, std::
size_t N>
370 void add(
const Int (&a)[N]) {
390 void setStartOffset(std::int16_t offset);
400 void setLength(std::size_t len);
405 void reserve(std::size_t len);
425 virtual char *start()
const;
426 virtual std::size_t length()
const;
439 template <
typename Int>
456 template <
typename Int, std::
size_t N>
517 const std::string &str
525 #endif // #ifndef CONVERSATIONVECTOR_HPP Used as a parameter to constructors to specify that communication will not change the length of the c...
ConversationVector(std::size_t length, Output)
Construct for output and reserve the given length within the internal vector.
ConversationVector(const std::vector< char > &v)
Construct for output and copy the given vector into this object.
void add(char i)
Adds a byte to an output part.
ConversationVector(std::size_t length, FixedLength)
Construct for fixed-length input and allocate space for the input.
bool bigEndian() const
True if this part is flagged as having data in big-endian form.
ConversationVector(std::vector< char > &&v)
Construct for output and move the given vector into this object.
Use with the insertion operator to specify big-endian data will follow.
ConversationVector(std::size_t length, VaribleLength)
Construct for variable-length input and allocate space for the input.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
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.
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.
An attempt was made to change the starting offset of a ConversationVector to an invalid value...
void addLe(Int i)
Adds an integer in little-endian form to an output part.
Represents a section of a half-duplex conversation with a device.
void addLe(const Int(&a)[N])
Adds an array of integers to the end of an output part in little-endian form.
An attempt was made to add data to a conversation part flagged for input.
ConversationVector(bool input)
Construct for either output or fixed-length input.
Base class for conversation related errors.
Used as a parameter to constructors to specify an output conversation part.
An operation requiring a varible length conversation part was attempted on a part not flagged as havi...
Use with the insertion operator to specify little-endian data will follow.
std::vector< char >::const_iterator begin() const
Begining iterator to inspect the contained data.
std::vector< char >::const_iterator end() const
Ending iterator to inspect the contained data.
void addBe(Int i)
Adds an integer in big-endian form to an output part.
Reserve(int l)
Specify how many bytes to reserve.
void reserve(std::size_t len)
Reserves space in the internal vector.
void add(const Int *a, std::size_t count)
Adds an array of integers to the end of an output part.
ConversationVector & operator<<(ConversationVector &cv, const Int &i)
Insertion operator to add an integer to a ConversationVector object.
Used as a parameter to constructors to specify that communication may change the length of the part...
Use with the insertion operator to reserve space in the vector.
std::vector< char > data
The internal buffer.
ConversationVector(Output)
Construct for output.
ConversationVector(Input)
Construct for fixed-length input without allocating space for the input.
void addBe(const Int(&a)[N])
Adds an array of integers to the end of an output part in big-endian form.
void add(std::int8_t(&a)[N])
Adds an array to the end an output part.
ConversationVector(std::size_t length, bool varlen=false)
Construct for fixed or variable-length input and allocate space for the input.
void addBe(std::int8_t i)
Adds a byte to an output part.
void add(const Int(&a)[N])
Adds an array of integers to the end of an output part.
void addLe(std::int8_t i)
Adds a byte to an output part.
void add(Int i)
Adds an integer to the end an output part.
Holds a conversation part inside a vector.