CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
array_segment.h
1
2#pragma once
3
4#include <system/shared_ptr.h>
5#include <system/object.h>
6#include <system/object_ext.h>
7#include <system/details/pointer_collection_helpers.h>
8#include <system/array.h>
9#include <cstdint>
10
11namespace System {
12
60template<typename T>
62{
65
66 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
67 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
68
69public:
71 {
72 return m_array;
73 }
74
75 int32_t get_Offset() const
76 {
77 return m_offset;
78 }
79
80 int32_t get_Count() const
81 {
82 return m_count;
83 }
84
85 T& operator[](int32_t index) const
86 {
87 return m_array[index + m_offset];
88 }
89
90 ArraySegment(System::ArrayPtr<T> array) : m_offset(0), m_count(0)
91 {
92 if (array == nullptr)
93 {
94 throw ArgumentNullException(u"array");
95 }
96 m_array = array;
97 m_offset = 0;
98 m_count = array->get_Length();
99 }
100
101 ArraySegment(System::ArrayPtr<T> array, int32_t offset, int32_t count)
102 {
103 if (array == nullptr)
104 {
105 throw ArgumentNullException(u"array");
106 }
107 if (offset < 0)
108 {
109 throw ArgumentOutOfRangeException(u"offset_ArgumentOutOfRange_NeedNonNegNum");
110 }
111 if (count < 0)
112 {
113 throw ArgumentOutOfRangeException(u"count_ArgumentOutOfRange_NeedNonNegNum");
114 }
115 if (array->get_Length() - offset < count)
116 {
117 throw ArgumentException(u"Argument_InvalidOffLen");
118 }
119 m_array = array;
120 m_offset = offset;
121 m_count = count;
122 }
123
125 {
126 auto result = MakeArray<T>(m_count);
127 Array<T>::Copy(m_array, m_offset, result, 0, m_count);
128 return result;
129 }
130
131 ArraySegment<T> Slice(int32_t index, int32_t count)
132 {
133 return ArraySegment<T>(m_array, m_offset + index, count);
134 }
135
136 int32_t GetHashCode() const override
137 {
138 return nullptr == m_array ? 0 : System::ObjectExt::GetHashCode(m_array) ^ m_offset ^ m_count;
139 }
140
141 virtual bool Equals(System::SharedPtr<Object> obj) override
142 {
144 {
146 }
147 else
148 {
149 return false;
150 }
151 }
152
154 {
155 return obj.m_array == m_array && obj.m_offset == m_offset && obj.m_count == m_count;
156 }
157
158 ArraySegment() : m_offset(0), m_count(0) { }
159
160private:
161 System::ArrayPtr<T> m_array;
162 int32_t m_offset;
163 int32_t m_count;
164};
165
166template<typename T>
168{
169 return System::ObjectExt::Equals(a, b);
170}
171
172template<typename T>
174{
175 return !(a == b);
176}
177
178} // namespace System
static void Copy(const ArrayPtr< SrcType > &srcArray, const ArrayPtr< DstType > &dstArray, int64_t count)
Copies the specified number of elements from the source array to the destination array.
Definition: array.h:1148
Represents a segment of the one-dimensional array. This type should be allocated on stack and passed ...
Definition: array_segment.h:62
int32_t GetHashCode() const override
Analog of C# Object.GetHashCode() method. Enables hashing of custom objects.
Definition: array_segment.h:136
ArraySegment(System::ArrayPtr< T > array)
Definition: array_segment.h:90
ArraySegment(System::ArrayPtr< T > array, int32_t offset, int32_t count)
Definition: array_segment.h:101
int32_t get_Count() const
Definition: array_segment.h:80
System::ArrayPtr< T > get_Array() const
Definition: array_segment.h:70
int32_t get_Offset() const
Definition: array_segment.h:75
bool Equals(ArraySegment< T > obj)
Definition: array_segment.h:153
T & operator[](int32_t index) const
Definition: array_segment.h:85
ArraySegment< T > Slice(int32_t index, int32_t count)
Definition: array_segment.h:131
virtual bool Equals(System::SharedPtr< Object > obj) override
Definition: array_segment.h:141
System::ArrayPtr< T > ToArray() const
Definition: array_segment.h:124
ArraySegment()
Definition: array_segment.h:158
static std::enable_if< std::is_enum< T >::value, T >::type Unbox(const SmartPtr< Object > &obj)
Unboxes value types after converting to Object. Implementation for enum types.
Definition: object_ext.h:235
static std::enable_if< System::IsBoxable< T >::value, bool >::type Is(const T &obj)
Implements 'is' operator translation. Specialization for boxable (value) types which exactly is that ...
Definition: object_ext.h:351
static int GetHashCode(const T &obj)
Implements GetHashCode() calls; works on both Object subclasses and unrelated types.
Definition: object_ext.h:30
static std::enable_if< IsExceptionWrapper< T >::value, bool >::type Equals(const T &obj, const T2 &another)
Definition: object_ext.h:36
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:51
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
bool operator!=(ArraySegment< T > a, ArraySegment< T > b)
Definition: array_segment.h:173
bool operator==(ArraySegment< T > a, ArraySegment< T > b)
Definition: array_segment.h:167