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()
76 {
77 return m_offset;
78 }
79
80 int32_t get_Count()
81 {
82 return m_count;
83 }
84
85 ArraySegment(System::ArrayPtr<T> array) : m_offset(0), m_count(0)
86 {
87 if (array == nullptr)
88 {
89 throw ArgumentNullException(u"array");
90 }
91 m_array = array;
92 m_offset = 0;
93 m_count = array->get_Length();
94 }
95
96 ArraySegment(System::ArrayPtr<T> array, int32_t offset, int32_t count)
97 {
98 if (array == nullptr)
99 {
100 throw ArgumentNullException(u"array");
101 }
102 if (offset < 0)
103 {
104 throw ArgumentOutOfRangeException(u"offset_ArgumentOutOfRange_NeedNonNegNum");
105 }
106 if (count < 0)
107 {
108 throw ArgumentOutOfRangeException(u"count_ArgumentOutOfRange_NeedNonNegNum");
109 }
110 if (array->get_Length() - offset < count)
111 {
112 throw ArgumentException(u"Argument_InvalidOffLen");
113 }
114 m_array = array;
115 m_offset = offset;
116 m_count = count;
117 }
118
119 int32_t GetHashCode() const override
120 {
121 return nullptr == m_array ? 0 : System::ObjectExt::GetHashCode(m_array) ^ m_offset ^ m_count;
122 }
123
124 virtual bool Equals(System::SharedPtr<Object> obj) override
125 {
127 {
129 }
130 else
131 {
132 return false;
133 }
134 }
135
137 {
138 return obj.m_array == m_array && obj.m_offset == m_offset && obj.m_count == m_count;
139 }
140
141 ArraySegment() : m_offset(0), m_count(0) { }
142
143private:
144 System::ArrayPtr<T> m_array;
145 int32_t m_offset;
146 int32_t m_count;
147};
148
149template<typename T>
151{
152 return System::ObjectExt::Equals(a, b);
153}
154
155template<typename T>
157{
158 return !(a == b);
159}
160
161} // namespace System
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:119
ArraySegment(System::ArrayPtr< T > array)
Definition: array_segment.h:85
int32_t get_Count()
Definition: array_segment.h:80
ArraySegment(System::ArrayPtr< T > array, int32_t offset, int32_t count)
Definition: array_segment.h:96
int32_t get_Offset()
Definition: array_segment.h:75
System::ArrayPtr< T > get_Array()
Definition: array_segment.h:70
bool Equals(ArraySegment< T > obj)
Definition: array_segment.h:136
virtual bool Equals(System::SharedPtr< Object > obj) override
Definition: array_segment.h:124
ArraySegment()
Definition: array_segment.h:141
static std::enable_if< std::is_convertible< T, Object >::value &&std::is_final< T >::value &&!System::IsBoxable< T >::value &&System::IsSmartPtr< U >::value, bool >::type Is(const U &obj)
Implements 'is' operator translation. Specialization for pointer types optimized for 'final' classes.
Definition: object_ext.h:352
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:233
static int GetHashCode(const T &obj)
Implements GetHashCode() calls; works on both Object subclasses and unrelated types.
Definition: object_ext.h:28
static std::enable_if< IsExceptionWrapper< T >::value, bool >::type Equals(const T &obj, const T2 &another)
Definition: object_ext.h:34
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:62
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:156
bool operator==(ArraySegment< T > a, ArraySegment< T > b)
Definition: array_segment.h:150