Remote Call Framework 3.4
ByteBuffer.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2023, Delta V Software. All rights reserved.
6 // https://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF under GPL terms.
12 //
13 // Version: 3.4
14 // Contact: support <at> deltavsoft.com
15 //
16 //******************************************************************************
17 
18 #ifndef INCLUDE_RCF_BYTEBUFFER_HPP
19 #define INCLUDE_RCF_BYTEBUFFER_HPP
20 
21 #include <functional>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include <RCF/Export.hpp>
27 
28 namespace RCF {
29 
30  class MemOstream;
31  typedef std::shared_ptr<MemOstream> MemOstreamPtr;
32 
33  class ReallocBuffer;
34  typedef std::shared_ptr<ReallocBuffer> ReallocBufferPtr;
35 
39  class RCF_EXPORT ByteBuffer
40  {
41  public:
42 
43  ByteBuffer();
44 
45  explicit
46  ByteBuffer(std::size_t pvlen);
47 
48  explicit
49  ByteBuffer(
50  const std::vector<char> & vc);
51 
52  explicit
53  ByteBuffer(
54  const std::string & s);
55 
56  explicit
57  ByteBuffer(
58  std::shared_ptr<std::vector<char> > spvc,
59  bool readOnly = false);
60 
61  explicit
62  ByteBuffer(
63  ReallocBufferPtr sprb,
64  bool readOnly = false);
65 
66  explicit
67  ByteBuffer(
68  MemOstreamPtr spos,
69  bool readOnly = false);
70 
71  ByteBuffer(
72  char *pv,
73  std::size_t pvlen,
74  bool readOnly = false);
75 
76  ByteBuffer(
77  char *pv,
78  std::size_t pvlen,
79  std::size_t leftMargin,
80  bool readOnly = false);
81 
82  ByteBuffer(
83  char *pv,
84  std::size_t pvlen,
85  std::shared_ptr<MemOstream> spos,
86  bool readOnly = false);
87 
88  ByteBuffer(
89  char *pv,
90  std::size_t pvlen,
91  std::size_t leftMargin,
92  std::shared_ptr<MemOstream> spos,
93  bool readOnly = false);
94 
95  ByteBuffer(
96  char *pv,
97  std::size_t pvlen,
98  std::shared_ptr<std::vector<char> > spvc,
99  bool readOnly = false);
100 
101  ByteBuffer(
102  char *pv,
103  std::size_t pvlen,
104  std::size_t leftMargin,
105  std::shared_ptr<std::vector<char> > spvc,
106  bool readOnly = false);
107 
108  ByteBuffer(
109  char *pv,
110  std::size_t pvlen,
111  ReallocBufferPtr sprb,
112  bool readOnly = false);
113 
114  ByteBuffer(
115  char *pv,
116  std::size_t pvlen,
117  std::size_t leftMargin,
118  ReallocBufferPtr sprb,
119  bool readOnly = false);
120 
121  ByteBuffer(
122  const ByteBuffer & byteBuffer,
123  std::size_t offset = 0,
124  std::size_t len = std::size_t(-1));
125 
126  char * getPtr() const;
127  std::size_t getLength() const;
128  std::size_t getLeftMargin() const;
129  bool getReadOnly() const;
130  bool isEmpty() const;
131  std::string string() const;
132 
133  void setLeftMargin(std::size_t len);
134  void expandIntoLeftMargin(std::size_t len);
135  ByteBuffer release();
136  void swap(ByteBuffer & rhs);
137  void clear();
138 
139  operator bool();
140  bool operator !();
141 
142  static const std::size_t npos;
143 
144  private:
145  // sentries
146  std::shared_ptr< std::vector<char> > mSpvc;
147  std::shared_ptr< MemOstream > mSpos;
148  std::shared_ptr< ReallocBuffer > mSprb;
149 
150  char * mPv;
151  std::size_t mPvlen;
152  std::size_t mLeftMargin;
153  bool mReadOnly;
154  };
155 
156  RCF_EXPORT bool operator==(const ByteBuffer &lhs, const ByteBuffer &rhs);
157 
158  RCF_EXPORT std::size_t lengthByteBuffers(
159  const std::vector<ByteBuffer> &byteBuffers);
160 
161  RCF_EXPORT void forEachByteBuffer(
162  std::function<void(const ByteBuffer&)> functor,
163  const std::vector<ByteBuffer> &byteBuffers,
164  std::size_t offset,
165  std::size_t length = -1);
166 
167  RCF_EXPORT ByteBuffer sliceByteBuffer(
168  const std::vector<ByteBuffer> &slicedBuffers,
169  std::size_t offset,
170  std::size_t length = -1);
171 
172  RCF_EXPORT void sliceByteBuffers(
173  std::vector<ByteBuffer> &slicedBuffers,
174  const std::vector<ByteBuffer> &byteBuffers,
175  std::size_t offset,
176  std::size_t length = std::size_t(-1));
177 
178  RCF_EXPORT void copyByteBuffers(
179  const std::vector<ByteBuffer> &byteBuffers,
180  char *pch);
181 
182  RCF_EXPORT void copyByteBuffers(
183  const std::vector<ByteBuffer> &byteBuffers,
184  ByteBuffer &byteBuffer);
185 
186 } // namespace RCF
187 
188 namespace SF {
189 
190  class Archive;
191 
192  RCF_EXPORT void serialize(SF::Archive &ar, RCF::ByteBuffer &byteBuffer);
193 
194 }
195 
196 #endif // ! INCLUDE_RCF_BYTEBUFFER_HPP
Represents an archive, in which serialized objects are stored.
Definition: Archive.hpp:31
Definition: ByteBuffer.hpp:188
Definition: ByteBuffer.hpp:39
Definition: AmiIoHandler.hpp:23