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
98 static ASPOSECPP_SHARED_API void BlockCopy(const SharedPtr<ArrayBase>& src, int srcOffset,
99 const SharedPtr<ArrayBase>& dst, int dstOffset, int count);
100
109 template<typename TSrc, typename TDst>
110 static void BlockCopy(const System::Details::ArrayView<TSrc>& src, int srcOffset, const System::Details::ArrayView<TDst>& dst, int dstOffset, int count)
111 {
112 static_assert(Details::IsPod<TSrc>::value, "BlockCopy template argument must be a POD type.");
113 static_assert(Details::IsPod<TDst>::value, "BlockCopy template argument must be a POD type.");
114
115 if (!src)
116 throw ArgumentNullException(u"src");
117
118 if (!dst)
119 throw ArgumentNullException(u"dst");
120
121 if (0 > srcOffset || 0 > dstOffset || 0 > count)
122 throw ArgumentOutOfRangeException();
123
124 if (_ByteLength(src) < srcOffset || _ByteLength(src) < srcOffset + count)
125 throw ArgumentOutOfRangeException(u"src->Count() < srcOffset |+count|");
126
127 if (_ByteLength(dst) < dstOffset || _ByteLength(dst) < dstOffset + count)
128 throw ArgumentOutOfRangeException(u"dst->Count() < dstOffset |+count|");
129
130 if (0 == count)
131 return;
132
133 _BlockCopy(src, srcOffset, dst, dstOffset, count);
134 }
135
144 template<typename TSrc, typename TDst>
145 static void BlockCopy(const SharedPtr<Array<TSrc>>& src, int srcOffset, const System::Details::ArrayView<TDst>& dst, int dstOffset, int count)
146 {
147 BlockCopy(static_cast<System::Details::ArrayView<TSrc>>(src), srcOffset, dst, dstOffset, count);
148 }
149
158 template<typename TSrc, typename TDst>
159 static void BlockCopy(const System::Details::ArrayView<TSrc>& src, int srcOffset, const SharedPtr<Array<TDst>>& dst, int dstOffset, int count)
160 {
161 BlockCopy(src, srcOffset, static_cast<System::Details::ArrayView<TDst>>(dst), dstOffset, count);
162 }
163
174 template<typename TSrc, std::size_t NS, typename TDst, std::size_t ND>
175 static void BlockCopy(const System::Details::StackArray<TSrc, NS>& src, int srcOffset, const System::Details::StackArray<TDst, ND>& dst, int dstOffset, int count)
176 {
177 BlockCopy(static_cast<System::Details::ArrayView<TSrc>>(src), srcOffset, static_cast<System::Details::ArrayView<TDst>>(dst), dstOffset, count);
178 }
179
189 template<typename TSrc, typename TDst, std::size_t ND>
190 static void BlockCopy(const SharedPtr<Array<TSrc>>& src, int srcOffset, const System::Details::StackArray<TDst, ND>& dst, int dstOffset, int count)
191 {
192 BlockCopy(static_cast<System::Details::ArrayView<TSrc>>(src), srcOffset, static_cast<System::Details::ArrayView<TDst>>(dst), dstOffset, count);
193 }
194
204 template<typename TSrc, std::size_t NS, typename TDst>
205 static void BlockCopy(const System::Details::StackArray<TSrc, NS>& src, int srcOffset, const SharedPtr<Array<TDst>>& dst, int dstOffset, int count)
206 {
207 BlockCopy(static_cast<System::Details::ArrayView<TSrc>>(src), srcOffset, static_cast<System::Details::ArrayView<TDst>>(dst), dstOffset, count);
208 }
209
214 template<class T>
215 static int ByteLength(const SharedPtr<Array<T>>& array)
216 {
217 return ByteLength(static_cast<System::Details::ArrayView<T>>(array));
218 }
219
224 template<class T>
225 static int ByteLength(const System::Details::ArrayView<T>& array)
226 {
227 static_assert(Details::IsPod<T>::value, "ByteLength template argument must be a POD type.");
228
229 if (!array)
230 throw ArgumentNullException(u"array");
231
232 return _ByteLength(array);
233 }
234
240 template<class T, std::size_t N>
241 static int ByteLength(const System::Details::StackArray<T, N>& array)
242 {
243 return ByteLength(static_cast<System::Details::ArrayView<T>>(array));
244 }
245
251 template<typename T>
252 static uint8_t GetByte(const SharedPtr<Array<T>>& array, int index)
253 {
254 return GetByte(static_cast<System::Details::ArrayView<T>>(array), index);
255 }
256
262 template<typename T>
263 static uint8_t GetByte(const System::Details::ArrayView<T>& array, int index)
264 {
265 static_assert(Details::IsPod<T>::value, "GetByte template argument must be a POD type.");
266
267 if (!array)
268 throw ArgumentNullException(u"array");
269
270 if (index < 0 || index >= _ByteLength(array))
271 throw ArgumentOutOfRangeException(u"index");
272
273 return _GetByte<T>(array, index);
274 }
275
282 template<typename T, std::size_t N>
283 static uint8_t GetByte(const System::Details::StackArray<T, N>& array, int index)
284 {
285 return GetByte(static_cast<System::Details::ArrayView<T>>(array), index);
286 }
287
293 template<typename T>
294 static void SetByte(const SharedPtr<Array<T>>& array, int index, uint8_t value)
295 {
296 SetByte(static_cast<System::Details::ArrayView<T>>(array), index, value);
297 }
298
304 template<typename T>
305 static void SetByte(const System::Details::ArrayView<T>& array, int index, uint8_t value)
306 {
307 static_assert(Details::IsPod<T>::value, "SetByte template argument must be a POD type.");
308
309 if (!array)
310 throw ArgumentNullException(u"array");
311
312 if (index < 0 || index >= _ByteLength(array))
313 throw ArgumentOutOfRangeException(u"index");
314
315 return _SetByte<T>(array, index, value);
316 }
317
324 template<typename T, std::size_t N>
325 static void SetByte(const System::Details::StackArray<T, N>& array, int index, uint8_t value)
326 {
327 SetByte(static_cast<System::Details::ArrayView<T>>(array), index, value);
328 }
329
330 private:
331
336 template<typename T>
337 static int _ByteLength(const System::Details::ArrayView<T>& array)
338 {
339 return (int)(array.Count()*sizeof(T));
340 }
341
347 template<typename T>
348 static uint8_t _GetByte(const System::Details::ArrayView<T>& array, int index)
349 {
350 return reinterpret_cast<const uint8_t*>(array.data())[index];
351 }
352
358 template<typename T>
359 static void _SetByte(const System::Details::ArrayView<T>& array, int index, uint8_t value)
360 {
361 reinterpret_cast<uint8_t*>(array.data())[index] = value;
362 }
363
372 template<typename TSrc, typename TDst>
373 static void _BlockCopy(const System::Details::ArrayView<TSrc>& src, int srcOffset, const System::Details::ArrayView<TDst>& dst, int dstOffset, int count)
374 {
375 std::copy(reinterpret_cast<const uint8_t*>(src.data()) + static_cast<size_t>(srcOffset)
376 , reinterpret_cast<const uint8_t*>(src.data()) + static_cast<size_t>(srcOffset) + static_cast<size_t>(count)
377 , reinterpret_cast<uint8_t*>(dst.data()) + static_cast<size_t>(dstOffset));
378 }
379 };
380}
381
382#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:285
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:145
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:175
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:263
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:110
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:225
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:190
static int ByteLength(const SharedPtr< Array< T > > &array)
Determines the number of bytes occupied by all elements of the specified array.
Definition: buffer.h:215
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:241
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:159
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:305
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:325
static void BlockCopy(const SharedPtr< ArrayBase > &src, int srcOffset, const SharedPtr< ArrayBase > &dst, int dstOffset, int count)
Interprets two specified arrays as raw arrays of bytes and copies data from one of them to another.
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:283
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:205
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:294
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:252
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