3#ifndef _aspose_system_array_h_
4#define _aspose_system_array_h_
6#include <system/details/collections_helper.h>
7#include <system/details/comparer_type.h>
8#include <system/details/equality_helper.h>
9#include <system/details/array_view.h>
10#include <system/details/stack_array.h>
11#include <system/object.h>
12#include <system/collections/icomparer.h>
13#include <system/collections/ienumerable.h>
14#include <system/collections/ilist.h>
15#include <system/exceptions.h>
16#include <system/collections/algorithms.h>
17#include <system/converter.h>
18#include <system/predicate.h>
19#include <system/action.h>
20#include <system/select_type.h>
21#include <system/cycles_detection.h>
28#include <initializer_list>
40 template <
typename X,
typename IdxType>
43 return (**ptr).operator[](
static_cast<int>(idx));
48 template <typename Integral, bool = std::numeric_limits<Integral>::is_signed>
49 struct NegativeValueChecker
54 static void Check(
const Integral &value)
57 throw System::OverflowException(u
"Negative array size");
62 template <
typename Integral>
63 struct NegativeValueChecker<Integral, false>
66 static void Check(
const Integral&) {}
71 template <
typename Integral,
bool = (sizeof(Integral) >
sizeof(int)) || (!std::numeric_limits<Integral>::is_signed && (
sizeof(Integral) ==
sizeof(
int)))>
72 struct IntPositiveOverflowChecker
77 static void Check(
const Integral& value)
79 if (value >=
static_cast<Integral
>((std::numeric_limits<int>::max)()))
80 throw System::OverflowException(u
"Array size too big for signed integer");
85 template <
typename Integral>
86 struct IntPositiveOverflowChecker<Integral, false>
89 static void Check(
const Integral &value) { ASPOSE_UNUSED(value); }
97 template <
typename Integral>
98 int FixArraySize(
const Integral &value)
100 NegativeValueChecker<Integral>::Check(value);
101 IntPositiveOverflowChecker<Integral>::Check(value);
102 return static_cast<int>(value);
140 System::Details::MakeObjectLeakageDetector::SignatureBacktraceSentry signature_sentry;
141 System::Details::MakeObjectLeakageDetector::SetSignature<Array<T>>(init);
143 Detail::OwnNextObject ownershipSentry;
147 ownershipSentry.CreatedSuccessfully(arr);
148 signature_sentry.CreatedSuccessfully(arr);
159 System::Details::MakeObjectLeakageDetector::SignatureBacktraceSentry signature_sentry;
160 System::Details::MakeObjectLeakageDetector::SetSignature<Array<T>>(std::forward<Args>(args)...);
162 Detail::OwnNextObject ownershipSentry;
166 ownershipSentry.CreatedSuccessfully(arr);
167 signature_sentry.CreatedSuccessfully(arr);
178 template <
class T,
class Integral,
class... Args>
179 typename std::enable_if<std::is_integral<Integral>::value,
ArrayPtr<T>>::type
MakeArray(Integral size, Args&&... args)
181 System::Details::MakeObjectLeakageDetector::SignatureBacktraceSentry signature_sentry;
182 System::Details::MakeObjectLeakageDetector::SetSignature<Array<T>>(Details::FixArraySize(size), std::forward<Args>(args)...);
184 Detail::OwnNextObject ownershipSentry;
186 Array<T>*
const arr =
new Array<T>(Details::FixArraySize(size), std::forward<Args>(args)...);
188 ownershipSentry.CreatedSuccessfully(arr);
189 signature_sentry.CreatedSuccessfully(arr);
263 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
264 RTTI_INFO_TEMPLATE_CLASS(
ThisType, ThisTypeBaseTypesInfo);
274 typedef System::Details::CollectionHelpers::ContainerPointerMode<UnderlyingType>
pointer_mode_t;
276 typedef std::vector<UnderlyingType, typename pointer_mode_t::allocator_type>
vector_t;
281#ifdef ASPOSE_GET_SHARED_MEMBERS
282 DEFINE_GET_SHARED_MEMBERS(m_data)
315 return (m_idx < 0 || m_idx >= (int64_t)m_array->
m_data.size())
316 ? System::Default<T>()
317 : m_array->
m_data[(size_t)m_idx];
325 if (m_idx < (int64_t)m_array->
m_data.size())
328 return m_idx < (int64_t)m_array->
m_data.size();
337#ifdef __DBG_FOR_EACH_MEMBER
341 void DBG_for_each_member(DBG::for_each_member_visitor &visitor)
const override
343 visitor.add_self(
this);
344 visitor.add_member(
this, m_array.
get_shared(),
"m_array");
348 const char* DBG_class_name()
const override {
return "Array<T>::Enumerator"; }
352#ifdef ASPOSE_GET_SHARED_MEMBERS
354 virtual void GetSharedMembers(System::Object::shared_members_type& result)
const override
356 Object::GetSharedMembers(result);
357 result.Add(
"System::Array<T>::Enumerator::m_array", m_array);
363 Array() : m_data(m_pointer_mode.GetAllocator()) {}
368 Array(
int count,
const T& init = T()) : m_data(count, static_cast<
UnderlyingType>(init), m_pointer_mode.GetAllocator()) { }
374 template <
typename ValueType>
375 Array(
typename std::enable_if<std::is_arithmetic<T>::value && std::is_arithmetic<ValueType>::value && std::is_convertible<ValueType, T>::value,
int>::type count,
ValueType init)
376 :
Array(count, ASPOSECPP_CHECKED_CAST(T, init)) {}
381 Array(
int count,
const T inits[]) : m_data(count, static_cast<
UnderlyingType>(T()), m_pointer_mode.GetAllocator())
383 for (
int i = 0; i < count; ++i)
384 m_data[i] = inits[i];
389 Array(
vector_t&& value) : m_data(std::move(value), m_pointer_mode.GetAllocator()) {}
393 Array(
const vector_t &assgn) : m_data(assgn, m_pointer_mode.GetAllocator()) {}
399 template <typename Q, typename = typename std::enable_if<std::is_same<Q, T>::value && !std::is_same<std::vector<Q>, vector_t>::value, std::vector<Q>>::type>
401 : m_data(value.begin(), value.end(), m_pointer_mode.GetAllocator())
408 template <typename Q, typename = typename std::enable_if<std::is_same<Q, T>::value && !std::is_same<std::vector<Q>, vector_t>::value, std::vector<Q>>::type>
410 : m_data(m_pointer_mode.GetAllocator())
417 Array(std::initializer_list<UnderlyingType> init) : m_data(init, m_pointer_mode.GetAllocator()) {}
422 template <std::
size_t InitArraySize>
423 Array(
const std::array<UnderlyingType, InitArraySize> &init) :
424 Array(init, static_cast<std::make_index_sequence<InitArraySize>*>(nullptr))
429 Array(std::initializer_list<bool> init,
int = 0) : m_data(m_pointer_mode.GetAllocator())
431 for (
auto it = init.begin(); it != init.end(); ++it)
441 return MakeObject<Enumerator>(std::move(
MakeSharedPtr(
this)));
457 virtual void Add(
const T&)
override
459 throw NotSupportedException(u
"Array as ICollection<T>::Add");
466 throw NotSupportedException(u
"Array as ICollection<T>::Clear");
473 m_pointer_mode.SetWeak(argument, m_data);
481 template <
typename Q = T>
482 auto ContainsImpl(
const Q* item)
const ->
decltype(std::declval<UnderlyingType>() == *item, void(0), bool())
484 return std::find_if(m_data.begin(), m_data.end(),
485 [&item](
const T& value) { return Details::AreEqual(value, *item); }) != m_data.end();
490 bool ContainsImpl(...)
const
492 throw NotImplementedException(ASPOSE_CURRENT_FUNCTION);
498 virtual bool Contains(
const T& item)
const override
500 return ContainsImpl(&item);
507 throw NotSupportedException(u
"Array as ICollection<T>::Remove");
526 this->CopyTo<T>(arr,
static_cast<int64_t
>(arrayIndex));
533 template <std::size_t ...InitArrayIndexes>
534 Array(
const std::array<UnderlyingType,
sizeof...(InitArrayIndexes)> &init, std::index_sequence<InitArrayIndexes...>*) :
535 m_data({ init[InitArrayIndexes]... }, m_pointer_mode.GetAllocator()) {}
542 template <
typename Q = T>
543 auto IndexOfImpl(
const Q* item)
const ->
decltype(std::declval<UnderlyingType>() == *item, void(0), int())
545 auto it = std::find_if(m_data.begin(), m_data.end(), [&item](
const T& value) { return Details::AreEqual(value, *item); });
547 return (it != m_data.end()) ?
static_cast<int>(it - m_data.begin()) : -1;
552 int IndexOfImpl(...)
const
554 throw NotImplementedException(ASPOSE_CURRENT_FUNCTION);
561 virtual int IndexOf(
const T& item)
const override
563 return IndexOfImpl(&item);
568 virtual void Insert(
int,
const T&)
override
570 throw NotSupportedException(u
"Array as IList<T>::Insert");
577 throw NotSupportedException(u
"Array as IList<T>::RemoveAt");
585 return operator[](index);
591 virtual void idx_set(
int index, T value)
override
593 operator[](index) = value;
603 for (
size_t i = 0; i < m_data.size(); ++i)
604 m_data[i] = inits[i];
612 for (
size_t i = 0; i < m_data.size(); ++i)
621 using namespace Collections::Generic::Details;
622 if (IsOutOfBounds(index, m_data)) {
623 throw ArgumentOutOfRangeException(u
"index");
625 return m_data[
static_cast<typename vector_t::size_type
>(index)];
633 using namespace Collections::Generic::Details;
634 if (IsOutOfBounds(index, m_data)) {
635 throw ArgumentOutOfRangeException(u
"index");
637 return m_data[
static_cast<typename vector_t::size_type
>(index)];
645 System::ArrayPtr<T> clone = System::MakeObject< System::Array<T> >(
static_cast<int>(m_data.size()));
646 std::copy(m_data.begin(), m_data.end(), clone->data().
begin());
661 template<
typename Y,
typename Z>
664 throw NotImplementedException();
672 return static_cast<int>(GetLongLength(dimension));
680 return upper_bound(m_data, dimension) + 1;
688 ASPOSE_UNUSED(dimension);
697 return upper_bound(m_data, dimension);
706 template <
typename InputType,
typename OutputType>
711 throw System::ArgumentNullException(u
"arr");
714 if (converter.IsNull())
716 throw System::ArgumentNullException(u
"converter");
720 for (
int i = 0; i < input_array->get_Length(); i++)
722 newArray[i] = converter(input_array[i]);
733 template <
typename InputType,
typename OutputType>
745 if (!arr || match.IsNull())
747 throw System::ArgumentNullException(u
"arr or match");
750 for (
int i = 0; i < arr->get_Length(); i++)
764 if (!arr || match.IsNull())
766 throw System::ArgumentNullException(u
"arr or match");
769 for (
auto val: arr->
m_data)
781 if (!arr || match.IsNull())
783 throw System::ArgumentNullException(u
"arr or match");
788 for (
auto val : arr->
m_data)
790 result->data().push_back(val);
801 if (!arr || match.IsNull())
803 throw System::ArgumentNullException(u
"arr or match");
805 for (
auto val : arr->
m_data)
812 int32_t
get_Rank()
const {
throw System::NotImplementedException(ASPOSE_CURRENT_FUNCTION); };
819 const int64_t len64 = get_LongLength();
821 if (len64 > (std::numeric_limits<int32_t>::max)()) {
822 throw OverflowException();
824 return static_cast<int32_t
>(len64);
831 return GetSizeTLength();
838 return recursive_size(m_data);
843 int Count()
const {
return get_Length(); }
850 template<
typename DstType>
853 this->CopyTo(dstArray, 0, dstIndex, GetSizeTLength());
861 template<
typename DstType>
862 void CopyTo(
const System::Details::ArrayView<DstType> &dstArray, int64_t dstIndex)
const
864 this->CopyTo(dstArray, 0, dstIndex, GetSizeTLength());
875 template<
typename DstType>
878 using namespace Collections::Generic::Details;
881 throw ArgumentNullException(u
"dstArray");
883 if (srcIndex < 0 || dstIndex < 0 || count < 0) {
884 throw ArgumentOutOfRangeException(u
"srcIndex, dstIndex or count");
886 if (IsOutOfSize(srcIndex + count, m_data)
887 || IsOutOfSize(dstIndex + count, dstArray->data())) {
888 throw ArgumentException(u
"srcIndex, dstIndex or count");
893 if (dstArray.
GetObjectOrNull() == (
Object*)(
this) && dstIndex > srcIndex && dstIndex < srcIndex + count)
896 m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex)
897 , m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex) + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, count)
898 , dstArray->data().
begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, dstIndex) + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, count)
904 m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex)
905 , m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex) + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, count)
906 , dstArray->data().
begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, dstIndex)
919 template<
typename DstType>
920 void CopyTo(
const System::Details::ArrayView<DstType> &dstArray, int64_t srcIndex, int64_t dstIndex, int64_t count)
const
922 using namespace Collections::Generic::Details;
925 throw ArgumentNullException(u
"dstArray");
927 if (srcIndex < 0 || dstIndex < 0 || count < 0) {
928 throw ArgumentOutOfRangeException(u
"srcIndex, dstIndex or count");
930 if (IsOutOfSize(srcIndex + count, m_data)
931 || dstIndex + count > dstArray.get_Length()) {
932 throw ArgumentException(u
"srcIndex, dstIndex or count");
935 if (dstArray.data() == this->data().data()
936 && dstIndex > srcIndex && dstIndex < srcIndex + count)
939 m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex)
940 , m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex) + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, count)
941 , dstArray.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, dstIndex) + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, count)
947 m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex)
948 , m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex) + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, count)
949 , dstArray.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, dstIndex)
960 throw ArgumentNullException(u
"action");
962 for (
auto val : arr->
m_data)
972 template<
typename ArrayType,
typename ValueType>
975 return IndexOf(arr, value, 0);
985 template<
typename ArrayType,
typename ValueType>
988 return IndexOf(arr, value, startIndex, arr->get_Length() - startIndex);
999 template<
typename ArrayType,
typename ValueType>
1002 using namespace Collections::Generic::Details;
1004 throw ArgumentNullException(u
"arr");
1006 if (startIndex < 0 || count < 0 || IsOutOfSize(startIndex + count, arr->data())) {
1007 throw ArgumentOutOfRangeException(u
"startIndex or count");
1010 auto begin = arr->data().
begin() + startIndex;
1011 auto end = begin + count;
1013 std::find_if(begin, end, [&value](
const ArrayType& item) {
return Details::AreEqual(item, value); });
1015 return (it != end) ?
static_cast<int>(it - arr->data().
begin()) : -1;
1026 template<
typename ArrayType,
typename ValueType>
1029 using namespace Collections::Generic::Details;
1031 throw ArgumentNullException(u
"arr");
1033 if (startIndex < 0 || count < 0
1034 || IsOutOfSize(startIndex, arr->data()) || IsOutOfSize(count, arr->data())
1035 || (startIndex - count + 1) < 0) {
1036 throw ArgumentOutOfRangeException(u
"startIndex or count");
1038 auto rbegin = arr->data().rbegin() + arr->data().size() - startIndex - 1;
1039 auto rend = rbegin + count;
1040 auto rit = std::find_if(rbegin, rend, [&value](
const ArrayType& item) {
return Details::AreEqual(item, value); });
1042 return (rit != rend) ? ASPOSECPP_CHECKED_CAST(
int, rit.base() - arr->data().
begin() - 1) : -1;
1052 template<
typename ArrayType,
typename ValueType>
1055 return LastIndexOf(items, value, startIndex, (items->get_Length() == 0) ? 0 : startIndex + 1);
1064 template<
typename ArrayType,
typename ValueType>
1067 return LastIndexOf(items, value, items->get_Length() - 1, items->get_Length());
1075 template<
typename Type>
1078 using namespace Collections::Generic::Details;
1080 throw ArgumentNullException(u
"arr");
1082 if (startIndex < 0 || count < 0 || IsOutOfSize(startIndex + count, arr->data())) {
1083 throw ArgumentOutOfRangeException(u
"startIndex or count");
1086 for (
auto i = 0; i < count; ++i)
1087 arr->data().at(startIndex + i) = Type();
1101 template <
typename SrcType,
typename DstType>
1106 throw ArgumentNullException(u
"srcArray");
1108 srcArray->CopyTo(dstArray, srcIndex, dstIndex, count);
1115 template<
typename SrcType,
typename DstType>
1120 throw ArgumentNullException(u
"srcArray");
1122 srcArray->CopyTo(dstArray, 0, 0, count);
1129 template<
typename SrcType,
typename DstType>
1130 static void Copy(System::Details::ArrayView<SrcType> srcArray,
1134 throw ArgumentNullException(u
"srcArray");
1136 srcArray.CopyTo(dstArray, 0, 0, count);
1143 template<
typename SrcType,
typename DstType>
1145 System::Details::ArrayView<DstType> dstArray, int64_t count)
1148 throw ArgumentNullException(u
"srcArray");
1150 srcArray->CopyTo(dstArray, 0, 0, count);
1157 template<
typename SrcType,
typename DstType>
1158 static void Copy(System::Details::ArrayView<SrcType> srcArray,
1159 System::Details::ArrayView<DstType> dstArray, int64_t count)
1162 throw ArgumentNullException(u
"srcArray");
1164 srcArray.CopyTo(dstArray, 0, 0, count);
1171 template<
typename SrcType, std::
size_t N,
typename DstType>
1172 static void Copy(System::Details::StackArray<SrcType, N> &srcArray,
1175 Copy(
static_cast<System::Details::ArrayView<SrcType>
>(srcArray), dstArray, count);
1182 template<
typename SrcType,
typename DstType, std::
size_t N>
1184 System::Details::StackArray<DstType, N> &dstArray, int64_t count)
1186 Copy(srcArray,
static_cast<System::Details::ArrayView<DstType>
>(dstArray), count);
1193 template<
typename SrcType, std::
size_t NS,
typename DstType, std::
size_t ND>
1194 static void Copy(System::Details::StackArray<SrcType, NS> &srcArray,
1195 System::Details::StackArray<DstType, ND> &dstArray, int64_t count)
1197 Copy(
static_cast<System::Details::ArrayView<SrcType>
>(srcArray),
1198 static_cast<System::Details::ArrayView<DstType>
>(dstArray), count);
1209 template<
typename SrcType,
typename DstType>
1214 throw ArgumentNullException(u
"srcArray");
1216 srcArray->CopyTo(dstArray, srcIndex, dstIndex, count);
1227 template<
typename SrcType,
typename DstType>
1228 static void Copy(System::Details::ArrayView<SrcType> srcArray, int64_t srcIndex,
1232 throw ArgumentNullException(u
"srcArray");
1234 srcArray.CopyTo(dstArray, srcIndex, dstIndex, count);
1245 template<
typename SrcType,
typename DstType>
1247 System::Details::ArrayView<DstType> dstArray, int64_t dstIndex, int64_t count)
1250 throw ArgumentNullException(u
"srcArray");
1252 srcArray->CopyTo(dstArray, srcIndex, dstIndex, count);
1263 template<
typename SrcType,
typename DstType>
1264 static void Copy(System::Details::ArrayView<SrcType> srcArray, int64_t srcIndex,
1265 System::Details::ArrayView<DstType> dstArray, int64_t dstIndex, int64_t count)
1268 throw ArgumentNullException(u
"srcArray");
1270 srcArray.CopyTo(dstArray, srcIndex, dstIndex, count);
1281 template<
typename SrcType, std::
size_t N,
typename DstType>
1282 static void Copy(System::Details::StackArray<SrcType, N> &srcArray, int64_t srcIndex,
1285 Copy(
static_cast<System::Details::ArrayView<SrcType>
>(srcArray), srcIndex, dstArray, dstIndex, count);
1296 template<
typename SrcType,
typename DstType, std::
size_t N>
1298 System::Details::StackArray<DstType, N> &dstArray, int64_t dstIndex, int64_t count)
1300 Copy(srcArray, srcIndex,
static_cast<System::Details::ArrayView<DstType>
>(dstArray), dstIndex, count);
1311 template<
typename SrcType, std::
size_t NS,
typename DstType, std::
size_t ND>
1312 static void Copy(System::Details::StackArray<SrcType, NS> &srcArray, int64_t srcIndex,
1313 System::Details::StackArray<DstType, ND> &dstArray, int64_t dstIndex, int64_t count)
1315 Copy(
static_cast<System::Details::ArrayView<SrcType>
>(srcArray), srcIndex,
1316 static_cast<System::Details::ArrayView<DstType>
>(dstArray), dstIndex, count);
1327 template<
typename SrcType,
typename DstType, std::
size_t ND>
1328 static void Copy(System::Details::ArrayView<SrcType> &srcArray, int64_t srcIndex,
1329 System::Details::StackArray<DstType, ND> &dstArray, int64_t dstIndex, int64_t count)
1331 Copy(srcArray, srcIndex,
1332 static_cast<System::Details::ArrayView<DstType>
>(dstArray), dstIndex, count);
1337 template<
typename Type>
1340 Sort(arr, 0, arr->get_Length());
1347 template<
typename Type>
1350 using namespace Collections::Generic::Details;
1352 throw ArgumentNullException(u
"arr");
1354 if (startIndex < 0 || count < 0 || IsOutOfSize(startIndex + count, arr->data())) {
1355 throw ArgumentOutOfRangeException(u
"startIndex or count");
1358 auto begin = arr->data().
begin() + startIndex;
1359 auto end = begin + count;
1361 std::sort(begin, end, Collections::Generic::Details::ComparerType<Type>());
1367 template<
typename Type>
1371 std::sort(arr->data().
begin(), arr->data().
end(), adapter);
1376 template<
typename Type,
typename Y>
1379 throw NotImplementedException();
1388 template<
typename TKey,
typename TValue>
1391 if (keys ==
nullptr)
1392 throw ArgumentNullException(u
"keys");
1394 Sort(keys, items, 0, keys->get_Length());
1405 template<
typename TKey,
typename TValue>
1408 if (keys ==
nullptr)
1409 throw ArgumentNullException(u
"keys");
1410 if (index < 0 || length < 0)
1411 throw ArgumentOutOfRangeException(length < 0 ? u
"length" : u
"index");
1412 if (index + length > keys->Count() || (items !=
nullptr && index + length > items->Count()))
1413 throw ArgumentException();
1415 if (items ==
nullptr)
1417 typename std::vector<TKey>::iterator keys_begin = keys->data().
begin() + index;
1418 typename std::vector<TKey>::iterator keys_end = keys_begin + length;
1420 std::sort(keys_begin, keys_end, Collections::Generic::Details::ComparerType<TKey>());
1425 std::multimap<TKey, TValue, Collections::Generic::Details::ComparerType<TKey>> map;
1426 for (
int i = index; i < index + length; ++i)
1427 map.insert(std::make_pair(keys[i], items[i]));
1429 auto map_iter = map.begin();
1430 for (
int i = index; (i < index + length) && (map_iter != map.end()); ++i, ++map_iter)
1432 keys[i] = map_iter->first;
1433 items[i] = map_iter->second;
1440 template<
typename Type>
1450 template<
typename Type>
1453 using namespace Collections::Generic::Details;
1455 throw ArgumentNullException(u
"arr");
1457 if (startIndex < 0 || count < 0 || IsOutOfSize(startIndex + count, arr->data())) {
1458 throw ArgumentOutOfRangeException(u
"startIndex or count");
1461 std::reverse(arr->
m_data.begin() + startIndex, arr->
m_data.begin() + startIndex + count);
1467 template<
typename Type>
1471 throw ArgumentOutOfRangeException(u
"new_size");
1474 arr->
m_data.resize((
typename vector_t::size_type)new_size);
1476 arr = MakeObject<Array<T>>(new_size);
1484 using namespace Collections::Generic::Details;
1485 if (IsOutOfBounds(index, m_data)) {
1486 throw ArgumentOutOfRangeException(u
"index");
1488 m_data[index] = value;
1523 return m_data.begin();
1531 return m_data.begin();
1539 return m_data.cbegin();
1547 return m_data.end();
1555 return m_data.end();
1563 return m_data.cend();
1572 return m_data.rbegin();
1581 return m_data.rbegin();
1590 return m_data.crbegin();
1599 return m_data.rend();
1608 return m_data.rend();
1617 return m_data.crend();
1637 return *std::min_element(m_data.cbegin(), m_data.cend());
1644 return *std::max_element(m_data.cbegin(), m_data.cend());
1653 for (
int i = 0; i < arr->get_Length(); i++)
1664 return new System::Details::NativeIteratorWrapper<T, iterator>(begin(), end());
1669 return new System::Details::NativeIteratorWrapper<T, iterator>(end(), end());
1674 return new System::Details::NativeConstIteratorWrapper<T, const_iterator>(begin(), end());
1679 return new System::Details::NativeConstIteratorWrapper<T, const_iterator>(end(), end());
1688 template <
typename ErrType>
1689 static int upper_bound(ErrType arr,
int dim)
1693 throw System::IndexOutOfRangeException();
1701 template <
typename VType,
typename Alloc>
1702 static int upper_bound(
const std::vector<VType, Alloc> &arr,
int dim)
1705 return (
int)arr.size() - 1;
1710 return upper_bound(arr[0], dim - 1);
1718 template <
typename U,
typename Alloc>
1719 static size_t recursive_size(
const std::vector<U, Alloc>& v)
1731 template <
typename U,
typename Alloc1,
typename Alloc2>
1732 static size_t recursive_size(
const std::vector<std::vector<U, Alloc1>, Alloc2>& v)
1735 for (
const auto &i : v)
1736 rv += recursive_size(i);
1745#ifdef __DBG_FOR_EACH_MEMBER
1749 void DBG_for_each_member(DBG::for_each_member_visitor &visitor)
const override
1751 visitor.add_self(
this);
1752 DBG::for_each_of_Object(
this, m_data, visitor);
1755 const char* DBG_class_name()
const override {
return "Array<T>"; }
1760 template <
typename TTo>
1761 struct CastResult<
Array<TTo>>
1764 typedef ArrayPtr<TTo>
type;
1773 template <
typename T>
1774 inline Array<T>* CreateArray(Array<T>*)
1776 return new Array<T>(0);
Implements IEnumerator interface that enables enumeration of elements of an Array object....
Definition: array.h:295
virtual ~Enumerator()
Destructor.
Definition: array.h:310
Enumerator(const SharedPtr< Array< T > > &arr)
Constructs a new Enumerator object that represents the specified array.
Definition: array.h:307
virtual MakeConstRef_t< T > get_Current() const override
Returns a copy of the current element.
Definition: array.h:313
virtual bool MoveNext() override
Checks if the current element's index does not point to the last element in the array and advances it...
Definition: array.h:323
virtual void Reset() override
Resets the current element's index.
Definition: array.h:332
Class that represents an array data structure. Objects of this class should only be allocated using S...
Definition: array.h:259
static System::ArrayPtr< T > FindAll(System::ArrayPtr< T > arr, System::Predicate< T > match)
Retrieves all the elements that match the conditions defined by the specified predicate.
Definition: array.h:779
static void Clear(const ArrayPtr< Type > &arr, int startIndex, int count)
Replaces count values starting at the startIndex index in the specified array with default values.
Definition: array.h:1076
static ArrayPtr< OutputType > ConvertAll(ArrayPtr< InputType > input_array, std::function< OutputType(InputType)> converter)
Constructs a new Array object and fills it with elements of the specified array converted to OutputTy...
Definition: array.h:734
const_reverse_iterator crbegin() const noexcept
Returns a reverse iterator to the first element of the reversed container. It corresponds to the last...
Definition: array.h:1588
static int IndexOf(const ArrayPtr< ArrayType > &arr, const ValueType &value)
Determines the index of the first occurrence of specified item in the array.
Definition: array.h:973
void SetValue(const T &value, int index)
Sets value of the element at specified index.
Definition: array.h:1482
SharedPtr< Collections::Generic::IEnumerator< T > > EnumeratorPtr
An alias for shared pointer type pointing to IEnumerator object containing elements of type T.
Definition: array.h:288
static void ConstrainedCopy(const ArrayPtr< SrcType > &srcArray, int64_t srcIndex, const ArrayPtr< DstType > &dstArray, int64_t dstIndex, int64_t count)
Copies a range of elements from an System.Array starting at the specified source.
Definition: array.h:1102
vector_t::iterator iterator
Iterator type.
Definition: array.h:1510
static void Sort(const ArrayPtr< Type > &arr, const SharedPtr< System::Collections::Generic::IComparer< T > > &comparator)
Sorts elements in the specified array using specified comparer.
Definition: array.h:1368
reverse_iterator rbegin() noexcept
Returns a reverse iterator to the first element of the reversed container. It corresponds to the last...
Definition: array.h:1570
UnderlyingType Min() const
Finds the smallest element in the array using operator<() to compare elements.
Definition: array.h:1635
Array(std::vector< Q > &&value)
Constructs an Array object and fills it with values moved from an std::vector object whose values' ty...
Definition: array.h:409
virtual bool Contains(const T &item) const override
Determines if the specified item is in the array.
Definition: array.h:498
vector_t::const_reverse_iterator const_reverse_iterator
Const reverse iterator type.
Definition: array.h:1516
const UnderlyingType * data_ptr() const
Returns a constant raw pointer to the beginning of the memory buffer where the array elements are sto...
Definition: array.h:1507
~Array() override
Destructor.
Definition: array.h:1743
virtual void Clear() override
Not supported because the array represented by the current object is read-only.
Definition: array.h:464
static void Copy(System::Details::ArrayView< SrcType > srcArray, int64_t srcIndex, System::Details::ArrayView< DstType > dstArray, int64_t dstIndex, int64_t count)
Copies a specified number of elements from the source array view starting at the specified index to t...
Definition: array.h:1264
iterator begin() noexcept
Returns an iterator to the first element of the container. If the container is empty,...
Definition: array.h:1521
virtual int IndexOf(const T &item) const override
Determines the index of the first occurrence of the specified item in the array.
Definition: array.h:561
static void Sort(const ArrayPtr< Type > &arr, const SharedPtr< System::Collections::Generic::IComparer< Y > > &comparator)
NOT IMPLEMENTED.
Definition: array.h:1377
vector_t m_data
The storage for array's elements.
Definition: array.h:280
static T Find(System::ArrayPtr< T > arr, System::Predicate< T > match)
Searches for the first element in the specified array that satisfies the conditions of the specified ...
Definition: array.h:762
ArrayPtr< T > Init(const T inits[])
Fills the array represented by the current object with the values from the specified array.
Definition: array.h:601
static void Sort(const ArrayPtr< TKey > &keys, const ArrayPtr< TValue > &items, int index, int length)
Sorts two arrays one containing keys and the other - corresponding items, based on the values of arra...
Definition: array.h:1406
int GetLength(int dimension)
Returns the number of elements in the specified dimension.
Definition: array.h:670
virtual EnumeratorPtr GetEnumerator() override
Returns a pointer to Enumerator object that provides IEnumerator interface to elements of the array r...
Definition: array.h:439
Array(vector_t &&value)
Move constructor.
Definition: array.h:389
vector_t::pointer data_ptr()
Returns a raw pointer to the beginning of the memory buffer where the array elements are stored.
Definition: array.h:1498
static void Reverse(const ArrayPtr< Type > &arr)
Reverses elements in the specified array.
Definition: array.h:1441
static void Copy(System::Details::StackArray< SrcType, NS > &srcArray, int64_t srcIndex, System::Details::StackArray< DstType, ND > &dstArray, int64_t dstIndex, int64_t count)
Copies a specified number of elements from the source array on stack starting at the specified index ...
Definition: array.h:1312
const vector_t & data() const
Returns a constant reference to the internal data structure used to store the array elements.
Definition: array.h:1495
static void Copy(System::Details::ArrayView< SrcType > &srcArray, int64_t srcIndex, System::Details::StackArray< DstType, ND > &dstArray, int64_t dstIndex, int64_t count)
Copies a specified number of elements from the source array view starting at the specified index to t...
Definition: array.h:1328
Array(std::initializer_list< bool > init, int=0)
Constructs an Array object and fills it with values from the specified initializer list containing el...
Definition: array.h:429
static int IndexOf(const ArrayPtr< ArrayType > &arr, const ValueType &value, int startIndex, int count)
Determines the index of the first occurrence of the specified item in a range of items of the array s...
Definition: array.h:1000
static void Copy(const ArrayPtr< SrcType > &srcArray, System::Details::ArrayView< DstType > dstArray, int64_t count)
Copies the specified number of elements from the source array to the destination array view.
Definition: array.h:1144
SharedPtr< Collections::Generic::IEnumerable< T > > EnumerablePtr
An alias for shared pointer type pointing to IEnumerable object containing elements of type T.
Definition: array.h:286
Array(const std::vector< Q > &value)
Constructs an Array object and fills it with values copied from an std::vector object whose values' t...
Definition: array.h:400
System::Details::CollectionHelpers::ContainerPointerMode< UnderlyingType > pointer_mode_t
Type to keep information on whether to treat array elements as shared or weak pointers,...
Definition: array.h:274
void CopyTo(const ArrayPtr< DstType > &dstArray, int64_t srcIndex, int64_t dstIndex, int64_t count) const
Copies a specified number of elements from the current array starting at specified position to specif...
Definition: array.h:876
System::Details::VirtualizedIteratorBase< T > * virtualizeEndConstIterator() const override
Gets the implementation of end const iterator for the current container.
Definition: array.h:1677
ArrayPtr< T > Clone()
Clones the array.
Definition: array.h:643
virtual void Add(const T &) override
Not supported because the array represented by the current object is read-only.
Definition: array.h:457
vector_t & data()
Returns a reference to the internal data structure used to store the array elements.
Definition: array.h:1492
void CopyTo(const ArrayPtr< DstType > &dstArray, int64_t dstIndex) const
Copies all elements of the current array to the specified destination array. Elements are inserted in...
Definition: array.h:851
void CopyTo(const System::Details::ArrayView< DstType > &dstArray, int64_t dstIndex) const
Copies all elements of the current array to the specified destination array view. Elements are insert...
Definition: array.h:862
void CopyTo(const System::Details::ArrayView< DstType > &dstArray, int64_t srcIndex, int64_t dstIndex, int64_t count) const
Copies a specified number of elements from the current array starting at specified position to specif...
Definition: array.h:920
virtual bool Remove(const T &) override
Not supported because the array represented by the current object is read-only.
Definition: array.h:505
const_reverse_iterator rend() const noexcept
Returns a reverse iterator to the element following the last element of the reversed container....
Definition: array.h:1606
Array(const vector_t &assgn)
Copy constructor.
Definition: array.h:393
iterator end() noexcept
Returns an iterator to the element following the last element of the container. This element acts as ...
Definition: array.h:1545
static int BinarySearch(System::ArrayPtr< T > arr, const T &item)
Performs binary search in the sorted array.
Definition: array.h:654
UnderlyingType Max() const
Finds the largest element in the array using operator<() to compare elements.
Definition: array.h:1642
int32_t get_Rank() const
NOT IMPLEMENTED.
Definition: array.h:812
const_iterator end() const noexcept
Returns an iterator to the element following the last element of the const-qualified container....
Definition: array.h:1553
static ArrayPtr< OutputType > ConvertAll(ArrayPtr< InputType > input_array, Converter< InputType, OutputType > converter)
Constructs a new Array object and fills it with elements of the specified array converted to OutputTy...
Definition: array.h:707
static int IndexOf(const ArrayPtr< ArrayType > &arr, const ValueType &value, int startIndex)
Determines the index of the first occurrence of the specified item in the array starting from the spe...
Definition: array.h:986
static bool Exists(ArrayPtr< T > arr, std::function< bool(T)> match)
Determines if the specified Array object contains an element that satisfies requirements of the speci...
Definition: array.h:1651
T ValueType
Alias for the type of the elements of the array.
Definition: array.h:268
static void Copy(System::Details::ArrayView< SrcType > srcArray, System::Details::ArrayView< DstType > dstArray, int64_t count)
Copies the specified number of elements from the source array view to the destination array view.
Definition: array.h:1158
static bool TrueForAll(System::ArrayPtr< T > arr, System::Predicate< T > match)
Determines whether all elements in the specified array satisfy the conditions defined by specified pr...
Definition: array.h:799
static int FindIndex(System::ArrayPtr< T > arr, System::Predicate< T > match)
Searches for the first element in the specified array that satisfies the conditions of the specified ...
Definition: array.h:743
static int LastIndexOf(const ArrayPtr< ArrayType > &arr, const ValueType &value, int startIndex, int count)
Determines the index of the last occurrence of the specified item in a range of items of the array sp...
Definition: array.h:1027
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:1116
vector_t::reverse_iterator reverse_iterator
Reverse iterator type.
Definition: array.h:1514
Array(int count, const T &init=T())
Filling constructor.
Definition: array.h:368
int64_t get_LongLength() const
Returns 64-bit integer that represents the total number of all elements in all dimensions of the arra...
Definition: array.h:829
static void Copy(System::Details::StackArray< SrcType, NS > &srcArray, System::Details::StackArray< DstType, ND > &dstArray, int64_t count)
Copies the specified number of elements from the source array on stack to the destination array on st...
Definition: array.h:1194
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginConstIterator() const override
Gets the implementation of begin const iterator for the current container.
Definition: array.h:1672
UnderlyingType const & operator[](int index) const
Returns an item at the specified index.
Definition: array.h:631
virtual void CopyTo(ArrayPtr< T > arr, int arrayIndex) override
Copies all elements of the current array to the specified destination array. Elements are inserted in...
Definition: array.h:524
virtual bool get_IsReadOnly() const override
Indicates whether the array is read-only.
Definition: array.h:515
static void Sort(const ArrayPtr< TKey > &keys, const ArrayPtr< TValue > &items)
Sorts two arrays one containing keys and the other - corresponding items, based on the values of arra...
Definition: array.h:1389
void Initialize()
Fills the array with the default constructed objects of type T.
Definition: array.h:610
Array(int count, const T inits[])
Filling constructor.
Definition: array.h:381
virtual T idx_get(int index) const override
Returns the item at the specified index.
Definition: array.h:583
int GetLowerBound(int dimension) const
Returns the lower bound of the specified dimension.
Definition: array.h:686
System::Details::VirtualizedIteratorBase< T > * virtualizeEndIterator() override
Gets the implementation of end iterator for the current container.
Definition: array.h:1667
static void ForEach(const ArrayPtr< T > &arr, System::Action< T > action)
Performs specified action on each element of the specified array.
Definition: array.h:957
int64_t GetLongLength(int dimension)
Returns the number of elements in the specified dimension as 64-bit integer.
Definition: array.h:678
static void Copy(System::Details::StackArray< SrcType, N > &srcArray, int64_t srcIndex, const ArrayPtr< DstType > &dstArray, int64_t dstIndex, int64_t count)
Copies a specified number of elements from the source array on stack starting at the specified index ...
Definition: array.h:1282
static int BinarySearch(System::ArrayPtr< T > arr, const Y &item, const SharedPtr< Collections::Generic::IComparer< Z > > &comparer)
NOT IMPLEMENTED.
Definition: array.h:662
static int LastIndexOf(const ArrayPtr< ArrayType > &items, const ValueType &value, int startIndex)
Determines the index of the last occurrence of the specified item in the array starting from the spec...
Definition: array.h:1053
static void Copy(const ArrayPtr< SrcType > &srcArray, System::Details::StackArray< DstType, N > &dstArray, int64_t count)
Copies the specified number of elements from the source array to the destination array on stack.
Definition: array.h:1183
virtual int get_Count() const override
Returns the size of the array.
Definition: array.h:450
typename System::Details::SelectType< T >::type UnderlyingType
Alias for the type used to represent each element of the array.
Definition: array.h:270
static void Sort(const ArrayPtr< Type > &arr)
Sorts elements in the specified array using default comparer.
Definition: array.h:1338
virtual void RemoveAt(int) override
Not supported because array represented by the current object is read-only.
Definition: array.h:575
virtual void idx_set(int index, T value) override
Sets the specified value as the item of the array at the specified index.
Definition: array.h:591
const_iterator cbegin() const noexcept
Returns an iterator to the first const-qualified element of the container. If the container is empty,...
Definition: array.h:1537
static void Copy(System::Details::ArrayView< SrcType > srcArray, const ArrayPtr< DstType > &dstArray, int64_t count)
Copies the specified number of elements from the source array view to the destination array.
Definition: array.h:1130
Array(const std::array< UnderlyingType, InitArraySize > &init)
Constructs an Array object and fills it with values from the specified array containing elements of U...
Definition: array.h:423
size_t GetSizeTLength() const
Returns an std::size_t variable that represents the total number of all elements in all dimensions of...
Definition: array.h:836
static void Resize(ArrayPtr< Type > &arr, int new_size)
Changes the size of the specified array to the specified value or crates new array with specified siz...
Definition: array.h:1468
static void Copy(System::Details::StackArray< SrcType, N > &srcArray, const ArrayPtr< DstType > &dstArray, int64_t count)
Copies the specified number of elements from the source array on stack to the destination array.
Definition: array.h:1172
static void Copy(const ArrayPtr< SrcType > &srcArray, int64_t srcIndex, System::Details::ArrayView< DstType > dstArray, int64_t dstIndex, int64_t count)
Copies a specified number of elements from the source array starting at the specified index to the sp...
Definition: array.h:1246
const_iterator cend() const noexcept
Returns an iterator to the element following the last element of the container. This element acts as ...
Definition: array.h:1561
static int LastIndexOf(const ArrayPtr< ArrayType > &items, const ValueType &value)
Determines the index of the last occurrence of the specified item in the array.
Definition: array.h:1065
std::vector< UnderlyingType, typename pointer_mode_t::allocator_type > vector_t
An alias for the type used to store the array's elements.
Definition: array.h:276
int GetUpperBound(int dimension)
Returns the upper bound of the specified dimension.
Definition: array.h:695
void SetTemplateWeakPtr(uint32_t argument) override
Makes array treat stored pointers as weak (if applicable).
Definition: array.h:471
const_iterator begin() const noexcept
Returns an iterator to the first element of the const-qualified container. If the container is empty,...
Definition: array.h:1529
virtual void Insert(int, const T &) override
Not supported because array represented by the current object is read-only.
Definition: array.h:568
static void Copy(const ArrayPtr< SrcType > &srcArray, int64_t srcIndex, const ArrayPtr< DstType > &dstArray, int64_t dstIndex, int64_t count)
Copies a specified number of elements from the source array starting at the specified index to the sp...
Definition: array.h:1210
static void Copy(System::Details::ArrayView< SrcType > srcArray, int64_t srcIndex, const ArrayPtr< DstType > &dstArray, int64_t dstIndex, int64_t count)
Copies a specified number of elements from the source array view starting at the specified index to t...
Definition: array.h:1228
const_reverse_iterator crend() const noexcept
Returns a reverse iterator to the element following the last element of the reversed container....
Definition: array.h:1615
static void Sort(const ArrayPtr< Type > &arr, int startIndex, int count)
Sorts a range of elements in the specified array using default comparer.
Definition: array.h:1348
vector_t::const_iterator const_iterator
Const iterator type.
Definition: array.h:1512
pointer_mode_t m_pointer_mode
Information on whether to treat array elements as shared or weak pointers, if applicable.
Definition: array.h:278
Array(typename std::enable_if< std::is_arithmetic< T >::value &&std::is_arithmetic< ValueType >::value &&std::is_convertible< ValueType, T >::value, int >::type count, ValueType init)
Filling constructor.
Definition: array.h:375
int32_t get_Length() const
Returns 32-bit integer that represents the total number of all elements in all dimensions of the arra...
Definition: array.h:816
reverse_iterator rend() noexcept
Returns a reverse iterator to the element following the last element of the reversed container....
Definition: array.h:1597
const_reverse_iterator rbegin() const noexcept
Returns a reverse iterator to the first element of the reversed container. It corresponds to the last...
Definition: array.h:1579
static void Reverse(const ArrayPtr< Type > &arr, int startIndex, int count)
Reverses a range of elements in the specified array.
Definition: array.h:1451
static void Copy(const ArrayPtr< SrcType > &srcArray, int64_t srcIndex, System::Details::StackArray< DstType, N > &dstArray, int64_t dstIndex, int64_t count)
Copies a specified number of elements from the source array starting at the specified index to the sp...
Definition: array.h:1297
Array()
Constructs an empty array.
Definition: array.h:363
Array(std::initializer_list< UnderlyingType > init)
Constructs an Array object and fills it with values from the specified initializer list containing el...
Definition: array.h:417
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginIterator() override
Gets the implementation of begin iterator for the current container.
Definition: array.h:1662
int Count() const
Returns a number that represents the total number of all elements in all dimensions of the array.
Definition: array.h:843
UnderlyingType & operator[](int index)
Returns an item at the specified index.
Definition: array.h:619
Interface that compares two objects in greater-equal-less sense. Objects of this class should only be...
Definition: icomparer.h:20
Interface of enumerator which can be used to iterate through some elements. Objects of this class sho...
Definition: ienumerator.h:63
Interface of indexed container of elements. Objects of this class should only be allocated using Syst...
Definition: ilist.h:19
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
auto end() -> decltype(std::declval< Q >().end())
Accessor for end() method of an underling collection. Only compiles if SmartPtr_ is specialization ty...
Definition: smart_ptr.h:838
auto begin() -> decltype(std::declval< Q >().begin())
Accessor for begin() method of an underling collection. Only compiles if SmartPtr_ is specialization ...
Definition: smart_ptr.h:830
Object * GetObjectOrNull() const
Gets pointed object (if any) or nullptr. Same as get().
Definition: smart_ptr.h:783
Pointee_ * get_shared() const
Gets pointed object, but asserts that pointer is in shared mode.
Definition: smart_ptr.h:524
class System::SmartPtr::Data m_data
An instance of Data class.
int _net_binnary_search(const containterT< T, Allocator > &container, int index, int count, T value, const SharedPtr< System::Collections::Generic::IComparer< T > > &comparer)
Implements binary search in random access container.
Definition: algorithms.h:23
Definition: db_command.h:9
ArrayPtr< T > MakeArray(std::initializer_list< T > init)
A factory function that constructs a new Array object, fills it with the elements from the specified ...
Definition: array.h:138
MulticastDelegate< void(Args...)> Action
Delegate type that references methods that have no return value.
Definition: action.h:40
SmartPtr< X > MakeSharedPtr(X *p)
Converts raw pointer to smart pointer.
Definition: smart_ptr.h:1650
MulticastDelegate< TOutput(TInput)> Converter
Represents a pointer to the invokable entity that accepts a single argument of the TInput type and re...
Definition: converter.h:14
MulticastDelegate< bool(T)> Predicate
Represents a pointer to a predicate - an invokable entity that accepts a single argument and returns ...
Definition: predicate.h:41
typename MakeConstRef< T >::type MakeConstRef_t
Helper type for MakeConstRef modifier.
Definition: make_const_ref.h:20
System::ArrayPtr< uint8_t > ByteArrayPtr
An alias for a smart pointer object that points to an array of unsigned 8-bit integers.
Definition: array.h:107
class ASPOSECPP_SHARED_CLASS Array
Definition: smart_ptr.h:22
SmartPtr< TTo > type
An alias for a pointer to an instance of TTo.
Definition: object.h:387
Adapter to use IComparer within STL environment. Uses IComparer if set; otherwise,...
Definition: icomparer.h:44