CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
bit_converter.h
1
3#ifndef __BitConverter_h__
4#define __BitConverter_h__
5
6#include "system/string.h"
7#include "system/array.h"
8#include "fwd.h"
9
10namespace System {
11
53 {
54 private:
59 static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> GetUShortBytes(const uint8_t *bytes);
64 static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> GetUIntBytes(const uint8_t *bytes);
69 static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> GetULongBytes(const uint8_t *bytes);
70
71 public:
74 static ASPOSECPP_SHARED_API bool _IsLittleEndian();
75
78 static const ASPOSECPP_SHARED_API bool IsLittleEndian;
79
83 static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> GetBytes(bool value);
84
88 static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> GetBytes(char_t value);
89
93 static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> GetBytes(int16_t value);
94
98 static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> GetBytes(int value);
99
103 static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> GetBytes(int64_t value);
104
108 static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> GetBytes(uint16_t value);
109
113 static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> GetBytes(uint32_t value);
114
118 static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> GetBytes(uint64_t value);
119
123 static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> GetBytes(float value);
124
128 static ASPOSECPP_SHARED_API System::ArrayPtr<uint8_t> GetBytes(double value);
129
130 private:
138 static void UShortFromBytes(uint8_t* dst, const System::Details::ArrayView<uint8_t>& src, int startIndex);
146 static void UIntFromBytes(uint8_t *dst, const System::Details::ArrayView<uint8_t>& src, int startIndex);
154 static void ULongFromBytes(uint8_t *dst, const System::Details::ArrayView<uint8_t>& src, int startIndex);
155
156 public:
161 static ASPOSECPP_SHARED_API bool ToBoolean(const System::ArrayPtr<uint8_t>& value, int startIndex);
162
167 static ASPOSECPP_SHARED_API bool ToBoolean(const System::Details::ArrayView<uint8_t> &value, int startIndex);
168
173 static ASPOSECPP_SHARED_API char_t ToChar(const System::ArrayPtr<uint8_t>& value, int startIndex);
174
179 static ASPOSECPP_SHARED_API char_t ToChar(const System::Details::ArrayView<uint8_t>& value, int startIndex);
180
185 static ASPOSECPP_SHARED_API int16_t ToInt16(const System::ArrayPtr<uint8_t>& value, int startIndex);
186
191 static ASPOSECPP_SHARED_API int16_t ToInt16(const System::Details::ArrayView<uint8_t>& value, int startIndex);
192
197 static ASPOSECPP_SHARED_API int ToInt32(const System::ArrayPtr<uint8_t>& value, int startIndex);
198
203 static ASPOSECPP_SHARED_API int ToInt32(const System::Details::ArrayView<uint8_t>& value, int startIndex);
204
209 static ASPOSECPP_SHARED_API int64_t ToInt64(const System::ArrayPtr<uint8_t>& value, int startIndex);
210
215 static ASPOSECPP_SHARED_API int64_t ToInt64(const System::Details::ArrayView<uint8_t>& value, int startIndex);
216
221 static ASPOSECPP_SHARED_API uint16_t ToUInt16(const System::ArrayPtr<uint8_t>& value, int startIndex);
222
227 static ASPOSECPP_SHARED_API uint16_t ToUInt16(const System::Details::ArrayView<uint8_t>& value, int startIndex);
228
233 static ASPOSECPP_SHARED_API uint32_t ToUInt32(const System::ArrayPtr<uint8_t>& value, int startIndex);
234
239 static ASPOSECPP_SHARED_API uint32_t ToUInt32(const System::Details::ArrayView<uint8_t>& value, int startIndex);
240
245 static ASPOSECPP_SHARED_API uint64_t ToUInt64(const System::ArrayPtr<uint8_t>& value, int startIndex);
246
251 static ASPOSECPP_SHARED_API uint64_t ToUInt64(const System::Details::ArrayView<uint8_t>& value, int startIndex);
252
257 static ASPOSECPP_SHARED_API float ToSingle(const System::ArrayPtr<uint8_t>& value, int startIndex);
258
263 static ASPOSECPP_SHARED_API float ToSingle(const System::Details::ArrayView<uint8_t>& value, int startIndex);
264
269 static ASPOSECPP_SHARED_API double ToDouble(const System::ArrayPtr<uint8_t>& value, int startIndex);
270
275 static ASPOSECPP_SHARED_API double ToDouble(const System::Details::ArrayView<uint8_t>& value, int startIndex);
276
283 static ASPOSECPP_SHARED_API String ToString(const ArrayPtr<uint8_t>& value, bool uppercase = true, const String& separator = u"-");
284
289 static ASPOSECPP_SHARED_API String ToString(const ArrayPtr<uint8_t>& value, int startIndex);
290
296 static ASPOSECPP_SHARED_API String ToString(const ArrayPtr<uint8_t>& value, int startIndex, int length);
297
302 static ASPOSECPP_SHARED_API int64_t DoubleToInt64Bits(double value);
303
307 static ASPOSECPP_SHARED_API double Int64BitsToDouble(int64_t value);
308 };
309
310}
311
312#endif
Contains methods that perform conversions of sequence of bytes to a value type and vice-versa....
Definition: bit_converter.h:53
static uint16_t ToUInt16(const System::ArrayPtr< uint8_t > &value, int startIndex)
Converts two bytes from the specified array starting at the specified index to unsigned 16-bit intege...
static bool _IsLittleEndian()
Indicates the endianness of the current architecture.
static System::ArrayPtr< uint8_t > GetBytes(uint64_t value)
Converts the specified unsigned 64-bit integer value into an array of bytes.
static System::ArrayPtr< uint8_t > GetBytes(uint16_t value)
Converts the specified unsigned 16-bit integer value into an array of bytes.
static int16_t ToInt16(const System::Details::ArrayView< uint8_t > &value, int startIndex)
Converts two bytes from the specified array starting at the specified index to 16-bit integer value.
static const bool IsLittleEndian
Indicates the endianness of the current architecture. true if the architecture is little endian,...
Definition: bit_converter.h:78
static double ToDouble(const System::ArrayPtr< uint8_t > &value, int startIndex)
Converts eight bytes from the specified array starting at the specified index to double-precision flo...
static int64_t ToInt64(const System::Details::ArrayView< uint8_t > &value, int startIndex)
Converts eight bytes from the specified array starting at the specified index to 64-bit integer value...
static System::ArrayPtr< uint8_t > GetBytes(float value)
Converts the specified single-precision floating-point value into an array of bytes.
static uint16_t ToUInt16(const System::Details::ArrayView< uint8_t > &value, int startIndex)
Converts two bytes from the specified array starting at the specified index to unsigned 16-bit intege...
static System::ArrayPtr< uint8_t > GetBytes(bool value)
Converts the specified boolean value into an array of bytes.
static int16_t ToInt16(const System::ArrayPtr< uint8_t > &value, int startIndex)
Converts two bytes from the specified array starting at the specified index to 16-bit integer value.
static bool ToBoolean(const System::Details::ArrayView< uint8_t > &value, int startIndex)
Converts one byte from the specified array starting at the specified index to boolean value.
static System::ArrayPtr< uint8_t > GetBytes(int16_t value)
Converts the specified 16-bit integer value into an array of bytes.
static String ToString(const ArrayPtr< uint8_t > &value, int startIndex, int length)
Converts a range of values of the specified byte array into their hexadecimal string representation.
static uint32_t ToUInt32(const System::ArrayPtr< uint8_t > &value, int startIndex)
Converts four bytes from the specified array starting at the specified index to unsigned 32-bit integ...
static int64_t DoubleToInt64Bits(double value)
Returns a 64-bit integer value whose binary representation is equal to binary representation of the s...
static char_t ToChar(const System::Details::ArrayView< uint8_t > &value, int startIndex)
Converts two bytes from the specified array starting at the specified index to char_t value.
static System::ArrayPtr< uint8_t > GetBytes(int value)
Converts the specified 32-bit integer value into an array of bytes.
static float ToSingle(const System::Details::ArrayView< uint8_t > &value, int startIndex)
Converts four bytes from the specified array starting at the specified index to single-precision floa...
static int ToInt32(const System::ArrayPtr< uint8_t > &value, int startIndex)
Converts four bytes from the specified array starting at the specified index to 32-bit integer value.
static int ToInt32(const System::Details::ArrayView< uint8_t > &value, int startIndex)
Converts four bytes from the specified array starting at the specified index to 32-bit integer value.
static uint64_t ToUInt64(const System::ArrayPtr< uint8_t > &value, int startIndex)
Converts eight bytes from the specified array starting at the specified index to unsigned 64-bit inte...
static int64_t ToInt64(const System::ArrayPtr< uint8_t > &value, int startIndex)
Converts eight bytes from the specified array starting at the specified index to 64-bit integer value...
static double Int64BitsToDouble(int64_t value)
Returns a double-precision floating point value whose value is equivalent to value.
static char_t ToChar(const System::ArrayPtr< uint8_t > &value, int startIndex)
Converts two bytes from the specified array starting at the specified index to char_t value.
static uint64_t ToUInt64(const System::Details::ArrayView< uint8_t > &value, int startIndex)
Converts eight bytes from the specified array starting at the specified index to unsigned 64-bit inte...
static System::ArrayPtr< uint8_t > GetBytes(char_t value)
Converts the specified char_t value into an array of bytes.
static String ToString(const ArrayPtr< uint8_t > &value, bool uppercase=true, const String &separator=u"-")
Converts all values of the specified byte array into their hexadecimal string representation....
static bool ToBoolean(const System::ArrayPtr< uint8_t > &value, int startIndex)
Converts one byte from the specified array starting at the specified index to boolean value.
static System::ArrayPtr< uint8_t > GetBytes(double value)
Converts the specified double-precision floating-point value into an array of bytes.
static double ToDouble(const System::Details::ArrayView< uint8_t > &value, int startIndex)
Converts eight bytes from the specified array starting at the specified index to double-precision flo...
static uint32_t ToUInt32(const System::Details::ArrayView< uint8_t > &value, int startIndex)
Converts four bytes from the specified array starting at the specified index to unsigned 32-bit integ...
static System::ArrayPtr< uint8_t > GetBytes(uint32_t value)
Converts the specified unsigned 32-bit integer value into an array of bytes.
static String ToString(const ArrayPtr< uint8_t > &value, int startIndex)
Converts values of the specified byte array into their hexadecimal string representation starting at ...
static System::ArrayPtr< uint8_t > GetBytes(int64_t value)
Converts the specified 64-bit integer value into an array of bytes.
static float ToSingle(const System::ArrayPtr< uint8_t > &value, int startIndex)
Converts four bytes from the specified array starting at the specified index to single-precision floa...
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
Definition: db_command.h:9