CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
memory_marshal.h
1
2#pragma once
3
4#include <system/span.h>
5#include <system/memory.h>
6
7namespace System { namespace Runtime { namespace InteropServices {
8
14{
15public:
20 template<typename T>
21 static Span<uint8_t> AsBytes(const Span<T>& span)
22 {
23 return Span<uint8_t>(span.data_ptr(), span.get_Length() * sizeof(T));
24 }
25
31 template <typename TFrom, typename TTo>
32 static Span<TTo> Cast(const Span<TFrom>& span)
33 {
34 return Span<TTo>((TTo*)span.data_ptr(), span.get_Length() * sizeof(TFrom) / sizeof(TTo));
35 }
36
41 template <typename T>
42 static Memory<T> AsMemory(const ReadOnlyMemory<T>& memory)
43 {
44 return reinterpret_cast<const Memory<T>&>(memory);
45 }
46
51 template <typename T>
52 static T& GetReference(const Span<T>& span)
53 {
54 return *span.data_ptr();
55 }
56
61 template <typename T>
62 static T& GetReference(const ReadOnlySpan<T>& span)
63 {
64 return *span.data_ptr();
65 }
66};
67
68}}} // namespace System::Runtime::InteropServices
Represents a mutable memory segment backed by an array.
Definition: memory.h:154
Represents a read-only memory segment backed by an array.
Definition: memory.h:232
Forward to use within Span class.
Definition: span.h:404
Provides memory marshalling implementation. For compatibility with translated code only,...
Definition: memory_marshal.h:14
static Span< TTo > Cast(const Span< TFrom > &span)
Casts a Span of one primitive type TFrom to another primitive type TTo.
Definition: memory_marshal.h:32
static T & GetReference(const ReadOnlySpan< T > &span)
Gets a reference to the first element of the specified read-only span.
Definition: memory_marshal.h:62
static Span< uint8_t > AsBytes(const Span< T > &span)
Casts a Span of one primitive type T to Span of bytes.
Definition: memory_marshal.h:21
static Memory< T > AsMemory(const ReadOnlyMemory< T > &memory)
Casts a ReadOnlyMemory to mutable Memory.
Definition: memory_marshal.h:42
static T & GetReference(const Span< T > &span)
Gets a reference to the first element of the specified span.
Definition: memory_marshal.h:52
Represents a contiguous region of arbitrary memory similar to C++20's std::span.
Definition: span.h:364
Definition: db_command.h:9