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