DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
Buffer.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "Common.h"
9#include "System/Object.h"
10#include "System/Array.h"
11#include "System/Char.h"
15
16namespace DotNetDupe {
17 namespace System {
18 using byte = unsigned char;
19
25 class Buffer : public Object {
26 public:
37 template <typename T>
38 static void BlockCopy(Array<T>& src, int srcOffset, Array<T>& dst, int dstOffset, int count) {
39 if (src.IsNull())
40 throw ArgumentNullException("src");
41 if (dst.IsNull())
42 throw ArgumentNullException("dst");
43
44 if (srcOffset < 0)
45 throw ArgumentOutOfRangeException("srcOffset");
46 if (dstOffset < 0)
47 throw ArgumentOutOfRangeException("dstOffset");
48 if (count < 0)
49 throw ArgumentOutOfRangeException("count");
50
51 if (srcOffset + count > src.GetLength() * sizeof(T))
52 throw ArgumentException("srcOffset + count > src.ByteLength");
53 if (dstOffset + count > dst.GetLength() * sizeof(T))
54 throw ArgumentException("dstOffset + count > dst.ByteLength");
55
57 for (int i = 0; i < count; ++i) {
58 *((char*)dst.GetData() + dstOffset + i) = *((char*)src.GetData() + srcOffset + i);
59 }
60 }
61
67 template <typename T>
68 static int ByteLength(Array<T>& array) {
69 if (array.IsNull())
70 throw ArgumentNullException("array");
71 return array.GetLength() * sizeof(T);
72 }
73
80 template <typename T>
81 static byte GetByte(Array<T>& array, int index) {
82 if (index < 0 || index >= ByteLength(array))
83 throw ArgumentOutOfRangeException("index");
84 return *((byte*)array.GetData() + index);
85 }
86
93 template <typename T>
94 static void SetByte(Array<T>& array, int index, byte value) {
95 if (index < 0 || index >= ByteLength(array))
96 throw ArgumentOutOfRangeException("index");
97 *((byte*)array.GetData() + index) = value;
98 }
99 };
100
101 }
102}
Defines the exception thrown when an invalid argument is provided to a method.
Defines the exception thrown when a null reference is passed to a method that does not accept it.
Defines the exception thrown when an argument value is outside the acceptable range of values.
Provides methods for creating, manipulating, searching, and sorting arrays.
Represents a Unicode character code point mirroring .NET System.Char.
Defines common cross-platform macros, export decorators, and fundamental types.
Base object class for DotNetDupe mirroring .NET System.Object.
ArgumentException(const String &sMessage)
Initializes a new instance of the ArgumentException class with a specified error message.
ArgumentNullException(const String &sMessage)
Initializes a new instance of the ArgumentNullException class with a specified error message.
ArgumentOutOfRangeException(const String &sMessage)
Initializes a new instance of the ArgumentOutOfRangeException class with a specified error message.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition Array.h:29
int GetLength() const
Gets the total number of elements in all dimensions of the Array.
Definition Array.h:142
T * GetData()
Gets a pointer to the contiguous internal element buffer.
Definition Array.h:146
bool IsNull() const
Checks whether the array has zero length.
Definition Array.h:166
Manipulates arrays of primitive types efficiently at the byte level.
Definition Buffer.h:25
static void SetByte(Array< T > &array, int index, byte value)
Assigns a specified value to a byte at a particular location in a specified array.
Definition Buffer.h:94
static void BlockCopy(Array< T > &src, int srcOffset, Array< T > &dst, int dstOffset, int count)
Copies a specified number of bytes from a source array starting at a particular offset to a destinati...
Definition Buffer.h:38
static byte GetByte(Array< T > &array, int index)
Retrieves the byte at a specified location in a specified array.
Definition Buffer.h:81
static int ByteLength(Array< T > &array)
Returns the number of bytes in the specified array.
Definition Buffer.h:68
Supports all classes in the DotNetDupe class hierarchy.
Definition Object.h:18
unsigned char byte
Definition Buffer.h:18