CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
array.h
1
3#ifndef _aspose_system_array_h_
4#define _aspose_system_array_h_
5
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>
22#include <system/comparison.h>
23#include <system/collections/read_only_collection.h>
24
25#include <fwd.h>
26
27#include <map>
28#include <vector>
29#include <functional>
30#include <initializer_list>
31#include <utility>
32#include <limits>
33#include <type_traits>
34#include <algorithm>
35
36#undef min
37#undef max
38
39namespace System { namespace Collections { namespace ObjectModel {
40template<typename> class ReadOnlyCollection;
41}}}
42
43namespace System
44{
45 namespace Details {
46 template <typename X, typename IdxType>
47 inline typename Array<X>::UnderlyingType& GetByIndex(const SmartPtr<Array<X>> *ptr, IdxType idx)
48 {
49 return (**ptr).operator[](static_cast<int>(idx));
50 }
51
54 template <typename Integral, bool = std::numeric_limits<Integral>::is_signed>
55 struct NegativeValueChecker
56 {
60 static void Check(const Integral &value)
61 {
62 if (value < 0)
63 throw System::OverflowException(u"Negative array size");
64 }
65 };
68 template <typename Integral>
69 struct NegativeValueChecker<Integral, false>
70 {
72 static void Check(const Integral&) {}
73 };
74
77 template <typename Integral, bool = (sizeof(Integral) > sizeof(int)) || (!std::numeric_limits<Integral>::is_signed && (sizeof(Integral) == sizeof(int)))>
78 struct IntPositiveOverflowChecker
79 {
83 static void Check(const Integral& value)
84 {
85 if (value >= static_cast<Integral>((std::numeric_limits<int>::max)()))
86 throw System::OverflowException(u"Array size too big for signed integer");
87 }
88 };
91 template <typename Integral>
92 struct IntPositiveOverflowChecker<Integral, false>
93 {
95 static void Check(const Integral &value) { ASPOSE_UNUSED(value); }
96 };
97
103 template <typename Integral>
104 int FixArraySize(const Integral &value)
105 {
106 NegativeValueChecker<Integral>::Check(value);
107 IntPositiveOverflowChecker<Integral>::Check(value);
108 return static_cast<int>(value);
109 }
110 }
111
114 class ASPOSECPP_SHARED_CLASS ArrayBase : virtual public Object
115 {
116 typedef ArrayBase ThisType;
117 typedef System::Object BaseType;
118
119 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
120 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
121
122 public:
125 virtual int32_t get_Length() const = 0;
126
129 virtual void* raw_data_ptr() = 0;
130 };
131
134
163 template<typename T>
164 ArrayPtr<T> MakeArray(std::initializer_list<T> init)
165 {
166 System::Details::MakeObjectLeakageDetector::SignatureBacktraceSentry signature_sentry;
167 System::Details::MakeObjectLeakageDetector::SetSignature<Array<T>>(init);
168
169 Detail::OwnNextObject ownershipSentry;
170
171 Array<T> *const arr = new Array<T>(init);
172
173 ownershipSentry.CreatedSuccessfully(arr);
174 signature_sentry.CreatedSuccessfully(arr);
175
176 return ArrayPtr<T>(arr);
177 }
178
183 template <class T, class... Args> ArrayPtr<T> MakeArray(Args&&... args)
184 {
185 System::Details::MakeObjectLeakageDetector::SignatureBacktraceSentry signature_sentry;
186 System::Details::MakeObjectLeakageDetector::SetSignature<Array<T>>(std::forward<Args>(args)...);
187
188 Detail::OwnNextObject ownershipSentry;
189
190 Array<T>* const arr = new Array<T>(std::forward<Args>(args)...);
191
192 ownershipSentry.CreatedSuccessfully(arr);
193 signature_sentry.CreatedSuccessfully(arr);
194
195 return ArrayPtr<T>(arr);
196 }
197
204 template <class T, class Integral, class... Args>
205 typename std::enable_if<std::is_integral<Integral>::value, ArrayPtr<T>>::type MakeArray(Integral size, Args&&... args)
206 {
207 System::Details::MakeObjectLeakageDetector::SignatureBacktraceSentry signature_sentry;
208 System::Details::MakeObjectLeakageDetector::SetSignature<Array<T>>(Details::FixArraySize(size), std::forward<Args>(args)...);
209
210 Detail::OwnNextObject ownershipSentry;
211
212 Array<T>* const arr = new Array<T>(Details::FixArraySize(size), std::forward<Args>(args)...);
213
214 ownershipSentry.CreatedSuccessfully(arr);
215 signature_sentry.CreatedSuccessfully(arr);
216
217 return ArrayPtr<T>(arr);
218 }
219
281 template<typename T>
282 class ASPOSECPP_SHARED_CLASS Array
283 : public ArrayBase
285 {
286 typedef Array<T> ThisType;
288
289 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
290 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
291
292 public:
294 using ValueType = T;
296 using UnderlyingType = typename System::Details::SelectType<T>::type;
297
298 protected:
300 typedef System::Details::CollectionHelpers::ContainerPointerMode<UnderlyingType> pointer_mode_t;
302 typedef std::vector<UnderlyingType, typename pointer_mode_t::allocator_type> vector_t;
307#ifdef ASPOSE_GET_SHARED_MEMBERS
308 DEFINE_GET_SHARED_MEMBERS(m_data)
309#endif
310 public:
315
320 class Enumerator : virtual public Object, public Collections::Generic::IEnumerator<T>
321 {
322 RTTI_INFO_TEMPLATE_CLASS(Array<T>::Enumerator, System::BaseTypesInfo<System::Object>);
323
324 private:
326 SharedPtr<Array<T>> m_array;
328 int64_t m_idx;
329
330 public:
333 Enumerator(const SharedPtr<Array<T>>& arr) : m_array(arr), m_idx(-1) { }
334
336 virtual ~Enumerator() {}
337
339 virtual MakeConstRef_t<T> get_Current() const override
340 {
341 return (m_idx < 0 || m_idx >= (int64_t)m_array->m_data.size())
342 ? System::Default<T>()
343 : m_array->m_data[(size_t)m_idx];
344 }
345
349 virtual bool MoveNext() override
350 {
351 if (m_idx < (int64_t)m_array->m_data.size())
352 m_idx++;
353
354 return m_idx < (int64_t)m_array->m_data.size();
355 }
356
358 virtual void Reset() override
359 {
360 m_idx = -1;
361 }
362
363#ifdef __DBG_FOR_EACH_MEMBER
364 public:
367 void DBG_for_each_member(DBG::for_each_member_visitor &visitor) const override
368 {
369 visitor.add_self(this);
370 visitor.add_member(this, m_array.get_shared(), "m_array");
371 }
372
374 const char* DBG_class_name() const override { return "Array<T>::Enumerator"; }
375#endif
376
377 protected:
378#ifdef ASPOSE_GET_SHARED_MEMBERS
380 virtual void GetSharedMembers(System::Object::shared_members_type& result) const override
381 {
382 Object::GetSharedMembers(result);
383 result.Add("System::Array<T>::Enumerator::m_array", m_array);
384 }
385#endif
386 };
387
389 Array() : m_data(m_pointer_mode.GetAllocator()) {}
390
394 Array(int count, const T& init = T()) : m_data(count, static_cast<UnderlyingType>(init), m_pointer_mode.GetAllocator()) { }
395
400 template <typename ValueType>
401 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)
402 : Array(count, ASPOSECPP_CHECKED_CAST(T, init)) {}
403
407 Array(int count, const T inits[]) : m_data(count, static_cast<UnderlyingType>(T()), m_pointer_mode.GetAllocator())
408 {
409 for (int i = 0; i < count; ++i)
410 m_data[i] = inits[i];
411 }
412
415 Array(vector_t&& value) : m_data(std::move(value), m_pointer_mode.GetAllocator()) {}
416
419 Array(const vector_t &assgn) : m_data(assgn, m_pointer_mode.GetAllocator()) {}
420
425 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>
426 Array(const std::vector<Q> &value)
427 : m_data(value.begin(), value.end(), m_pointer_mode.GetAllocator())
428 {}
429
434 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>
435 Array(std::vector<Q> &&value)
436 : m_data(m_pointer_mode.GetAllocator())
437 {
438 m_data.swap(value);
439 }
440
443 Array(std::initializer_list<UnderlyingType> init) : m_data(init, m_pointer_mode.GetAllocator()) {}
444
448 template <std::size_t InitArraySize>
449 Array(const std::array<UnderlyingType, InitArraySize> &init) :
450 Array(init, static_cast<std::make_index_sequence<InitArraySize>*>(nullptr))
451 {}
452
455 Array(std::initializer_list<bool> init, int = 0) : m_data(m_pointer_mode.GetAllocator())
456 {
457 for (auto it = init.begin(); it != init.end(); ++it)
458 m_data.push_back(UnderlyingType(*it));
459 }
460
461 // IEnumerable<T> interface
462
465 virtual EnumeratorPtr GetEnumerator() override
466 {
467 return MakeObject<Enumerator>(std::move(MakeSharedPtr(this)));
468 }
469
470 // end of IEnumerable<T> interface
471
472 // ICollection<T> interface
473 // Note: members which add, insert, or remove elements throw NotSupportedException.
474
476 virtual int get_Count() const override
477 {
478 return get_Length();
479 }
480
483 virtual void Add(const T&) override
484 {
485 throw NotSupportedException(u"Array as ICollection<T>::Add");
486 }
487
490 virtual void Clear() override
491 {
492 throw NotSupportedException(u"Array as ICollection<T>::Clear");
493 }
494
497 void SetTemplateWeakPtr(uint32_t argument) override
498 {
499 m_pointer_mode.SetWeak(argument, m_data);
500 }
501
502private:
507 template <typename Q = T>
508 auto ContainsImpl(const Q* item) const -> decltype(std::declval<UnderlyingType>() == *item, void(0), bool())
509 {
510 return std::find_if(m_data.begin(), m_data.end(),
511 [&item](const T& value) { return Details::AreEqual(value, *item); }) != m_data.end();
512 }
513
516 bool ContainsImpl(...) const
517 {
518 throw NotImplementedException(ASPOSE_CURRENT_FUNCTION);
519 }
520public:
524 virtual bool Contains(const T& item) const override
525 {
526 return ContainsImpl(&item);
527 }
528
531 virtual bool Remove(const T&) override
532 {
533 throw NotSupportedException(u"Array as ICollection<T>::Remove");
534 }
535
536 // Returns True when you cast or converted to an ICollection<T> object,
537 // even though individual array elements can be modified.
538
541 virtual bool get_IsReadOnly() const override
542 {
543 return true;
544 }
545
550 virtual void CopyTo(ArrayPtr<T> arr, int arrayIndex) override
551 {
552 this->CopyTo<T>(arr, static_cast<int64_t>(arrayIndex));
553 }
554
555 // end of ICollection<T> interface
556
557 // IList<T> interface
558private:
559 template <std::size_t ...InitArrayIndexes>
560 Array(const std::array<UnderlyingType, sizeof...(InitArrayIndexes)> &init, std::index_sequence<InitArrayIndexes...>*) :
561 m_data({ init[InitArrayIndexes]... }, m_pointer_mode.GetAllocator()) {}
562
563
568 template <typename Q = T>
569 auto IndexOfImpl(const Q* item) const -> decltype(std::declval<UnderlyingType>() == *item, void(0), int())
570 {
571 auto it = std::find_if(m_data.begin(), m_data.end(), [&item](const T& value) { return Details::AreEqual(value, *item); });
572
573 return (it != m_data.end()) ? static_cast<int>(it - m_data.begin()) : -1;
574 }
575
578 int IndexOfImpl(...) const
579 {
580 throw NotImplementedException(ASPOSE_CURRENT_FUNCTION);
581 }
582
583public:
587 virtual int IndexOf(const T& item) const override
588 {
589 return IndexOfImpl(&item);
590 }
591
594 virtual void Insert(int, const T&) override
595 {
596 throw NotSupportedException(u"Array as IList<T>::Insert");
597 }
598
601 virtual void RemoveAt(int) override
602 {
603 throw NotSupportedException(u"Array as IList<T>::RemoveAt");
604 }
605
609 virtual T idx_get(int index) const override
610 {
611 return operator[](index);
612 }
613
617 virtual void idx_set(int index, T value) override
618 {
619 operator[](index) = value;
620 }
621
622 // end of IList<T> interface
623
627 ArrayPtr<T> Init(const T inits[])
628 {
629 for (size_t i = 0; i < m_data.size(); ++i)
630 m_data[i] = inits[i];
631
632 return MakeSharedPtr(this);
633 }
634
637 {
638 for (size_t i = 0; i < m_data.size(); ++i)
639 m_data[i] = T();
640 }
641
646 {
647 using namespace Collections::Generic::Details;
648 if (IsOutOfBounds(index, m_data)) {
649 throw ArgumentOutOfRangeException(u"index");
650 }
651 return m_data[static_cast<typename vector_t::size_type>(index)];
652 }
653
657 UnderlyingType const& operator[](int index) const
658 {
659 using namespace Collections::Generic::Details;
660 if (IsOutOfBounds(index, m_data)) {
661 throw ArgumentOutOfRangeException(u"index");
662 }
663 return m_data[static_cast<typename vector_t::size_type>(index)];
664 }
665
670 {
671 System::ArrayPtr<T> clone = System::MakeObject< System::Array<T> >(static_cast<int>(m_data.size()));
672 std::copy(m_data.begin(), m_data.end(), clone->data().begin());
673 return clone;
674 }
675
678 {
679 return System::MakeObject<Collections::ObjectModel::ReadOnlyCollection<T>>(array);
680 }
681
686 static int BinarySearch(System::ArrayPtr<T> arr, const T &item)
687 {
688 return Collections::Generic::_net_binnary_search(arr->m_data, 0, static_cast<int32_t>(arr->m_data.size()), item);
689 }
690
693 template<typename Y, typename Z>
694 static int BinarySearch(System::ArrayPtr<T> arr, const Y& item, const SharedPtr<Collections::Generic::IComparer<Z>>& comparer)
695 {
696 throw NotImplementedException();
697 }
698
702 int GetLength(int dimension)
703 {
704 return static_cast<int>(GetLongLength(dimension));
705 }
706
710 int64_t GetLongLength(int dimension)
711 {
712 return upper_bound(m_data, dimension) + 1;
713 }
714
718 int GetLowerBound(int dimension) const
719 {
720 ASPOSE_UNUSED(dimension);
721 return 0;
722 }
723
727 int GetUpperBound(int dimension)
728 {
729 return upper_bound(m_data, dimension);
730 }
731
738 template <typename InputType, typename OutputType>
740 {
741 if (!input_array)
742 {
743 throw System::ArgumentNullException(u"arr");
744 }
745
746 if (converter.IsNull())
747 {
748 throw System::ArgumentNullException(u"converter");
749 }
750
751 System::ArrayPtr<OutputType> newArray = System::MakeObject< System::Array<OutputType> >(input_array->get_Length());
752 for (int i = 0; i < input_array->get_Length(); i++)
753 {
754 newArray[i] = converter(input_array[i]);
755 }
756 return newArray;
757 }
758
765 template <typename InputType, typename OutputType>
766 static ArrayPtr<OutputType> ConvertAll(ArrayPtr<InputType> input_array, std::function<OutputType(InputType)> converter)
767 {
768 return ConvertAll(input_array, Converter<InputType, OutputType>(converter));
769 }
770
776 {
777 if (!arr || match.IsNull())
778 {
779 throw System::ArgumentNullException(u"arr or match");
780 }
781
782 for (int i = 0; i < arr->get_Length(); i++)
783 {
784 if (match(arr[i]))
785 return i;
786 }
787 return -1;
788 }
789
795 {
796 if (!arr || match.IsNull())
797 {
798 throw System::ArgumentNullException(u"arr or match");
799 }
800
801 for (auto val: arr->m_data)
802 if (match(val))
803 return val;
804 return T();
805 }
806
812 {
813 if (!arr || match.IsNull())
814 {
815 throw System::ArgumentNullException(u"arr or match");
816 }
817
818 System::ArrayPtr<T> result = System::MakeObject<System::Array<T>>();
819
820 for (auto val : arr->m_data)
821 if (match(val))
822 result->data().push_back(val);
823
824 return result;
825 }
826
832 {
833 if (!arr || match.IsNull())
834 {
835 throw System::ArgumentNullException(u"arr or match");
836 }
837 for (auto val : arr->m_data)
838 if (!match(val))
839 return false;
840 return true;
841 }
842
844 int32_t get_Rank() const { throw System::NotImplementedException(ASPOSE_CURRENT_FUNCTION); };
845
848 int32_t get_Length() const override
849 {
850 //TODO IF the array is multidimensional THEN OverflowException
851 const int64_t len64 = get_LongLength();
852
853 if (len64 > (std::numeric_limits<int32_t>::max)()) {
854 throw OverflowException();
855 }
856 return static_cast<int32_t>(len64);
857 }
858
861 int64_t get_LongLength() const
862 {
863 return GetSizeTLength();
864 }
865
868 size_t GetSizeTLength() const
869 {
870 return recursive_size(m_data);
871 }
872
875 int Count() const { return get_Length(); }
876
882 template<typename DstType>
883 void CopyTo(const ArrayPtr<DstType> &dstArray, int64_t dstIndex) const
884 {
885 this->CopyTo(dstArray, 0, dstIndex, GetSizeTLength());
886 }
887
893 template<typename DstType>
894 void CopyTo(const System::Details::ArrayView<DstType> &dstArray, int64_t dstIndex) const
895 {
896 this->CopyTo(dstArray, 0, dstIndex, GetSizeTLength());
897 }
898
907 template<typename DstType>
908 void CopyTo(const ArrayPtr<DstType> &dstArray, int64_t srcIndex, int64_t dstIndex, int64_t count) const
909 {
910 using namespace Collections::Generic::Details;
911
912 if (!dstArray) {
913 throw ArgumentNullException(u"dstArray");
914 }
915 if (srcIndex < 0 || dstIndex < 0 || count < 0) {
916 throw ArgumentOutOfRangeException(u"srcIndex, dstIndex or count");
917 }
918 if (IsOutOfSize(srcIndex + count, m_data)
919 || IsOutOfSize(dstIndex + count, dstArray->data())) {
920 throw ArgumentException(u"srcIndex, dstIndex or count");
921 }
922
923 // casts are safe because bounds have already checked.
924
925 if (dstArray.GetObjectOrNull() == (Object*)(this) && dstIndex > srcIndex && dstIndex < srcIndex + count)
926 {
927 std::copy_backward(
928 m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex)
929 , m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex) + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, count)
930 , dstArray->data().begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, dstIndex) + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, count)
931 );
932 }
933 else
934 {
935 std::copy(
936 m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex)
937 , m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex) + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, count)
938 , dstArray->data().begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, dstIndex)
939 );
940 }
941 }
942
951 template<typename DstType>
952 void CopyTo(const System::Details::ArrayView<DstType> &dstArray, int64_t srcIndex, int64_t dstIndex, int64_t count) const
953 {
954 using namespace Collections::Generic::Details;
955
956 if (!dstArray) {
957 throw ArgumentNullException(u"dstArray");
958 }
959 if (srcIndex < 0 || dstIndex < 0 || count < 0) {
960 throw ArgumentOutOfRangeException(u"srcIndex, dstIndex or count");
961 }
962 if (IsOutOfSize(srcIndex + count, m_data)
963 || dstIndex + count > dstArray.get_Length()) {
964 throw ArgumentException(u"srcIndex, dstIndex or count");
965 }
966
967 if (dstArray.data() == this->data().data()
968 && dstIndex > srcIndex && dstIndex < srcIndex + count)
969 {
970 std::copy_backward(
971 m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex)
972 , m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex) + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, count)
973 , dstArray.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, dstIndex) + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, count)
974 );
975 }
976 else
977 {
978 std::copy(
979 m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex)
980 , m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex) + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, count)
981 , dstArray.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, dstIndex)
982 );
983 }
984 }
985
989 static void ForEach(const ArrayPtr<T>& arr, System::Action<T> action)
990 {
991 if (action.IsNull())
992 throw ArgumentNullException(u"action");
993
994 for (auto val : arr->m_data)
995 action(val);
996 }
997
1004 template<typename ArrayType, typename ValueType>
1005 static int IndexOf(const ArrayPtr<ArrayType> &arr, const ValueType& value)
1006 {
1007 return IndexOf(arr, value, 0);
1008 }
1009
1017 template<typename ArrayType, typename ValueType>
1018 static int IndexOf(const ArrayPtr<ArrayType> &arr, const ValueType& value, int startIndex)
1019 {
1020 return IndexOf(arr, value, startIndex, arr->get_Length() - startIndex);
1021 }
1022
1031 template<typename ArrayType, typename ValueType>
1032 static int IndexOf(const ArrayPtr<ArrayType> &arr, const ValueType& value, int startIndex, int count)
1033 {
1034 using namespace Collections::Generic::Details;
1035 if (!arr) {
1036 throw ArgumentNullException(u"arr");
1037 }
1038 if (startIndex < 0 || count < 0 || IsOutOfSize(startIndex + count, arr->data())) {
1039 throw ArgumentOutOfRangeException(u"startIndex or count");
1040 }
1041
1042 auto begin = arr->data().begin() + startIndex;
1043 auto end = begin + count;
1044 auto it =
1045 std::find_if(begin, end, [&value](const ArrayType& item) { return Details::AreEqual(item, value); });
1046
1047 return (it != end) ? static_cast<int>(it - arr->data().begin()) : -1;
1048 }
1049
1058 template<typename ArrayType, typename ValueType>
1059 static int LastIndexOf(const ArrayPtr<ArrayType>& arr, const ValueType& value, int startIndex, int count)
1060 {
1061 using namespace Collections::Generic::Details;
1062 if (!arr) {
1063 throw ArgumentNullException(u"arr");
1064 }
1065 if (startIndex < 0 || count < 0
1066 || IsOutOfSize(startIndex, arr->data()) || IsOutOfSize(count, arr->data())
1067 || (startIndex - count + 1) < 0) {
1068 throw ArgumentOutOfRangeException(u"startIndex or count");
1069 }
1070 auto rbegin = arr->data().rbegin() + arr->data().size() - startIndex - 1;
1071 auto rend = rbegin + count;
1072 auto rit = std::find_if(rbegin, rend, [&value](const ArrayType& item) { return Details::AreEqual(item, value); });
1073
1074 return (rit != rend) ? ASPOSECPP_CHECKED_CAST(int, rit.base() - arr->data().begin() - 1) : -1;
1075 }
1076
1084 template<typename ArrayType, typename ValueType>
1085 static int LastIndexOf(const ArrayPtr<ArrayType>& items, const ValueType& value, int startIndex)
1086 {
1087 return LastIndexOf(items, value, startIndex, (items->get_Length() == 0) ? 0 : startIndex + 1);
1088 }
1089
1096 template<typename ArrayType, typename ValueType>
1097 static int LastIndexOf(const ArrayPtr<ArrayType>& items, const ValueType& value)
1098 {
1099 return LastIndexOf(items, value, items->get_Length() - 1, items->get_Length());
1100 }
1101
1107 template<typename Type>
1108 static void Clear(const ArrayPtr<Type> &arr, int startIndex, int count)
1109 {
1110 using namespace Collections::Generic::Details;
1111 if (!arr) {
1112 throw ArgumentNullException(u"arr");
1113 }
1114 if (startIndex < 0 || count < 0 || IsOutOfSize(startIndex + count, arr->data())) {
1115 throw ArgumentOutOfRangeException(u"startIndex or count");
1116 }
1117
1118 for (auto i = 0; i < count; ++i)
1119 arr->data().at(startIndex + i) = Type();
1120 }
1121
1123 // index and pastes them to another System.Array starting at the specified destination
1124 // index. Guarantees that all changes are undone if the copy does not succeed completely.
1133 template <typename SrcType, typename DstType>
1134 static void ConstrainedCopy(const ArrayPtr<SrcType> &srcArray, int64_t srcIndex,
1135 const ArrayPtr<DstType> &dstArray, int64_t dstIndex, int64_t count)
1136 {
1137 if (!srcArray) {
1138 throw ArgumentNullException(u"srcArray");
1139 }
1140 srcArray->CopyTo(dstArray, srcIndex, dstIndex, count);
1141 }
1142
1147 template<typename SrcType, typename DstType>
1148 static void Copy(const ArrayPtr<SrcType> &srcArray,
1149 const ArrayPtr<DstType> &dstArray, int64_t count)
1150 {
1151 if (!srcArray) {
1152 throw ArgumentNullException(u"srcArray");
1153 }
1154 srcArray->CopyTo(dstArray, 0, 0, count);
1155 }
1156
1161 template<typename SrcType, typename DstType>
1162 static void Copy(System::Details::ArrayView<SrcType> srcArray,
1163 const ArrayPtr<DstType> &dstArray, int64_t count)
1164 {
1165 if (!srcArray) {
1166 throw ArgumentNullException(u"srcArray");
1167 }
1168 srcArray.CopyTo(dstArray, 0, 0, count);
1169 }
1170
1175 template<typename SrcType, typename DstType>
1176 static void Copy(const ArrayPtr<SrcType> &srcArray,
1177 System::Details::ArrayView<DstType> dstArray, int64_t count)
1178 {
1179 if (!srcArray) {
1180 throw ArgumentNullException(u"srcArray");
1181 }
1182 srcArray->CopyTo(dstArray, 0, 0, count);
1183 }
1184
1189 template<typename SrcType, typename DstType>
1190 static void Copy(System::Details::ArrayView<SrcType> srcArray,
1191 System::Details::ArrayView<DstType> dstArray, int64_t count)
1192 {
1193 if (!srcArray) {
1194 throw ArgumentNullException(u"srcArray");
1195 }
1196 srcArray.CopyTo(dstArray, 0, 0, count);
1197 }
1198
1203 template<typename SrcType, std::size_t N, typename DstType>
1204 static void Copy(System::Details::StackArray<SrcType, N> &srcArray,
1205 const ArrayPtr<DstType> &dstArray, int64_t count)
1206 {
1207 Copy(static_cast<System::Details::ArrayView<SrcType> >(srcArray), dstArray, count);
1208 }
1209
1214 template<typename SrcType, typename DstType, std::size_t N>
1215 static void Copy(const ArrayPtr<SrcType> &srcArray,
1216 System::Details::StackArray<DstType, N> &dstArray, int64_t count)
1217 {
1218 Copy(srcArray, static_cast<System::Details::ArrayView<DstType> >(dstArray), count);
1219 }
1220
1225 template<typename SrcType, std::size_t NS, typename DstType, std::size_t ND>
1226 static void Copy(System::Details::StackArray<SrcType, NS> &srcArray,
1227 System::Details::StackArray<DstType, ND> &dstArray, int64_t count)
1228 {
1229 Copy(static_cast<System::Details::ArrayView<SrcType> >(srcArray),
1230 static_cast<System::Details::ArrayView<DstType> >(dstArray), count);
1231 }
1232
1241 template<typename SrcType, typename DstType>
1242 static void Copy(const ArrayPtr<SrcType> &srcArray, int64_t srcIndex,
1243 const ArrayPtr<DstType> &dstArray, int64_t dstIndex, int64_t count)
1244 {
1245 if (!srcArray) {
1246 throw ArgumentNullException(u"srcArray");
1247 }
1248 srcArray->CopyTo(dstArray, srcIndex, dstIndex, count);
1249 }
1250
1259 template<typename SrcType, typename DstType>
1260 static void Copy(System::Details::ArrayView<SrcType> srcArray, int64_t srcIndex,
1261 const ArrayPtr<DstType> &dstArray, int64_t dstIndex, int64_t count)
1262 {
1263 if (!srcArray) {
1264 throw ArgumentNullException(u"srcArray");
1265 }
1266 srcArray.CopyTo(dstArray, srcIndex, dstIndex, count);
1267 }
1268
1277 template<typename SrcType, typename DstType>
1278 static void Copy(const ArrayPtr<SrcType> &srcArray, int64_t srcIndex,
1279 System::Details::ArrayView<DstType> dstArray, int64_t dstIndex, int64_t count)
1280 {
1281 if (!srcArray) {
1282 throw ArgumentNullException(u"srcArray");
1283 }
1284 srcArray->CopyTo(dstArray, srcIndex, dstIndex, count);
1285 }
1286
1295 template<typename SrcType, typename DstType>
1296 static void Copy(System::Details::ArrayView<SrcType> srcArray, int64_t srcIndex,
1297 System::Details::ArrayView<DstType> dstArray, int64_t dstIndex, int64_t count)
1298 {
1299 if (!srcArray) {
1300 throw ArgumentNullException(u"srcArray");
1301 }
1302 srcArray.CopyTo(dstArray, srcIndex, dstIndex, count);
1303 }
1304
1313 template<typename SrcType, std::size_t N, typename DstType>
1314 static void Copy(System::Details::StackArray<SrcType, N> &srcArray, int64_t srcIndex,
1315 const ArrayPtr<DstType> &dstArray, int64_t dstIndex, int64_t count)
1316 {
1317 Copy(static_cast<System::Details::ArrayView<SrcType> >(srcArray), srcIndex, dstArray, dstIndex, count);
1318 }
1319
1328 template<typename SrcType, typename DstType, std::size_t N>
1329 static void Copy(const ArrayPtr<SrcType> &srcArray, int64_t srcIndex,
1330 System::Details::StackArray<DstType, N> &dstArray, int64_t dstIndex, int64_t count)
1331 {
1332 Copy(srcArray, srcIndex, static_cast<System::Details::ArrayView<DstType> >(dstArray), dstIndex, count);
1333 }
1334
1343 template<typename SrcType, std::size_t NS, typename DstType, std::size_t ND>
1344 static void Copy(System::Details::StackArray<SrcType, NS> &srcArray, int64_t srcIndex,
1345 System::Details::StackArray<DstType, ND> &dstArray, int64_t dstIndex, int64_t count)
1346 {
1347 Copy(static_cast<System::Details::ArrayView<SrcType>>(srcArray), srcIndex,
1348 static_cast<System::Details::ArrayView<DstType>>(dstArray), dstIndex, count);
1349 }
1350
1359 template<typename SrcType, typename DstType, std::size_t ND>
1360 static void Copy(System::Details::ArrayView<SrcType> &srcArray, int64_t srcIndex,
1361 System::Details::StackArray<DstType, ND> &dstArray, int64_t dstIndex, int64_t count)
1362 {
1363 Copy(srcArray, srcIndex,
1364 static_cast<System::Details::ArrayView<DstType>>(dstArray), dstIndex, count);
1365 }
1366
1369 template<typename Type>
1370 static void Sort(const ArrayPtr<Type> &arr)
1371 {
1372 Sort(arr, 0, arr->get_Length());
1373 }
1374
1379 template<typename Type>
1380 static void Sort(const ArrayPtr<Type> &arr, int startIndex, int count)
1381 {
1382 using namespace Collections::Generic::Details;
1383 if (!arr) {
1384 throw ArgumentNullException(u"arr");
1385 }
1386 if (startIndex < 0 || count < 0 || IsOutOfSize(startIndex + count, arr->data())) {
1387 throw ArgumentOutOfRangeException(u"startIndex or count");
1388 }
1389
1390 auto begin = arr->data().begin() + startIndex;
1391 auto end = begin + count;
1392
1393 std::sort(begin, end, Collections::Generic::Details::ComparerType<Type>());
1394 }
1395
1399 template<typename Type>
1401 {
1402 Collections::Generic::ComparerAdapter<T> adapter(comparator);
1403 std::sort(arr->data().begin(), arr->data().end(), adapter);
1404 }
1405
1408 template<typename Type, typename Y>
1410 {
1411 throw NotImplementedException();
1412 }
1413
1415 template<typename Type>
1416 static void Sort(const ArrayPtr<Type>& arr, const System::Comparison<T>& comparison)
1417 {
1418 std::sort(arr->data().begin(), arr->data().end(), comparison);
1419 }
1420
1427 template<typename TKey, typename TValue>
1428 static void Sort(const ArrayPtr<TKey>& keys, const ArrayPtr<TValue>& items)
1429 {
1430 if (keys == nullptr)
1431 throw ArgumentNullException(u"keys");
1432
1433 Sort(keys, items, 0, keys->get_Length());
1434 }
1435
1444 template<typename TKey, typename TValue>
1445 static void Sort(const ArrayPtr<TKey>& keys, const ArrayPtr<TValue>& items, int index, int length)
1446 {
1447 if (keys == nullptr)
1448 throw ArgumentNullException(u"keys");
1449 if (index < 0 || length < 0)
1450 throw ArgumentOutOfRangeException(length < 0 ? u"length" : u"index");
1451 if (index + length > keys->Count() || (items != nullptr && index + length > items->Count()))
1452 throw ArgumentException();
1453
1454 if (items == nullptr)
1455 {
1456 typename std::vector<TKey>::iterator keys_begin = keys->data().begin() + index;
1457 typename std::vector<TKey>::iterator keys_end = keys_begin + length;
1458
1459 std::sort(keys_begin, keys_end, Collections::Generic::Details::ComparerType<TKey>());
1460 }
1461 else
1462 {
1463 // Sorting keys and items via multimap
1464 std::multimap<TKey, TValue, Collections::Generic::Details::ComparerType<TKey>> map;
1465 for (int i = index; i < index + length; ++i)
1466 map.insert(std::make_pair(keys[i], items[i]));
1467
1468 auto map_iter = map.begin();
1469 for (int i = index; (i < index + length) && (map_iter != map.end()); ++i, ++map_iter)
1470 {
1471 keys[i] = map_iter->first;
1472 items[i] = map_iter->second;
1473 }
1474 }
1475 }
1476
1479 template<typename Type>
1480 static void Reverse(const ArrayPtr<Type> &arr)
1481 {
1482 std::reverse(arr->m_data.begin(), arr->m_data.end());
1483 }
1484
1489 template<typename Type>
1490 static void Reverse(const ArrayPtr<Type> &arr, int startIndex, int count)
1491 {
1492 using namespace Collections::Generic::Details;
1493 if (!arr) {
1494 throw ArgumentNullException(u"arr");
1495 }
1496 if (startIndex < 0 || count < 0 || IsOutOfSize(startIndex + count, arr->data())) {
1497 throw ArgumentOutOfRangeException(u"startIndex or count");
1498 }
1499
1500 std::reverse(arr->m_data.begin() + startIndex, arr->m_data.begin() + startIndex + count);
1501 }
1502
1506 template<typename Type>
1507 static void Resize(ArrayPtr<Type> &arr, int new_size)
1508 {
1509 if (new_size < 0)
1510 throw ArgumentOutOfRangeException(u"new_size");
1511
1512 if (arr)
1513 {
1514 // Array is present, so we need to resize it
1515 if (arr.get_shared_count() != 1)
1516 {
1517 // Array is shared between some variables, so we need to create new one of needed size
1518 auto new_array = MakeObject<Array<T>>(new_size);
1519 std::copy(arr->data_ptr(), arr->data_ptr() + (std::ptrdiff_t)std::min(new_size, arr->get_Length()), new_array->data_ptr());
1520 arr = new_array;
1521 }
1522 else
1523 {
1524 // Array is owned only by this variable, so we probably can just resize its data
1525 arr->m_data.resize((typename vector_t::size_type)new_size);
1526 }
1527 }
1528 else
1529 {
1530 // No array present, we just need to create new one
1531 arr = MakeObject<Array<T>>(new_size);
1532 }
1533 }
1534
1538 void SetValue(const T &value, int index)
1539 {
1540 using namespace Collections::Generic::Details;
1541 if (IsOutOfBounds(index, m_data)) {
1542 throw ArgumentOutOfRangeException(u"index");
1543 }
1544 m_data[index] = value;
1545 }
1546
1548 vector_t& data() { return m_data; }
1549
1551 const vector_t& data() const { return m_data; }
1552
1554 typename vector_t::pointer data_ptr() // VS2013 std::vector has no data() member
1555 {
1556 if(m_data.empty())
1557 return nullptr;
1558
1559 return &m_data[0];
1560 }
1561
1563 const UnderlyingType * data_ptr() const { return data_ptr(); }
1564
1567 void* raw_data_ptr() override { return data_ptr(); }
1568
1570 typedef typename vector_t::iterator iterator;
1572 typedef typename vector_t::const_iterator const_iterator;
1574 typedef typename vector_t::reverse_iterator reverse_iterator;
1576 typedef typename vector_t::const_reverse_iterator const_reverse_iterator;
1577
1581 iterator begin() noexcept
1582 {
1583 return m_data.begin();
1584 }
1585
1589 const_iterator begin() const noexcept
1590 {
1591 return m_data.begin();
1592 }
1593
1597 const_iterator cbegin() const noexcept
1598 {
1599 return m_data.cbegin();
1600 }
1601
1605 iterator end() noexcept
1606 {
1607 return m_data.end();
1608 }
1609
1613 const_iterator end() const noexcept
1614 {
1615 return m_data.end();
1616 }
1617
1621 const_iterator cend() const noexcept
1622 {
1623 return m_data.cend();
1624 }
1625
1631 {
1632 return m_data.rbegin();
1633 }
1634
1640 {
1641 return m_data.rbegin();
1642 }
1643
1649 {
1650 return m_data.crbegin();
1651 }
1652
1658 {
1659 return m_data.rend();
1660 }
1661
1667 {
1668 return m_data.rend();
1669 }
1670
1676 {
1677 return m_data.crend();
1678 }
1679
1680 // int get_Count() const; - see ICollection<T> interface
1681 // void Add(const T& item); - see ICollection<T> interface
1682 // void Clear(); - see ICollection<T> interface
1683 // bool Contains(const T& item) const; - see ICollection<T> interface
1684 // bool Remove(const T& item); - see ICollection<T> interface
1685
1686 // IList interface
1687
1688 // int IndexOf(const T& item) const; - see IList<T> interface
1689 // void Insert(int index, const T& item); - see IList<T> interface
1690 // void RemoveAt(int index); - see IList<T> interface
1691
1692 // IEnumerable interface
1696 {
1697 return *std::min_element(m_data.cbegin(), m_data.cend());
1698 }
1699
1703 {
1704 return *std::max_element(m_data.cbegin(), m_data.cend());
1705 }
1706
1711 static bool Exists(ArrayPtr<T> arr, std::function<bool(T)> match)
1712 {
1713 for (int i = 0; i < arr->get_Length(); i++)
1714 {
1715 if (match(arr[i]))
1716 return true;
1717 }
1718 return false;
1719 }
1720
1722 System::Details::VirtualizedIteratorBase<T>* virtualizeBeginIterator() override
1723 {
1724 return new System::Details::NativeIteratorWrapper<T, iterator>(begin(), end());
1725 }
1727 System::Details::VirtualizedIteratorBase<T>* virtualizeEndIterator() override
1728 {
1729 return new System::Details::NativeIteratorWrapper<T, iterator>(end(), end());
1730 }
1732 System::Details::VirtualizedIteratorBase<T>* virtualizeBeginConstIterator() const override
1733 {
1734 return new System::Details::NativeConstIteratorWrapper<T, const_iterator>(begin(), end());
1735 }
1737 System::Details::VirtualizedIteratorBase<T>* virtualizeEndConstIterator() const override
1738 {
1739 return new System::Details::NativeConstIteratorWrapper<T, const_iterator>(end(), end());
1740 }
1741
1742private:
1748 template <typename ErrType>
1749 static int upper_bound(ErrType arr, int dim)
1750 {
1751 ASPOSE_UNUSED(arr);
1752 ASPOSE_UNUSED(dim);
1753 throw System::IndexOutOfRangeException();
1754 }
1761 template <typename VType, typename Alloc>
1762 static int upper_bound(const std::vector<VType, Alloc> &arr, int dim)
1763 {
1764 if (!dim)
1765 return (int)arr.size() - 1;
1766
1767 if (!arr.size())
1768 return -1;
1769
1770 return upper_bound(arr[0], dim - 1);
1771 }
1772
1778 template <typename U, typename Alloc>
1779 static size_t recursive_size(const std::vector<U, Alloc>& v)
1780 {
1781 return v.size();
1782 }
1783
1791 template <typename U, typename Alloc1, typename Alloc2>
1792 static size_t recursive_size(const std::vector<std::vector<U, Alloc1>, Alloc2>& v)
1793 {
1794 size_t rv = 0;
1795 for (const auto &i : v)
1796 rv += recursive_size(i);
1797
1798 return rv;
1799 }
1800
1801protected:
1803 ~Array() override {}
1804
1805#ifdef __DBG_FOR_EACH_MEMBER
1806 public:
1809 void DBG_for_each_member(DBG::for_each_member_visitor &visitor) const override
1810 {
1811 visitor.add_self(this);
1812 DBG::for_each_of_Object(this, m_data, visitor);
1813 }
1815 const char* DBG_class_name() const override { return "Array<T>"; }
1816#endif
1817 };
1820 template <typename TTo>
1821 struct CastResult<Array<TTo>>
1822 {
1824 typedef ArrayPtr<TTo> type;
1825 };
1827
1828
1829 namespace Details {
1833 template <typename T>
1834 inline Array<T>* CreateArray(Array<T>*)
1835 {
1836 return new Array<T>(0);
1837 }
1838
1839 } // namespace Details
1840
1841} // namespace System
1842
1843#endif // _aspose_system_array_h_
Implements IEnumerator interface that enables enumeration of elements of an Array object....
Definition: array.h:321
virtual ~Enumerator()
Destructor.
Definition: array.h:336
Enumerator(const SharedPtr< Array< T > > &arr)
Constructs a new Enumerator object that represents the specified array.
Definition: array.h:333
virtual MakeConstRef_t< T > get_Current() const override
Returns a copy of the current element.
Definition: array.h:339
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:349
virtual void Reset() override
Resets the current element's index.
Definition: array.h:358
The dummy for System.Array class (abstract base class for all arrays) May be filled with functionalit...
Definition: array.h:115
virtual void * raw_data_ptr()=0
Returns pointer to the first element of single-dimension array. For multi-dimensional arrays result u...
virtual int32_t get_Length() const =0
Returns 32-bit integer that represents the total number of all elements in all dimensions of the arra...
Class that represents an array data structure. Objects of this class should only be allocated using S...
Definition: array.h:285
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:811
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:1108
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:766
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:1648
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:1005
void SetValue(const T &value, int index)
Sets value of the element at specified index.
Definition: array.h:1538
SharedPtr< Collections::Generic::IEnumerator< T > > EnumeratorPtr
An alias for shared pointer type pointing to IEnumerator object containing elements of type T.
Definition: array.h:314
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:1134
vector_t::iterator iterator
Iterator type.
Definition: array.h:1570
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:1400
reverse_iterator rbegin() noexcept
Returns a reverse iterator to the first element of the reversed container. It corresponds to the last...
Definition: array.h:1630
UnderlyingType Min() const
Finds the smallest element in the array using operator<() to compare elements.
Definition: array.h:1695
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:435
virtual bool Contains(const T &item) const override
Determines if the specified item is in the array.
Definition: array.h:524
vector_t::const_reverse_iterator const_reverse_iterator
Const reverse iterator type.
Definition: array.h:1576
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:1563
~Array() override
Destructor.
Definition: array.h:1803
virtual void Clear() override
Not supported because the array represented by the current object is read-only.
Definition: array.h:490
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:1296
iterator begin() noexcept
Returns an iterator to the first element of the container. If the container is empty,...
Definition: array.h:1581
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:587
static void Sort(const ArrayPtr< Type > &arr, const SharedPtr< System::Collections::Generic::IComparer< Y > > &comparator)
NOT IMPLEMENTED.
Definition: array.h:1409
vector_t m_data
The storage for array's elements.
Definition: array.h:306
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:794
ArrayPtr< T > Init(const T inits[])
Fills the array represented by the current object with the values from the specified array.
Definition: array.h:627
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:1445
int GetLength(int dimension)
Returns the number of elements in the specified dimension.
Definition: array.h:702
virtual EnumeratorPtr GetEnumerator() override
Returns a pointer to Enumerator object that provides IEnumerator interface to elements of the array r...
Definition: array.h:465
Array(vector_t &&value)
Move constructor.
Definition: array.h:415
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:1554
static void Reverse(const ArrayPtr< Type > &arr)
Reverses elements in the specified array.
Definition: array.h:1480
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:1344
const vector_t & data() const
Returns a constant reference to the internal data structure used to store the array elements.
Definition: array.h:1551
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:1360
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:455
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:1032
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:1176
SharedPtr< Collections::Generic::IEnumerable< T > > EnumerablePtr
An alias for shared pointer type pointing to IEnumerable object containing elements of type T.
Definition: array.h:312
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:426
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:300
void * raw_data_ptr() override
Returns pointer to the first element of single-dimension array. For multi-dimensional arrays result u...
Definition: array.h:1567
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:908
System::Details::VirtualizedIteratorBase< T > * virtualizeEndConstIterator() const override
Gets the implementation of end const iterator for the current container.
Definition: array.h:1737
ArrayPtr< T > Clone()
Clones the array.
Definition: array.h:669
virtual void Add(const T &) override
Not supported because the array represented by the current object is read-only.
Definition: array.h:483
vector_t & data()
Returns a reference to the internal data structure used to store the array elements.
Definition: array.h:1548
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:883
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:894
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:952
virtual bool Remove(const T &) override
Not supported because the array represented by the current object is read-only.
Definition: array.h:531
const_reverse_iterator rend() const noexcept
Returns a reverse iterator to the element following the last element of the reversed container....
Definition: array.h:1666
Array(const vector_t &assgn)
Copy constructor.
Definition: array.h:419
iterator end() noexcept
Returns an iterator to the element following the last element of the container. This element acts as ...
Definition: array.h:1605
static int BinarySearch(System::ArrayPtr< T > arr, const T &item)
Performs binary search in the sorted array.
Definition: array.h:686
UnderlyingType Max() const
Finds the largest element in the array using operator<() to compare elements.
Definition: array.h:1702
int32_t get_Rank() const
NOT IMPLEMENTED.
Definition: array.h:844
const_iterator end() const noexcept
Returns an iterator to the element following the last element of the const-qualified container....
Definition: array.h:1613
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:739
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:1018
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:1711
T ValueType
Alias for the type of the elements of the array.
Definition: array.h:294
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:1190
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:831
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:775
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:1059
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
vector_t::reverse_iterator reverse_iterator
Reverse iterator type.
Definition: array.h:1574
Array(int count, const T &init=T())
Filling constructor.
Definition: array.h:394
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:861
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:1226
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginConstIterator() const override
Gets the implementation of begin const iterator for the current container.
Definition: array.h:1732
static void Sort(const ArrayPtr< Type > &arr, const System::Comparison< T > &comparison)
Sorts elements in the specified array using specified comparison.
Definition: array.h:1416
UnderlyingType const & operator[](int index) const
Returns an item at the specified index.
Definition: array.h:657
static SharedPtr< Collections::ObjectModel::ReadOnlyCollection< T > > AsReadOnly(const SharedPtr< Array< T > > &array)
Casts array to read only collection.
Definition: array.h:677
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:550
virtual bool get_IsReadOnly() const override
Indicates whether the array is read-only.
Definition: array.h:541
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:1428
void Initialize()
Fills the array with the default constructed objects of type T.
Definition: array.h:636
Array(int count, const T inits[])
Filling constructor.
Definition: array.h:407
virtual T idx_get(int index) const override
Returns the item at the specified index.
Definition: array.h:609
int GetLowerBound(int dimension) const
Returns the lower bound of the specified dimension.
Definition: array.h:718
System::Details::VirtualizedIteratorBase< T > * virtualizeEndIterator() override
Gets the implementation of end iterator for the current container.
Definition: array.h:1727
static void ForEach(const ArrayPtr< T > &arr, System::Action< T > action)
Performs specified action on each element of the specified array.
Definition: array.h:989
int64_t GetLongLength(int dimension)
Returns the number of elements in the specified dimension as 64-bit integer.
Definition: array.h:710
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:1314
static int BinarySearch(System::ArrayPtr< T > arr, const Y &item, const SharedPtr< Collections::Generic::IComparer< Z > > &comparer)
NOT IMPLEMENTED.
Definition: array.h:694
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:1085
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:1215
virtual int get_Count() const override
Returns the size of the array.
Definition: array.h:476
typename System::Details::SelectType< T >::type UnderlyingType
Alias for the type used to represent each element of the array.
Definition: array.h:296
static void Sort(const ArrayPtr< Type > &arr)
Sorts elements in the specified array using default comparer.
Definition: array.h:1370
virtual void RemoveAt(int) override
Not supported because array represented by the current object is read-only.
Definition: array.h:601
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:617
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:1597
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:1162
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:449
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:868
int32_t get_Length() const override
Returns 32-bit integer that represents the total number of all elements in all dimensions of the arra...
Definition: array.h:848
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:1507
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:1204
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:1278
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:1621
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:1097
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:302
int GetUpperBound(int dimension)
Returns the upper bound of the specified dimension.
Definition: array.h:727
void SetTemplateWeakPtr(uint32_t argument) override
Makes array treat stored pointers as weak (if applicable).
Definition: array.h:497
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:1589
virtual void Insert(int, const T &) override
Not supported because array represented by the current object is read-only.
Definition: array.h:594
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:1242
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:1260
const_reverse_iterator crend() const noexcept
Returns a reverse iterator to the element following the last element of the reversed container....
Definition: array.h:1675
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:1380
vector_t::const_iterator const_iterator
Const iterator type.
Definition: array.h:1572
pointer_mode_t m_pointer_mode
Information on whether to treat array elements as shared or weak pointers, if applicable.
Definition: array.h:304
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:401
reverse_iterator rend() noexcept
Returns a reverse iterator to the element following the last element of the reversed container....
Definition: array.h:1657
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:1639
static void Reverse(const ArrayPtr< Type > &arr, int startIndex, int count)
Reverses a range of elements in the specified array.
Definition: array.h:1490
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:1329
Array()
Constructs an empty array.
Definition: array.h:389
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:443
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginIterator() override
Gets the implementation of begin iterator for the current container.
Definition: array.h:1722
int Count() const
Returns a number that represents the total number of all elements in all dimensions of the array.
Definition: array.h:875
UnderlyingType & operator[](int index)
Returns an item at the specified index.
Definition: array.h:645
Interface that compares two objects in greater-equal-less sense. Objects of this class should only be...
Definition: icomparer.h:21
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
Represents a pointer to the method that compares two objects of the same type. This type should be al...
Definition: comparison.h:93
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
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
int get_shared_count() const
Gets number of shared pointers existing to referenced object, including current one....
Definition: smart_ptr.h:803
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:164
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:133
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:376
Adapter to use IComparer within STL environment. Uses IComparer if set; otherwise,...
Definition: icomparer.h:45