DUDS
Distributed Update of Data from Something
ConversationPart.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  */
10 #ifndef CONVERSATIONPART_HPP
11 #define CONVERSATIONPART_HPP
12 
13 #include <cstdint>
15 #include <boost/exception/info.hpp>
16 
17 namespace duds { namespace hardware { namespace interface {
18 
22 struct ConversationError : virtual std::exception, virtual boost::exception { };
23 
51 public:
62  static constexpr Flags MpfInput = Flags::Bit(0);
67  static constexpr Flags MpfExtract = Flags::Bit(1);
73  static constexpr Flags MpfVarlen = Flags::Bit(2);
77  static constexpr Flags MpfBigendian = Flags::Bit(3);
88  static constexpr Flags MpfBreak = Flags::Bit(4);
89 private:
94  Flags mpf; // message part flags, but message was changed to conversation
95 protected:
100  std::int16_t val16;
104  ConversationPart(Flags f) : mpf(f) { }
108  ConversationPart(Flags f, std::int16_t v) : mpf(f), val16(v) { }
109 public:
113  ConversationPart(const ConversationPart &) = default;
114  virtual ~ConversationPart();
123  Flags flags() const {
124  return mpf;
125  }
129  bool input() const {
130  return mpf & MpfInput;
131  }
135  bool output() const {
136  return !(mpf & MpfInput);
137  }
141  bool extract() const {
142  return mpf & MpfExtract;
143  }
150  mpf.setTo(MpfExtract, ex);
151  return *this;
152  }
157  bool varyingLength() const {
158  return (mpf & MpfVarlen) && (mpf & MpfInput);
159  }
163  bool bigEndian() const {
164  return mpf & MpfBigendian;
165  }
173  mpf.setTo(MpfBigendian, big);
174  return *this;
175  }
179  bool littleEndian() const {
180  return !(mpf & MpfBigendian);
181  }
189  mpf.setTo(MpfBigendian, !little);
190  return *this;
191  }
202  mpf |= MpfBreak;
203  return *this;
204  }
211  virtual char *start() const = 0;
215  virtual std::size_t length() const = 0;
216 };
217 
218 } } }
219 
220 #endif // #ifndef CONVERSATIONPART_HPP
BitFlags setTo(const BitFlags &bf, bool val)
Make all bits in bf set or clear based on the value of val.
Definition: BitFlags.hpp:267
ConversationPart & breakBefore()
Flags the conversation part to have a break before this part is sent.
ConversationPart & extract(bool ex)
Changes the extraction flag for this part.
bool bigEndian() const
True if this part is flagged as having data in big-endian form.
bool varyingLength() const
True if this part is flagged as having a variable length.
bool output() const
True if this part is flagged for output use.
ConversationPart(Flags f, std::int16_t v)
Construct with the given flags and an initial value for val16.
Represents a section of a half-duplex conversation with a device.
std::int16_t val16
A small integer for derived classes to use.
bool littleEndian() const
True if this part is flagged as having data in little-endian form.
Base class for conversation related errors.
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...
ConversationPart(Flags f)
Construct with the given flags.
Flags flags() const
Returns the flags.
bool extract() const
True if this part is flagged for extraction by ConversationExtractor.
ConversationPart & bigEndian(bool big)
Changes the flagged endianess of this part.
ConversationPart & littleEndian(bool little)
Changes the flagged endianess of this part.
Flags mpf
A set of flags that alter the behavior of the message part.
bool input() const
True if this part is flagged for input use.