DUDS
Distributed Update of Data from Something
ConversationVector.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
11 #include <duds/general/Errors.hpp>
12 
13 namespace duds { namespace hardware { namespace interface {
14 
16  if (input()) {
17  throw ConversationBadAdd();
18  }
19  data.push_back(i);
20 }
21 
22 void ConversationVector::add(const std::string &str) {
23  if (input()) {
24  throw ConversationBadAdd();
25  }
26  data.insert(data.end(), str.begin(), str.end());
27 }
28 
29 void ConversationVector::add(std::int8_t *a, std::size_t l) {
30  if (input()) {
31  throw ConversationBadAdd();
32  }
33  data.insert(data.end(), a, a + l);
34 }
35 
36 void ConversationVector::setStartOffset(std::int16_t offset) {
37  if (!varyingLength()) {
39  }
40  if ((offset < 0) || (offset > data.size())) {
42  }
43  val16 = offset;
44 }
45 
46 void ConversationVector::setLength(std::size_t len) {
47  if (varyingLength()) {
48  data.resize(len);
49  } else {
51  }
52 }
53 
54 void ConversationVector::reserve(std::size_t len) {
55  data.reserve(len + val16);
56 }
57 
59  return const_cast<char*>(&(data[val16]));
60 }
61 
62 std::size_t ConversationVector::length() const {
63  return data.size() - val16;
64 }
65 
66 } } }
void add(char i)
Adds a byte to an output part.
virtual std::size_t length() const
Returns the length of the buffer following the start pointer.
bool varyingLength() const
True if this part is flagged as having a variable length.
An attempt was made to change the starting offset of a ConversationVector to an invalid value...
void setLength(std::size_t len)
Sets a new length, including the data prior to the start pointer, for a conversation part with a vary...
std::int16_t val16
A small integer for derived classes to use.
An attempt was made to add data to a conversation part flagged for input.
void setStartOffset(std::int16_t offset)
Sets a new start offset, in bytes, for a variable length input part.
An operation requiring a varible length conversation part was attempted on a part not flagged as havi...
void reserve(std::size_t len)
Reserves space in the internal vector.
std::vector< char > data
The internal buffer.
virtual char * start() const
Returns a pointer to the begining of the conversation part&#39;s buffer.
General errors.
bool input() const
True if this part is flagged for input use.
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
Definition: Errors.hpp:48