DUDS
Distributed Update of Data from Something
Conversation.hpp
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  */
16 #ifndef CONVERSATION_HPP
17 #define CONVERSATION_HPP
18 
19 #include <memory>
22 
23 namespace duds { namespace hardware { namespace interface {
24 
26 
31 typedef boost::error_info<struct Info_ConversationPartIndex, int>
33 
52 class Conversation {
53 public:
57  typedef std::vector< std::unique_ptr<ConversationPart> > PartVector;
58 protected:
62  PartVector parts; // the clonus horror
63 public:
64  //struct CopyAll { };
65  //struct CopyExtractible { };
66  //struct MoveExtractible { };
67  Conversation() = default;
68  //Conversation(const Conversation &msg);
69  //Conversation(const Conversation &msg, CopyAll) : Conversation(msg) { }
70  /*
71  * Creates a copy of the given Conversation that only includes the
72  * ConversationPart objects flagged as extractible.
73  * @sa ConversationPart::MpfExtract
74  * @param msg The source of the copy.
75  */
76  //Conversation(const Conversation &msg, CopyExtractible);
77  /*
78  * Creates a new Conversation that only includes ConversationPart objects
79  * flagged as extractible. The parts are moved from the original. They
80  * are replaced in @a msg by new ConversationVector objects with identical
81  * flags and lengths. This can be used to extract data on one thread while
82  * reusing the original Conversation to gather more data.
83  * @sa ConversationPart::MpfExtract
84  * @param msg The source of the copy.
85  */
86  //Conversation(Conversation &msg, MoveExtractible);
90  PartVector::iterator begin() {
91  return parts.begin();
92  }
96  PartVector::iterator end() {
97  return parts.end();
98  }
103  PartVector::const_iterator cbegin() const {
104  return parts.cbegin();
105  }
109  PartVector::const_iterator cend() const {
110  return parts.cend();
111  }
115  std::size_t size() const {
116  return parts.size();
117  }
121  bool empty() const {
122  return parts.empty();
123  }
127  void clear() {
128  parts.clear();
129  }
138  template <class CP>
139  void add(std::unique_ptr<CP> &cp) {
140  parts.emplace_back(std::move(cp));
141  }
150  template <class CP>
151  CP &add(const CP &cp) {
152  CP *np = new CP(cp);
153  parts.emplace_back(np);
154  return *np;
155  }
166  ConversationVector &addInputVector(std::size_t len);
175  template <class LengthType>
176  ConversationVector &addInputVector(std::size_t len, LengthType lt) {
177  ConversationVector *cv = new ConversationVector(len, lt);
178  parts.emplace_back(cv);
179  return *cv;
180  }
186  ConversationExternal &addOutputBuffer(const char *a, std::size_t len);
193  template <typename T, std::size_t N>
196  parts.emplace_back(ce);
197  return *ce;
198  }
206  ConversationExternal &addInputBuffer(char *a, std::size_t len);
215  template <typename T, std::size_t N>
218  parts.emplace_back(ce);
219  return *ce;
220  }
228 };
229 
230 } } }
231 
232 #endif // #ifndef CONVERSATION_HPP
ConversationExternal & addOutputBuffer(const char *a, std::size_t len)
Adds a conversation part that will use the given buffer for output.
void clear()
Makes the conversation empty.
std::size_t size() const
Returns the number of parts within this conversation.
ConversationVector & addInputVector(std::size_t len)
Creates a new ConversationVector for fixed length input and initializes it with the given length...
void add(std::unique_ptr< CP > &cp)
Adds an already constructed conversation part to the end of the conversation.
ConversationVector & addInputVector(std::size_t len, LengthType lt)
Creates a new ConversationVector for fixed or variable length input and initializes it with the given...
CP & add(const CP &cp)
Adds a copy of an existing conversation part to the end of the conversation.
ConversationExternal & addInputBuffer(T(&a)[N])
Adds a conversation part that will write input into the given array.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
References a conversation part in an externally controlled buffer.
PartVector::const_iterator cend() const
An iterator to the end of ConversationPart vector.
PartVector::iterator begin()
An iterator to the first ConversationPart that allows modification.
PartVector parts
The container of the parts that make up the full conversation.
PartVector::iterator end()
An iterator to the end of ConversationPart vector.
ConversationExtractor extract() const
Returns an extraction object that can be used to read all the conversation data marked extractible...
ConversationVector & addOutputVector()
Creates a new ConversationVector for output and returns it for modification.
ConversationExternal & addOutputBuffer(const T(&a)[N])
Adds a conversation part that will use the given array for output.
PartVector::const_iterator cbegin() const
An iterator to the first ConversationPart that does not allow modification.
Extracts data from a Conversation without modifying the Conversation or copying from it...
std::vector< std::unique_ptr< ConversationPart > > PartVector
The storage type for the ConversationPart objects.
ConversationExternal & addInputBuffer(char *a, std::size_t len)
Adds a conversation part that will write input into the given buffer.
bool empty() const
Returns true if the conversation has no parts.
Holds a conversation part inside a vector.
Represents a two-way conversation with a device.
boost::error_info< struct Info_ConversationPartIndex, int > ConversationPartIndex
An attribute for errors when using Conversation objects that references the ConversationPart by index...