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
61template<typename T>
63{
66
67 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
68 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
69
70public:
72 {
73 return m_array;
74 }
75
76 int32_t get_Offset()
77 {
78 return m_offset;
79 }
80
81 int32_t get_Count()
82 {
83 return m_count;
84 }
85
86 ArraySegment(System::ArrayPtr<T> array) : m_offset(0), m_count(0)
87 {
88 if (array == nullptr)
89 {
90 throw ArgumentNullException(u"array");
91 }
92 m_array = array;
93 m_offset = 0;
94 m_count = array->get_Length();
95 }
96
97 ArraySegment(System::ArrayPtr<T> array, int32_t offset, int32_t count)
98 {
99 if (array == nullptr)
100 {
101 throw ArgumentNullException(u"array");
102 }
103 if (offset < 0)
104 {
105 throw ArgumentOutOfRangeException(u"offset_ArgumentOutOfRange_NeedNonNegNum");
106 }
107 if (count < 0)
108 {
109 throw ArgumentOutOfRangeException(u"count_ArgumentOutOfRange_NeedNonNegNum");
110 }
111 if (array->get_Length() - offset < count)
112 {
113 throw ArgumentException(u"Argument_InvalidOffLen");
114 }
115 m_array = array;
116 m_offset = offset;
117 m_count = count;
118 }
119
120 int32_t GetHashCode() const override
121 {
122 return nullptr == m_array ? 0 : System::ObjectExt::GetHashCode(m_array) ^ m_offset ^ m_count;
123 }
124
125 virtual bool Equals(System::SharedPtr<Object> obj) override
126 {
128 {
130 }
131 else
132 {
133 return false;
134 }
135 }
136
138 {
139 return obj.m_array == m_array && obj.m_offset == m_offset && obj.m_count == m_count;
140 }
141
142 ArraySegment() : m_offset(0), m_count(0) { }
143
144private:
145 System::ArrayPtr<T> m_array;
146 int32_t m_offset;
147 int32_t m_count;
148};
149
150template<typename T>
152{
153 return System::ObjectExt::Equals(a, b);
154}
155
156template<typename T>
158{
159 return !(a == b);
160}
161
162} // namespace System
Represents a segment of the one-dimensional array. Objects of this class should only be allocated usi...
Definition: array_segment.h:63
int32_t GetHashCode() const override
Analog of C# Object.GetHashCode() method. Enables hashing of custom objects.
Definition: array_segment.h:120
ArraySegment(System::ArrayPtr< T > array)
Definition: array_segment.h:86
int32_t get_Count()
Definition: array_segment.h:81
ArraySegment(System::ArrayPtr< T > array, int32_t offset, int32_t count)
Definition: array_segment.h:97
int32_t get_Offset()
Definition: array_segment.h:76
System::ArrayPtr< T > get_Array()
Definition: array_segment.h:71
bool Equals(ArraySegment< T > obj)
Definition: array_segment.h:137
virtual bool Equals(System::SharedPtr< Object > obj) override
Definition: array_segment.h:125
ArraySegment()
Definition: array_segment.h:142
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:157
bool operator==(ArraySegment< T > a, ArraySegment< T > b)
Definition: array_segment.h:151