CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
buffer.h
1
3#ifndef _aspose_system_buffer_h_
4#define _aspose_system_buffer_h_
5
6#include <algorithm>
7
8#include "fwd.h"
9#include "system/array.h"
10#include "system/exceptions.h"
11#include "system/details/array_view.h"
12#include "system/details/stack_array.h"
13
14namespace System {
15
66 class Buffer
67 {
68 public:
69
76 static ASPOSECPP_SHARED_API void BlockCopy(const uint8_t* src, int srcOffset, uint8_t* dst, int dstOffset, int count);
77
86 template<typename TSrc, typename TDst>
87 static void BlockCopy(const SharedPtr<Array<TSrc>>& src, int srcOffset, const SharedPtr<Array<TDst>>& dst, int dstOffset, int count)
88 {
89 BlockCopy(static_cast<System::Details::ArrayView<TSrc>>(src), srcOffset, static_cast<System::Details::ArrayView<TDst>>(dst), dstOffset, count);
90 }
91
100 template<typename TSrc, typename TDst>
101 static void BlockCopy(const System::Details::ArrayView<TSrc>& src, int srcOffset, const System::Details::ArrayView<TDst>& dst, int dstOffset, int count)
102 {
103 static_assert(Details::IsPod<TSrc>::value, "BlockCopy template argument must be a POD type.");
104 static_assert(Details::IsPod<TDst>::value, "BlockCopy template argument must be a POD type.");
105
106 if (!src)
107 throw ArgumentNullException(u"src");
108
109 if (!dst)
110 throw ArgumentNullException(u"dst");
111
112 if (0 > srcOffset || 0 > dstOffset || 0 > count)
113 throw ArgumentOutOfRangeException();
114
115 if (_ByteLength(src) < srcOffset || _ByteLength(src) < srcOffset + count)
116 throw ArgumentOutOfRangeException(u"src->Count() < srcOffset |+count|");
117
118 if (_ByteLength(dst) < dstOffset || _ByteLength(dst) < dstOffset + count)
119 throw ArgumentOutOfRangeException(u"dst->Count() < dstOffset |+count|");
120
121 if (0 == count)
122 return;
123
124 _BlockCopy(src, srcOffset, dst, dstOffset, count);
125 }
126
135 template<typename TSrc, typename TDst>
136 static void BlockCopy(const SharedPtr<Array<TSrc>>& src, int srcOffset, const System::Details::ArrayView<TDst>& dst, int dstOffset, int count)
137 {
138 BlockCopy(static_cast<System::Details::ArrayView<TSrc>>(src), srcOffset, dst, dstOffset, count);
139 }
140
149 template<typename TSrc, typename TDst>
150 static void BlockCopy(const System::Details::ArrayView<TSrc>& src, int srcOffset, const SharedPtr<Array<TDst>>& dst, int dstOffset, int count)
151 {
152 BlockCopy(src, srcOffset, static_cast<System::Details::ArrayView<TDst>>(dst), dstOffset, count);
153 }
154
165 template<typename TSrc, std::size_t NS, typename TDst, std::size_t ND>
166 static void BlockCopy(const System::Details::StackArray<TSrc, NS>& src, int srcOffset, const System::Details::StackArray<TDst, ND>& dst, int dstOffset, int count)
167 {
168 BlockCopy(static_cast<System::Details::ArrayView<TSrc>>(src), srcOffset, static_cast<System::Details::ArrayView<TDst>>(dst), dstOffset, count);
169 }
170
180 template<typename TSrc, typename TDst, std::size_t ND>
181 static void BlockCopy(const SharedPtr<Array<TSrc>>& src, int srcOffset, const System::Details::StackArray<TDst, ND>& dst, int dstOffset, int count)
182 {
183 BlockCopy(static_cast<System::Details::ArrayView<TSrc>>(src), srcOffset, static_cast<System::Details::ArrayView<TDst>>(dst), dstOffset, count);
184 }
185
195 template<typename TSrc, std::size_t NS, typename TDst>
196 static void BlockCopy(const System::Details::StackArray<TSrc, NS>& src, int srcOffset, const SharedPtr<Array<TDst>>& dst, int dstOffset, int count)
197 {
198 BlockCopy(static_cast<System::Details::ArrayView<TSrc>>(src), srcOffset, static_cast<System::Details::ArrayView<TDst>>(dst), dstOffset, count);
199 }
200
205 template<class T>
206 static int ByteLength(const SharedPtr<Array<T>>& array)
207 {
208 return ByteLength(static_cast<System::Details::ArrayView<T>>(array));
209 }
210
215 template<class T>
216 static int ByteLength(const System::Details::ArrayView<T>& array)
217 {
218 static_assert(Details::IsPod<T>::value, "ByteLength template argument must be a POD type.");
219
220 if (!array)
221 throw ArgumentNullException(u"array");
222
223 return _ByteLength(array);
224 }
225
231 template<class T, std::size_t N>
232 static int ByteLength(const System::Details::StackArray<T, N>& array)
233 {
234 return ByteLength(static_cast<System::Details::ArrayView<T>>(array));
235 }
236
242 template<typename T>
243 static uint8_t GetByte(const SharedPtr<Array<T>>& array, int index)
244 {
245 return GetByte(static_cast<System::Details::ArrayView<T>>(array), index);
246 }
247
253 template<typename T>
254 static uint8_t GetByte(const System::Details::ArrayView<T>& array, int index)
255 {
256 static_assert(Details::IsPod<T>::value, "GetByte template argument must be a POD type.");
257
258 if (!array)
259 throw ArgumentNullException(u"array");
260
261 if (index < 0 || index >= _ByteLength(array))
262 throw ArgumentOutOfRangeException(u"index");
263
264 return _GetByte<T>(array, index);
265 }
266
273 template<typename T, std::size_t N>
274 static uint8_t GetByte(const System::Details::StackArray<T, N>& array, int index)
275 {
276 return GetByte(static_cast<System::Details::ArrayView<T>>(array), index);
277 }
278
284 template<typename T>
285 static void SetByte(const SharedPtr<Array<T>>& array, int index, uint8_t value)
286 {
287 SetByte(static_cast<System::Details::ArrayView<T>>(array), index, value);
288 }
289
295 template<typename T>
296 static void SetByte(const System::Details::ArrayView<T>& array, int index, uint8_t value)
297 {
298 static_assert(Details::IsPod<T>::value, "SetByte template argument must be a POD type.");
299
300 if (!array)
301 throw ArgumentNullException(u"array");
302
303 if (index < 0 || index >= _ByteLength(array))
304 throw ArgumentOutOfRangeException(u"index");
305
306 return _SetByte<T>(array, index, value);
307 }
308
315 template<typename T, std::size_t N>
316 static void SetByte(const System::Details::StackArray<T, N>& array, int index, uint8_t value)
317 {
318 SetByte(static_cast<System::Details::ArrayView<T>>(array), index, value);
319 }
320
321 private:
322
327 template<typename T>
328 static int _ByteLength(const System::Details::ArrayView<T>& array)
329 {
330 return (int)(array.Count()*sizeof(T));
331 }
332
338 template<typename T>
339 static uint8_t _GetByte(const System::Details::ArrayView<T>& array, int index)
340 {
341 return reinterpret_cast<const uint8_t*>(array.data())[index];
342 }
343
349 template<typename T>
350 static void _SetByte(const System::Details::ArrayView<T>& array, int index, uint8_t value)
351 {
352 reinterpret_cast<uint8_t*>(array.data())[index] = value;
353 }
354
363 template<typename TSrc, typename TDst>
364 static void _BlockCopy(const System::Details::ArrayView<TSrc>& src, int srcOffset, const System::Details::ArrayView<TDst>& dst, int dstOffset, int count)
365 {
366 std::copy(reinterpret_cast<const uint8_t*>(src.data()) + static_cast<size_t>(srcOffset)
367 , reinterpret_cast<const uint8_t*>(src.data()) + static_cast<size_t>(srcOffset) + static_cast<size_t>(count)
368 , reinterpret_cast<uint8_t*>(dst.data()) + static_cast<size_t>(dstOffset));
369 }
370 };
371}
372
373#endif // _aspose_system_buffer_h_
Class that represents an array data structure. Objects of this class should only be allocated using S...
Definition: array.h:259
Contains methods that manipulate raw byte arrays. This is a static type with no instance services....
Definition: buffer.h:67
static void BlockCopy(const SharedPtr< Array< TSrc > > &src, int srcOffset, const System::Details::ArrayView< TDst > &dst, int dstOffset, int count)
Interprets two specified typed arrays as raw arrays of bytes and copies data from one of them to anot...
Definition: buffer.h:136
static void BlockCopy(const uint8_t *src, int srcOffset, uint8_t *dst, int dstOffset, int count)
Copies a specified number of bytes from source buffer to destination buffer.
static void BlockCopy(const System::Details::StackArray< TSrc, NS > &src, int srcOffset, const System::Details::StackArray< TDst, ND > &dst, int dstOffset, int count)
Interprets two specified typed arrays as raw arrays of bytes and copies data from one of them to anot...
Definition: buffer.h:166
static uint8_t GetByte(const System::Details::ArrayView< T > &array, int index)
Interprets the specified typed array as a raw byte array and retrieves the byte value at specified by...
Definition: buffer.h:254
static void BlockCopy(const System::Details::ArrayView< TSrc > &src, int srcOffset, const System::Details::ArrayView< TDst > &dst, int dstOffset, int count)
Interprets two specified typed arrays as raw arrays of bytes and copies data from one of them to anot...
Definition: buffer.h:101
static int ByteLength(const System::Details::ArrayView< T > &array)
Determines the number of bytes occupied by all elements of the specified array.
Definition: buffer.h:216
static void BlockCopy(const SharedPtr< Array< TSrc > > &src, int srcOffset, const System::Details::StackArray< TDst, ND > &dst, int dstOffset, int count)
Interprets two specified typed arrays as raw arrays of bytes and copies data from one of them to anot...
Definition: buffer.h:181
static int ByteLength(const SharedPtr< Array< T > > &array)
Determines the number of bytes occupied by all elements of the specified array.
Definition: buffer.h:206
static int ByteLength(const System::Details::StackArray< T, N > &array)
Determines the number of bytes occupied by all elements of the specified array.
Definition: buffer.h:232
static void BlockCopy(const System::Details::ArrayView< TSrc > &src, int srcOffset, const SharedPtr< Array< TDst > > &dst, int dstOffset, int count)
Interprets two specified typed arrays as raw arrays of bytes and copies data from one of them to anot...
Definition: buffer.h:150
static void SetByte(const System::Details::ArrayView< T > &array, int index, uint8_t value)
Interprets the specified typed array as a raw byte array and sets the specified byte value at specifi...
Definition: buffer.h:296
static void SetByte(const System::Details::StackArray< T, N > &array, int index, uint8_t value)
Interprets the specified typed array as a raw byte array and sets the specified byte value at specifi...
Definition: buffer.h:316
static void BlockCopy(const SharedPtr< Array< TSrc > > &src, int srcOffset, const SharedPtr< Array< TDst > > &dst, int dstOffset, int count)
Interprets two specified typed arrays as raw arrays of bytes and copies data from one of them to anot...
Definition: buffer.h:87
static uint8_t GetByte(const System::Details::StackArray< T, N > &array, int index)
Interprets the specified typed array as a raw byte array and retrieves the byte value at specified by...
Definition: buffer.h:274
static void BlockCopy(const System::Details::StackArray< TSrc, NS > &src, int srcOffset, const SharedPtr< Array< TDst > > &dst, int dstOffset, int count)
Interprets two specified typed arrays as raw arrays of bytes and copies data from one of them to anot...
Definition: buffer.h:196
static void SetByte(const SharedPtr< Array< T > > &array, int index, uint8_t value)
Interprets the specified typed array as a raw byte array and sets the specified byte value at specifi...
Definition: buffer.h:285
static uint8_t GetByte(const SharedPtr< Array< T > > &array, int index)
Interprets the specified typed array as a raw byte array and retrieves the byte value at specified by...
Definition: buffer.h:243
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
Definition: db_command.h:9