DUDS
Distributed Update of Data from Something
ConversationExternal.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  */
11 
12 namespace duds { namespace hardware { namespace interface {
13 
25  char *data;
29  std::size_t len;
30 public:
34  ConversationExternal(const ConversationExternal &) = default;
44  const char *a,
45  std::size_t length,
47  ) : ConversationPart(flags), data(const_cast<char*>(a)), len(length) { }
54  ConversationExternal(char *a, std::size_t length, Flags flags = MpfInput) :
55  ConversationPart(flags), data(a), len(length) { }
64  template <typename T, std::size_t N>
65  ConversationExternal(const T (&a)[N], Flags f = Flags::Zero()) :
67  data((char*)(const_cast<T(&)[N]>(a))),
68  len(N * sizeof(T)) { }
80  template <typename T, std::size_t N>
82  ConversationPart(f), data((char*)(a)), len(N * sizeof(T)) { }
83  virtual char *start() const;
84  virtual std::size_t length() const;
85 };
86 
87 } } }
static constexpr Flags MpfInput
True/set for input; false for output.
ConversationExternal(const T(&a)[N], Flags f=Flags::Zero())
Creates an output part from the given array.
static constexpr BitFlags Zero()
Makes a bit flags container with all flags cleared.
Definition: BitFlags.hpp:133
ConversationExternal(const ConversationExternal &)=default
Copies are ok.
ConversationExternal(const char *a, std::size_t length, Flags flags=Flags::Zero())
Creates an output part from the given buffer.
References a conversation part in an externally controlled buffer.
Represents a section of a half-duplex conversation with a device.
ConversationExternal(char *a, std::size_t length, Flags flags=MpfInput)
Creates an input part from the given buffer.
Flags flags() const
Returns the flags.
char * data
Points to the start of the external buffer.
virtual std::size_t length() const
Returns the length of the buffer following the start pointer.
virtual char * start() const
Returns a pointer to the begining of the conversation part&#39;s buffer.
ConversationExternal(T(&a)[N], Flags f=MpfInput)
Creates an input part from the given array.
std::size_t len
Length of the external buffer.