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/collections/iread_only_list.h>
16#include <system/exceptions.h>
17#include <system/collections/algorithms.h>
18#include <system/converter.h>
19#include <system/predicate.h>
20#include <system/action.h>
21#include <system/select_type.h>
22#include <system/cycles_detection.h>
23#include <system/comparison.h>
24#include <system/collections/read_only_collection.h>
25
26#include <fwd.h>
27
28#include <map>
29#include <vector>
30#include <functional>
31#include <initializer_list>
32#include <utility>
33#include <limits>
34#include <type_traits>
35#include <algorithm>
36
37#undef min
38#undef max
39
40namespace System { namespace Collections { namespace ObjectModel {
41template<typename> class ReadOnlyCollection;
42}}}
43
44namespace System
45{
46 namespace Details {
47 template <typename X, typename IdxType>
48 inline typename Array<X>::UnderlyingType& GetByIndex(const SmartPtr<Array<X>> *ptr, IdxType idx)
49 {
50 return (**ptr).operator[](static_cast<int>(idx));
51 }
52
55 template <typename Integral, bool = std::numeric_limits<Integral>::is_signed>
56 struct NegativeValueChecker
57 {
61 static void Check(const Integral &value)
62 {
63 if (value < 0)
64 throw System::OverflowException(u"Negative array size");
65 }
66 };
69 template <typename Integral>
70 struct NegativeValueChecker<Integral, false>
71 {
73 static void Check(const Integral&) {}
74 };
75
78 template <typename Integral, bool = (sizeof(Integral) > sizeof(int)) || (!std::numeric_limits<Integral>::is_signed && (sizeof(Integral) == sizeof(int)))>
79 struct IntPositiveOverflowChecker
80 {
84 static void Check(const Integral& value)
85 {
86 if (value >= static_cast<Integral>((std::numeric_limits<int>::max)()))
87 throw System::OverflowException(u"Array size too big for signed integer");
88 }
89 };
92 template <typename Integral>
93 struct IntPositiveOverflowChecker<Integral, false>
94 {
96 static void Check(const Integral &value) { ASPOSE_UNUSED(value); }
97 };
98
104 template <typename Integral>
105 int FixArraySize(const Integral &value)
106 {
107 NegativeValueChecker<Integral>::Check(value);
108 IntPositiveOverflowChecker<Integral>::Check(value);
109 return static_cast<int>(value);
110 }
111 }
112
115
144 template<typename T>
145 ArrayPtr<T> MakeArray(std::initializer_list<T> init)
146 {
147 System::Details::MakeObjectLeakageDetector::SignatureBacktraceSentry signature_sentry;
148 System::Details::MakeObjectLeakageDetector::SetSignature<Array<T>>(init);
149
150 Detail::OwnNextObject ownershipSentry;
151
152 Array<T> *const arr = new Array<T>(init);
153
154 ownershipSentry.CreatedSuccessfully(arr);
155 signature_sentry.CreatedSuccessfully(arr);
156
157 return ArrayPtr<T>(arr);
158 }
159
164 template <class T, class... Args> ArrayPtr<T> MakeArray(Args&&... args)
165 {
166 System::Details::MakeObjectLeakageDetector::SignatureBacktraceSentry signature_sentry;
167 System::Details::MakeObjectLeakageDetector::SetSignature<Array<T>>(std::forward<Args>(args)...);
168
169 Detail::OwnNextObject ownershipSentry;
170
171 Array<T>* const arr = new Array<T>(std::forward<Args>(args)...);
172
173 ownershipSentry.CreatedSuccessfully(arr);
174 signature_sentry.CreatedSuccessfully(arr);
175
176 return ArrayPtr<T>(arr);
177 }
178
185 template <class T, class Integral, class... Args>
186 typename std::enable_if<std::is_integral<Integral>::value, ArrayPtr<T>>::type MakeArray(Integral size, Args&&... args)
187 {
188 System::Details::MakeObjectLeakageDetector::SignatureBacktraceSentry signature_sentry;
189 System::Details::MakeObjectLeakageDetector::SetSignature<Array<T>>(Details::FixArraySize(size), std::forward<Args>(args)...);
190
191 Detail::OwnNextObject ownershipSentry;
192
193 Array<T>* const arr = new Array<T>(Details::FixArraySize(size), std::forward<Args>(args)...);
194
195 ownershipSentry.CreatedSuccessfully(arr);
196 signature_sentry.CreatedSuccessfully(arr);
197
198 return ArrayPtr<T>(arr);
199 }
200
203 class ASPOSECPP_SHARED_CLASS ArrayBase : virtual public Object
204 {
205 typedef ArrayBase ThisType;
206 typedef System::Object BaseType;
207
208 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
209 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
210
211 public:
214 virtual int32_t get_Length() const = 0;
215
218 virtual void* raw_data_ptr() = 0;
219
223 template <typename T>
225 {
226 return MakeArray<T>();
227 }
228 };
229
291 template<typename T>
292 class ASPOSECPP_SHARED_CLASS Array
293 : public ArrayBase
296 {
297 typedef Array<T> ThisType;
299
300 typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
301 RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
302
303 public:
305 using ValueType = T;
307 using UnderlyingType = typename System::Details::SelectType<T>::type;
308
309 protected:
311 typedef System::Details::CollectionHelpers::ContainerPointerMode<UnderlyingType> pointer_mode_t;
313 typedef std::vector<UnderlyingType, typename pointer_mode_t::allocator_type> vector_t;
318#ifdef ASPOSE_GET_SHARED_MEMBERS
319 DEFINE_GET_SHARED_MEMBERS(m_data)
320#endif
321 public:
326
331 class Enumerator : virtual public Object, public Collections::Generic::IEnumerator<T>
332 {
333 RTTI_INFO_TEMPLATE_CLASS(Array<T>::Enumerator, System::BaseTypesInfo<System::Object>);
334
335 private:
337 SharedPtr<Array<T>> m_array;
339 int64_t m_idx;
340
341 public:
344 Enumerator(const SharedPtr<Array<T>>& arr) : m_array(arr), m_idx(-1) { }
345
347 virtual ~Enumerator() {}
348
350 virtual MakeConstRef_t<T> get_Current() const override
351 {
352 return (m_idx < 0 || m_idx >= (int64_t)m_array->m_data.size())
353 ? System::Default<T>()
354 : m_array->m_data[(size_t)m_idx];
355 }
356
360 virtual bool MoveNext() override
361 {
362 if (m_idx < (int64_t)m_array->m_data.size())
363 m_idx++;
364
365 return m_idx < (int64_t)m_array->m_data.size();
366 }
367
369 virtual void Reset() override
370 {
371 m_idx = -1;
372 }
373
374#ifdef __DBG_FOR_EACH_MEMBER
375 public:
378 void DBG_for_each_member(DBG::for_each_member_visitor &visitor) const override
379 {
380 visitor.add_self(this);
381 visitor.add_member(this, m_array.get_shared(), "m_array");
382 }
383
385 const char* DBG_class_name() const override { return "Array<T>::Enumerator"; }
386#endif
387
388 protected:
389#ifdef ASPOSE_GET_SHARED_MEMBERS
391 virtual void GetSharedMembers(System::Object::shared_members_type& result) const override
392 {
393 Object::GetSharedMembers(result);
394 result.Add("System::Array<T>::Enumerator::m_array", m_array);
395 }
396#endif
397 };
398
400 Array() : m_data(m_pointer_mode.GetAllocator()) {}
401
405 Array(int count, const T& init = T()) : m_data(count, static_cast<UnderlyingType>(init), m_pointer_mode.GetAllocator()) { }
406
411 template <typename ValueType>
412 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)
413 : Array(count, ASPOSECPP_CHECKED_CAST(T, init)) {}
414
418 Array(int count, const T inits[]) : m_data(count, static_cast<UnderlyingType>(T()), m_pointer_mode.GetAllocator())
419 {
420 for (int i = 0; i < count; ++i)
421 m_data[i] = inits[i];
422 }
423
426 Array(vector_t&& value) : m_data(std::move(value), m_pointer_mode.GetAllocator()) {}
427
430 Array(const vector_t &assgn) : m_data(assgn, m_pointer_mode.GetAllocator()) {}
431
436 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>
437 Array(const std::vector<Q> &value)
438 : m_data(value.begin(), value.end(), m_pointer_mode.GetAllocator())
439 {}
440
445 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>
446 Array(std::vector<Q> &&value)
447 : m_data(m_pointer_mode.GetAllocator())
448 {
449 m_data.swap(value);
450 }
451
454 Array(std::initializer_list<UnderlyingType> init) : m_data(init, m_pointer_mode.GetAllocator()) {}
455
459 template <std::size_t InitArraySize>
460 Array(const std::array<UnderlyingType, InitArraySize> &init) :
461 Array(init, static_cast<std::make_index_sequence<InitArraySize>*>(nullptr))
462 {}
463
466 Array(std::initializer_list<bool> init, int = 0) : m_data(m_pointer_mode.GetAllocator())
467 {
468 for (auto it = init.begin(); it != init.end(); ++it)
469 m_data.push_back(UnderlyingType(*it));
470 }
471
472 // IEnumerable<T> interface
473
476 virtual EnumeratorPtr GetEnumerator() override
477 {
478 return MakeObject<Enumerator>(std::move(MakeSharedPtr(this)));
479 }
480
481 // end of IEnumerable<T> interface
482
483 // ICollection<T> interface
484 // Note: members which add, insert, or remove elements throw NotSupportedException.
485
487 virtual int get_Count() const override
488 {
489 return get_Length();
490 }
491
494 virtual void Add(const T&) override
495 {
496 throw NotSupportedException(u"Array as ICollection<T>::Add");
497 }
498
501 virtual void Clear() override
502 {
503 throw NotSupportedException(u"Array as ICollection<T>::Clear");
504 }
505
508 void SetTemplateWeakPtr(uint32_t argument) override
509 {
510 m_pointer_mode.SetWeak(argument, m_data);
511 }
512
513private:
518 template <typename Q = T>
519 auto ContainsImpl(const Q* item) const -> decltype(std::declval<UnderlyingType>() == *item, void(0), bool())
520 {
521 return std::find_if(m_data.begin(), m_data.end(),
522 [&item](const T& value) { return Details::AreEqual(value, *item); }) != m_data.end();
523 }
524
527 bool ContainsImpl(...) const
528 {
529 throw NotImplementedException(ASPOSE_CURRENT_FUNCTION);
530 }
531public:
535 virtual bool Contains(const T& item) const override
536 {
537 return ContainsImpl(&item);
538 }
539
542 virtual bool Remove(const T&) override
543 {
544 throw NotSupportedException(u"Array as ICollection<T>::Remove");
545 }
546
547 // Returns True when you cast or converted to an ICollection<T> object,
548 // even though individual array elements can be modified.
549
552 virtual bool get_IsReadOnly() const override
553 {
554 return true;
555 }
556
561 virtual void CopyTo(ArrayPtr<T> arr, int arrayIndex) override
562 {
563 this->CopyTo<T>(arr, static_cast<int64_t>(arrayIndex));
564 }
565
566 // end of ICollection<T> interface
567
568 // IList<T> interface
569private:
570 template <std::size_t ...InitArrayIndexes>
571 Array(const std::array<UnderlyingType, sizeof...(InitArrayIndexes)> &init, std::index_sequence<InitArrayIndexes...>*) :
572 m_data({ init[InitArrayIndexes]... }, m_pointer_mode.GetAllocator()) {}
573
574
579 template <typename Q = T>
580 auto IndexOfImpl(const Q* item) const -> decltype(std::declval<UnderlyingType>() == *item, void(0), int())
581 {
582 auto it = std::find_if(m_data.begin(), m_data.end(), [&item](const T& value) { return Details::AreEqual(value, *item); });
583
584 return (it != m_data.end()) ? static_cast<int>(it - m_data.begin()) : -1;
585 }
586
589 int IndexOfImpl(...) const
590 {
591 throw NotImplementedException(ASPOSE_CURRENT_FUNCTION);
592 }
593
594public:
598 virtual int IndexOf(const T& item) const override
599 {
600 return IndexOfImpl(&item);
601 }
602
605 virtual void Insert(int, const T&) override
606 {
607 throw NotSupportedException(u"Array as IList<T>::Insert");
608 }
609
612 virtual void RemoveAt(int) override
613 {
614 throw NotSupportedException(u"Array as IList<T>::RemoveAt");
615 }
616
620 virtual T idx_get(int index) const override
621 {
622 return operator[](index);
623 }
624
628 virtual void idx_set(int index, T value) override
629 {
630 operator[](index) = value;
631 }
632
633 // end of IList<T> interface
634
638 ArrayPtr<T> Init(const T inits[])
639 {
640 for (size_t i = 0; i < m_data.size(); ++i)
641 m_data[i] = inits[i];
642
643 return MakeSharedPtr(this);
644 }
645
648 {
649 for (size_t i = 0; i < m_data.size(); ++i)
650 m_data[i] = T();
651 }
652
657 {
658 using namespace Collections::Generic::Details;
659 if (IsOutOfBounds(index, m_data)) {
660 throw ArgumentOutOfRangeException(u"index");
661 }
662 return m_data[static_cast<typename vector_t::size_type>(index)];
663 }
664
668 UnderlyingType const& operator[](int index) const
669 {
670 using namespace Collections::Generic::Details;
671 if (IsOutOfBounds(index, m_data)) {
672 throw ArgumentOutOfRangeException(u"index");
673 }
674 return m_data[static_cast<typename vector_t::size_type>(index)];
675 }
676
681 {
682 System::ArrayPtr<T> clone = System::MakeObject< System::Array<T> >(static_cast<int>(m_data.size()));
683 std::copy(m_data.begin(), m_data.end(), clone->data().begin());
684 return clone;
685 }
686
689 {
690 return System::MakeObject<Collections::ObjectModel::ReadOnlyCollection<T>>(array);
691 }
692
697 static int BinarySearch(System::ArrayPtr<T> arr, const T &item)
698 {
699 return Collections::Generic::_net_binnary_search(arr->m_data, 0, static_cast<int32_t>(arr->m_data.size()), item);
700 }
701
704 template<typename Y, typename Z>
705 static int BinarySearch(System::ArrayPtr<T> arr, const Y& item, const SharedPtr<Collections::Generic::IComparer<Z>>& comparer)
706 {
707 throw NotImplementedException();
708 }
709
713 int GetLength(int dimension)
714 {
715 return static_cast<int>(GetLongLength(dimension));
716 }
717
721 int64_t GetLongLength(int dimension)
722 {
723 return upper_bound(m_data, dimension) + 1;
724 }
725
729 int GetLowerBound(int dimension) const
730 {
731 ASPOSE_UNUSED(dimension);
732 return 0;
733 }
734
738 int GetUpperBound(int dimension)
739 {
740 return upper_bound(m_data, dimension);
741 }
742
749 template <typename InputType, typename OutputType>
751 {
752 if (!input_array)
753 {
754 throw System::ArgumentNullException(u"arr");
755 }
756
757 if (converter.IsNull())
758 {
759 throw System::ArgumentNullException(u"converter");
760 }
761
762 System::ArrayPtr<OutputType> newArray = System::MakeObject< System::Array<OutputType> >(input_array->get_Length());
763 for (int i = 0; i < input_array->get_Length(); i++)
764 {
765 newArray[i] = converter(input_array[i]);
766 }
767 return newArray;
768 }
769
776 template <typename InputType, typename OutputType>
777 static ArrayPtr<OutputType> ConvertAll(ArrayPtr<InputType> input_array, std::function<OutputType(InputType)> converter)
778 {
779 return ConvertAll(input_array, Converter<InputType, OutputType>(converter));
780 }
781
787 {
788 if (!arr || match.IsNull())
789 {
790 throw System::ArgumentNullException(u"arr or match");
791 }
792
793 for (int i = 0; i < arr->get_Length(); i++)
794 {
795 if (match(arr[i]))
796 return i;
797 }
798 return -1;
799 }
800
806 {
807 if (!arr || match.IsNull())
808 {
809 throw System::ArgumentNullException(u"arr or match");
810 }
811
812 for (auto val: arr->m_data)
813 if (match(val))
814 return val;
815 return T();
816 }
817
823 {
824 if (!arr || match.IsNull())
825 {
826 throw System::ArgumentNullException(u"arr or match");
827 }
828
829 System::ArrayPtr<T> result = System::MakeObject<System::Array<T>>();
830
831 for (auto val : arr->m_data)
832 if (match(val))
833 result->data().push_back(val);
834
835 return result;
836 }
837
843 {
844 if (!arr || match.IsNull())
845 {
846 throw System::ArgumentNullException(u"arr or match");
847 }
848 for (auto val : arr->m_data)
849 if (!match(val))
850 return false;
851 return true;
852 }
853
855 int32_t get_Rank() const { throw System::NotImplementedException(ASPOSE_CURRENT_FUNCTION); };
856
859 int32_t get_Length() const override
860 {
861 //TODO IF the array is multidimensional THEN OverflowException
862 const int64_t len64 = get_LongLength();
863
864 if (len64 > (std::numeric_limits<int32_t>::max)()) {
865 throw OverflowException();
866 }
867 return static_cast<int32_t>(len64);
868 }
869
872 int64_t get_LongLength() const
873 {
874 return GetSizeTLength();
875 }
876
879 size_t GetSizeTLength() const
880 {
881 return recursive_size(m_data);
882 }
883
886 int Count() const { return get_Length(); }
887
893 template<typename DstType>
894 void CopyTo(const ArrayPtr<DstType> &dstArray, int64_t dstIndex) const
895 {
896 this->CopyTo(dstArray, 0, dstIndex, GetSizeTLength());
897 }
898
904 template<typename DstType>
905 void CopyTo(const System::Details::ArrayView<DstType> &dstArray, int64_t dstIndex) const
906 {
907 this->CopyTo(dstArray, 0, dstIndex, GetSizeTLength());
908 }
909
918 template<typename DstType>
919 void CopyTo(const ArrayPtr<DstType> &dstArray, int64_t srcIndex, int64_t dstIndex, int64_t count) const
920 {
921 using namespace Collections::Generic::Details;
922
923 if (!dstArray) {
924 throw ArgumentNullException(u"dstArray");
925 }
926 if (srcIndex < 0 || dstIndex < 0 || count < 0) {
927 throw ArgumentOutOfRangeException(u"srcIndex, dstIndex or count");
928 }
929 if (IsOutOfSize(srcIndex + count, m_data)
930 || IsOutOfSize(dstIndex + count, dstArray->data())) {
931 throw ArgumentException(u"srcIndex, dstIndex or count");
932 }
933
934 // casts are safe because bounds have already checked.
935
936 if (dstArray.GetObjectOrNull() == (Object*)(this) && dstIndex > srcIndex && dstIndex < srcIndex + count)
937 {
938 std::copy_backward(
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->data().begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, dstIndex) + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, count)
942 );
943 }
944 else
945 {
946 std::copy(
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->data().begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, dstIndex)
950 );
951 }
952 }
953
962 template<typename DstType>
963 void CopyTo(const System::Details::ArrayView<DstType> &dstArray, int64_t srcIndex, int64_t dstIndex, int64_t count) const
964 {
965 using namespace Collections::Generic::Details;
966
967 if (!dstArray) {
968 throw ArgumentNullException(u"dstArray");
969 }
970 if (srcIndex < 0 || dstIndex < 0 || count < 0) {
971 throw ArgumentOutOfRangeException(u"srcIndex, dstIndex or count");
972 }
973 if (IsOutOfSize(srcIndex + count, m_data)
974 || dstIndex + count > dstArray.get_Length()) {
975 throw ArgumentException(u"srcIndex, dstIndex or count");
976 }
977
978 if (dstArray.data() == this->data().data()
979 && dstIndex > srcIndex && dstIndex < srcIndex + count)
980 {
981 std::copy_backward(
982 m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex)
983 , m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex) + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, count)
984 , dstArray.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, dstIndex) + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, count)
985 );
986 }
987 else
988 {
989 std::copy(
990 m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex)
991 , m_data.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, srcIndex) + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, count)
992 , dstArray.begin() + ASPOSECPP_CHECKED_CAST(std::ptrdiff_t, dstIndex)
993 );
994 }
995 }
996
1000 static void ForEach(const ArrayPtr<T>& arr, System::Action<T> action)
1001 {
1002 if (action.IsNull())
1003 throw ArgumentNullException(u"action");
1004
1005 for (auto val : arr->m_data)
1006 action(val);
1007 }
1008
1015 template<typename ArrayType, typename ValueType>
1016 static int IndexOf(const ArrayPtr<ArrayType> &arr, const ValueType& value)
1017 {
1018 return IndexOf(arr, value, 0);
1019 }
1020
1028 template<typename ArrayType, typename ValueType>
1029 static int IndexOf(const ArrayPtr<ArrayType> &arr, const ValueType& value, int startIndex)
1030 {
1031 return IndexOf(arr, value, startIndex, arr->get_Length() - startIndex);
1032 }
1033
1042 template<typename ArrayType, typename ValueType>
1043 static int IndexOf(const ArrayPtr<ArrayType> &arr, const ValueType& value, int startIndex, int count)
1044 {
1045 using namespace Collections::Generic::Details;
1046 if (!arr) {
1047 throw ArgumentNullException(u"arr");
1048 }
1049 if (startIndex < 0 || count < 0 || IsOutOfSize(startIndex + count, arr->data())) {
1050 throw ArgumentOutOfRangeException(u"startIndex or count");
1051 }
1052
1053 auto begin = arr->data().begin() + startIndex;
1054 auto end = begin + count;
1055 auto it =
1056 std::find_if(begin, end, [&value](const ArrayType& item) { return Details::AreEqual(item, value); });
1057
1058 return (it != end) ? static_cast<int>(it - arr->data().begin()) : -1;
1059 }
1060
1069 template<typename ArrayType, typename ValueType>
1070 static int LastIndexOf(const ArrayPtr<ArrayType>& arr, const ValueType& value, int startIndex, int count)
1071 {
1072 using namespace Collections::Generic::Details;
1073 if (!arr) {
1074 throw ArgumentNullException(u"arr");
1075 }
1076 if (startIndex < 0 || count < 0
1077 || IsOutOfSize(startIndex, arr->data()) || IsOutOfSize(count, arr->data())
1078 || (startIndex - count + 1) < 0) {
1079 throw ArgumentOutOfRangeException(u"startIndex or count");
1080 }
1081 auto rbegin = arr->data().rbegin() + arr->data().size() - startIndex - 1;
1082 auto rend = rbegin + count;
1083 auto rit = std::find_if(rbegin, rend, [&value](const ArrayType& item) { return Details::AreEqual(item, value); });
1084
1085 return (rit != rend) ? ASPOSECPP_CHECKED_CAST(int, rit.base() - arr->data().begin() - 1) : -1;
1086 }
1087
1095 template<typename ArrayType, typename ValueType>
1096 static int LastIndexOf(const ArrayPtr<ArrayType>& items, const ValueType& value, int startIndex)
1097 {
1098 return LastIndexOf(items, value, startIndex, (items->get_Length() == 0) ? 0 : startIndex + 1);
1099 }
1100
1107 template<typename ArrayType, typename ValueType>
1108 static int LastIndexOf(const ArrayPtr<ArrayType>& items, const ValueType& value)
1109 {
1110 return LastIndexOf(items, value, items->get_Length() - 1, items->get_Length());
1111 }
1112
1118 template<typename Type>
1119 static void Clear(const ArrayPtr<Type> &arr, int startIndex, int count)
1120 {
1121 using namespace Collections::Generic::Details;
1122 if (!arr) {
1123 throw ArgumentNullException(u"arr");
1124 }
1125 if (startIndex < 0 || count < 0 || IsOutOfSize(startIndex + count, arr->data())) {
1126 throw ArgumentOutOfRangeException(u"startIndex or count");
1127 }
1128
1129 for (auto i = 0; i < count; ++i)
1130 arr->data().at(startIndex + i) = Type();
1131 }
1132
1134 // index and pastes them to another System.Array starting at the specified destination
1135 // index. Guarantees that all changes are undone if the copy does not succeed completely.
1144 template <typename SrcType, typename DstType>
1145 static void ConstrainedCopy(const ArrayPtr<SrcType> &srcArray, int64_t srcIndex,
1146 const ArrayPtr<DstType> &dstArray, int64_t dstIndex, int64_t count)
1147 {
1148 if (!srcArray) {
1149 throw ArgumentNullException(u"srcArray");
1150 }
1151 srcArray->CopyTo(dstArray, srcIndex, dstIndex, count);
1152 }
1153
1158 template<typename SrcType, typename DstType>
1159 static void Copy(const ArrayPtr<SrcType> &srcArray,
1160 const ArrayPtr<DstType> &dstArray, int64_t count)
1161 {
1162 if (!srcArray) {
1163 throw ArgumentNullException(u"srcArray");
1164 }
1165 srcArray->CopyTo(dstArray, 0, 0, count);
1166 }
1167
1172 template<typename SrcType, typename DstType>
1173 static void Copy(System::Details::ArrayView<SrcType> srcArray,
1174 const ArrayPtr<DstType> &dstArray, int64_t count)
1175 {
1176 if (!srcArray) {
1177 throw ArgumentNullException(u"srcArray");
1178 }
1179 srcArray.CopyTo(dstArray, 0, 0, count);
1180 }
1181
1186 template<typename SrcType, typename DstType>
1187 static void Copy(const ArrayPtr<SrcType> &srcArray,
1188 System::Details::ArrayView<DstType> dstArray, int64_t count)
1189 {
1190 if (!srcArray) {
1191 throw ArgumentNullException(u"srcArray");
1192 }
1193 srcArray->CopyTo(dstArray, 0, 0, count);
1194 }
1195
1200 template<typename SrcType, typename DstType>
1201 static void Copy(System::Details::ArrayView<SrcType> srcArray,
1202 System::Details::ArrayView<DstType> dstArray, int64_t count)
1203 {
1204 if (!srcArray) {
1205 throw ArgumentNullException(u"srcArray");
1206 }
1207 srcArray.CopyTo(dstArray, 0, 0, count);
1208 }
1209
1214 template<typename SrcType, std::size_t N, typename DstType>
1215 static void Copy(System::Details::StackArray<SrcType, N> &srcArray,
1216 const ArrayPtr<DstType> &dstArray, int64_t count)
1217 {
1218 Copy(static_cast<System::Details::ArrayView<SrcType> >(srcArray), dstArray, count);
1219 }
1220
1225 template<typename SrcType, typename DstType, std::size_t N>
1226 static void Copy(const ArrayPtr<SrcType> &srcArray,
1227 System::Details::StackArray<DstType, N> &dstArray, int64_t count)
1228 {
1229 Copy(srcArray, static_cast<System::Details::ArrayView<DstType> >(dstArray), count);
1230 }
1231
1236 template<typename SrcType, std::size_t NS, typename DstType, std::size_t ND>
1237 static void Copy(System::Details::StackArray<SrcType, NS> &srcArray,
1238 System::Details::StackArray<DstType, ND> &dstArray, int64_t count)
1239 {
1240 Copy(static_cast<System::Details::ArrayView<SrcType> >(srcArray),
1241 static_cast<System::Details::ArrayView<DstType> >(dstArray), count);
1242 }
1243
1252 template<typename SrcType, typename DstType>
1253 static void Copy(const ArrayPtr<SrcType> &srcArray, int64_t srcIndex,
1254 const ArrayPtr<DstType> &dstArray, int64_t dstIndex, int64_t count)
1255 {
1256 if (!srcArray) {
1257 throw ArgumentNullException(u"srcArray");
1258 }
1259 srcArray->CopyTo(dstArray, srcIndex, dstIndex, count);
1260 }
1261
1270 template<typename SrcType, typename DstType>
1271 static void Copy(System::Details::ArrayView<SrcType> srcArray, int64_t srcIndex,
1272 const ArrayPtr<DstType> &dstArray, int64_t dstIndex, int64_t count)
1273 {
1274 if (!srcArray) {
1275 throw ArgumentNullException(u"srcArray");
1276 }
1277 srcArray.CopyTo(dstArray, srcIndex, dstIndex, count);
1278 }
1279
1288 template<typename SrcType, typename DstType>
1289 static void Copy(const ArrayPtr<SrcType> &srcArray, int64_t srcIndex,
1290 System::Details::ArrayView<DstType> dstArray, int64_t dstIndex, int64_t count)
1291 {
1292 if (!srcArray) {
1293 throw ArgumentNullException(u"srcArray");
1294 }
1295 srcArray->CopyTo(dstArray, srcIndex, dstIndex, count);
1296 }
1297
1306 template<typename SrcType, typename DstType>
1307 static void Copy(System::Details::ArrayView<SrcType> srcArray, int64_t srcIndex,
1308 System::Details::ArrayView<DstType> dstArray, int64_t dstIndex, int64_t count)
1309 {
1310 if (!srcArray) {
1311 throw ArgumentNullException(u"srcArray");
1312 }
1313 srcArray.CopyTo(dstArray, srcIndex, dstIndex, count);
1314 }
1315
1324 template<typename SrcType, std::size_t N, typename DstType>
1325 static void Copy(System::Details::StackArray<SrcType, N> &srcArray, int64_t srcIndex,
1326 const ArrayPtr<DstType> &dstArray, int64_t dstIndex, int64_t count)
1327 {
1328 Copy(static_cast<System::Details::ArrayView<SrcType> >(srcArray), srcIndex, dstArray, dstIndex, count);
1329 }
1330
1339 template<typename SrcType, typename DstType, std::size_t N>
1340 static void Copy(const ArrayPtr<SrcType> &srcArray, int64_t srcIndex,
1341 System::Details::StackArray<DstType, N> &dstArray, int64_t dstIndex, int64_t count)
1342 {
1343 Copy(srcArray, srcIndex, static_cast<System::Details::ArrayView<DstType> >(dstArray), dstIndex, count);
1344 }
1345
1354 template<typename SrcType, std::size_t NS, typename DstType, std::size_t ND>
1355 static void Copy(System::Details::StackArray<SrcType, NS> &srcArray, int64_t srcIndex,
1356 System::Details::StackArray<DstType, ND> &dstArray, int64_t dstIndex, int64_t count)
1357 {
1358 Copy(static_cast<System::Details::ArrayView<SrcType>>(srcArray), srcIndex,
1359 static_cast<System::Details::ArrayView<DstType>>(dstArray), dstIndex, count);
1360 }
1361
1370 template<typename SrcType, typename DstType, std::size_t ND>
1371 static void Copy(System::Details::ArrayView<SrcType> &srcArray, int64_t srcIndex,
1372 System::Details::StackArray<DstType, ND> &dstArray, int64_t dstIndex, int64_t count)
1373 {
1374 Copy(srcArray, srcIndex,
1375 static_cast<System::Details::ArrayView<DstType>>(dstArray), dstIndex, count);
1376 }
1377
1380 template<typename Type>
1381 static void Sort(const ArrayPtr<Type> &arr)
1382 {
1383 Sort(arr, 0, arr->get_Length());
1384 }
1385
1390 template<typename Type>
1391 static void Sort(const ArrayPtr<Type> &arr, int startIndex, int count)
1392 {
1393 using namespace Collections::Generic::Details;
1394 if (!arr) {
1395 throw ArgumentNullException(u"arr");
1396 }
1397 if (startIndex < 0 || count < 0 || IsOutOfSize(startIndex + count, arr->data())) {
1398 throw ArgumentOutOfRangeException(u"startIndex or count");
1399 }
1400
1401 auto begin = arr->data().begin() + startIndex;
1402 auto end = begin + count;
1403
1404 std::sort(begin, end, Collections::Generic::Details::ComparerType<Type>());
1405 }
1406
1410 template<typename Type>
1412 {
1413 Collections::Generic::ComparerAdapter<T> adapter(comparator);
1414 std::sort(arr->data().begin(), arr->data().end(), adapter);
1415 }
1416
1419 template<typename Type, typename Y>
1421 {
1422 throw NotImplementedException();
1423 }
1424
1426 template<typename Type>
1427 static void Sort(const ArrayPtr<Type>& arr, const System::Comparison<T>& comparison)
1428 {
1429 std::sort(arr->data().begin(), arr->data().end(), comparison);
1430 }
1431
1438 template<typename TKey, typename TValue>
1439 static void Sort(const ArrayPtr<TKey>& keys, const ArrayPtr<TValue>& items)
1440 {
1441 if (keys == nullptr)
1442 throw ArgumentNullException(u"keys");
1443
1444 Sort(keys, items, 0, keys->get_Length());
1445 }
1446
1455 template<typename TKey, typename TValue>
1456 static void Sort(const ArrayPtr<TKey>& keys, const ArrayPtr<TValue>& items, int index, int length)
1457 {
1458 if (keys == nullptr)
1459 throw ArgumentNullException(u"keys");
1460 if (index < 0 || length < 0)
1461 throw ArgumentOutOfRangeException(length < 0 ? u"length" : u"index");
1462 if (index + length > keys->Count() || (items != nullptr && index + length > items->Count()))
1463 throw ArgumentException();
1464
1465 if (items == nullptr)
1466 {
1467 typename std::vector<TKey>::iterator keys_begin = keys->data().begin() + index;
1468 typename std::vector<TKey>::iterator keys_end = keys_begin + length;
1469
1470 std::sort(keys_begin, keys_end, Collections::Generic::Details::ComparerType<TKey>());
1471 }
1472 else
1473 {
1474 // Sorting keys and items via multimap
1475 std::multimap<TKey, TValue, Collections::Generic::Details::ComparerType<TKey>> map;
1476 for (int i = index; i < index + length; ++i)
1477 map.insert(std::make_pair(keys[i], items[i]));
1478
1479 auto map_iter = map.begin();
1480 for (int i = index; (i < index + length) && (map_iter != map.end()); ++i, ++map_iter)
1481 {
1482 keys[i] = map_iter->first;
1483 items[i] = map_iter->second;
1484 }
1485 }
1486 }
1487
1490 template<typename Type>
1491 static void Reverse(const ArrayPtr<Type> &arr)
1492 {
1493 std::reverse(arr->m_data.begin(), arr->m_data.end());
1494 }
1495
1500 template<typename Type>
1501 static void Reverse(const ArrayPtr<Type> &arr, int startIndex, int count)
1502 {
1503 using namespace Collections::Generic::Details;
1504 if (!arr) {
1505 throw ArgumentNullException(u"arr");
1506 }
1507 if (startIndex < 0 || count < 0 || IsOutOfSize(startIndex + count, arr->data())) {
1508 throw ArgumentOutOfRangeException(u"startIndex or count");
1509 }
1510
1511 std::reverse(arr->m_data.begin() + startIndex, arr->m_data.begin() + startIndex + count);
1512 }
1513
1517 template<typename Type>
1518 static void Resize(ArrayPtr<Type> &arr, int new_size)
1519 {
1520 if (new_size < 0)
1521 throw ArgumentOutOfRangeException(u"new_size");
1522
1523 if (arr)
1524 {
1525 // Array is present, so we need to resize it
1526 if (arr.get_shared_count() != 1)
1527 {
1528 // Array is shared between some variables, so we need to create new one of needed size
1529 auto new_array = MakeObject<Array<T>>(new_size);
1530 std::copy(arr->data_ptr(), arr->data_ptr() + (std::ptrdiff_t)std::min(new_size, arr->get_Length()), new_array->data_ptr());
1531 arr = new_array;
1532 }
1533 else
1534 {
1535 // Array is owned only by this variable, so we probably can just resize its data
1536 arr->m_data.resize((typename vector_t::size_type)new_size);
1537 }
1538 }
1539 else
1540 {
1541 // No array present, we just need to create new one
1542 arr = MakeObject<Array<T>>(new_size);
1543 }
1544 }
1545
1549 void SetValue(const T &value, int index)
1550 {
1551 using namespace Collections::Generic::Details;
1552 if (IsOutOfBounds(index, m_data)) {
1553 throw ArgumentOutOfRangeException(u"index");
1554 }
1555 m_data[index] = value;
1556 }
1557
1559 vector_t& data() { return m_data; }
1560
1562 const vector_t& data() const { return m_data; }
1563
1565 typename vector_t::pointer data_ptr() // VS2013 std::vector has no data() member
1566 {
1567 if(m_data.empty())
1568 return nullptr;
1569
1570 return &m_data[0];
1571 }
1572
1574 const UnderlyingType * data_ptr() const { return data_ptr(); }
1575
1578 void* raw_data_ptr() override { return data_ptr(); }
1579
1581 typedef typename vector_t::iterator iterator;
1583 typedef typename vector_t::const_iterator const_iterator;
1585 typedef typename vector_t::reverse_iterator reverse_iterator;
1587 typedef typename vector_t::const_reverse_iterator const_reverse_iterator;
1588
1592 iterator begin() noexcept
1593 {
1594 return m_data.begin();
1595 }
1596
1600 const_iterator begin() const noexcept
1601 {
1602 return m_data.begin();
1603 }
1604
1608 const_iterator cbegin() const noexcept
1609 {
1610 return m_data.cbegin();
1611 }
1612
1616 iterator end() noexcept
1617 {
1618 return m_data.end();
1619 }
1620
1624 const_iterator end() const noexcept
1625 {
1626 return m_data.end();
1627 }
1628
1632 const_iterator cend() const noexcept
1633 {
1634 return m_data.cend();
1635 }
1636
1642 {
1643 return m_data.rbegin();
1644 }
1645
1651 {
1652 return m_data.rbegin();
1653 }
1654
1660 {
1661 return m_data.crbegin();
1662 }
1663
1669 {
1670 return m_data.rend();
1671 }
1672
1678 {
1679 return m_data.rend();
1680 }
1681
1687 {
1688 return m_data.crend();
1689 }
1690
1691 // int get_Count() const; - see ICollection<T> interface
1692 // void Add(const T& item); - see ICollection<T> interface
1693 // void Clear(); - see ICollection<T> interface
1694 // bool Contains(const T& item) const; - see ICollection<T> interface
1695 // bool Remove(const T& item); - see ICollection<T> interface
1696
1697 // IList interface
1698
1699 // int IndexOf(const T& item) const; - see IList<T> interface
1700 // void Insert(int index, const T& item); - see IList<T> interface
1701 // void RemoveAt(int index); - see IList<T> interface
1702
1703 // IEnumerable interface
1707 {
1708 return *std::min_element(m_data.cbegin(), m_data.cend());
1709 }
1710
1714 {
1715 return *std::max_element(m_data.cbegin(), m_data.cend());
1716 }
1717
1722 static bool Exists(ArrayPtr<T> arr, std::function<bool(T)> match)
1723 {
1724 for (int i = 0; i < arr->get_Length(); i++)
1725 {
1726 if (match(arr[i]))
1727 return true;
1728 }
1729 return false;
1730 }
1731
1733 System::Details::VirtualizedIteratorBase<T>* virtualizeBeginIterator() override
1734 {
1735 return new System::Details::NativeIteratorWrapper<T, iterator>(begin(), end());
1736 }
1738 System::Details::VirtualizedIteratorBase<T>* virtualizeEndIterator() override
1739 {
1740 return new System::Details::NativeIteratorWrapper<T, iterator>(end(), end());
1741 }
1743 System::Details::VirtualizedIteratorBase<T>* virtualizeBeginConstIterator() const override
1744 {
1745 return new System::Details::NativeConstIteratorWrapper<T, const_iterator>(begin(), end());
1746 }
1748 System::Details::VirtualizedIteratorBase<T>* virtualizeEndConstIterator() const override
1749 {
1750 return new System::Details::NativeConstIteratorWrapper<T, const_iterator>(end(), end());
1751 }
1752
1753private:
1759 template <typename ErrType>
1760 static int upper_bound(ErrType arr, int dim)
1761 {
1762 ASPOSE_UNUSED(arr);
1763 ASPOSE_UNUSED(dim);
1764 throw System::IndexOutOfRangeException();
1765 }
1772 template <typename VType, typename Alloc>
1773 static int upper_bound(const std::vector<VType, Alloc> &arr, int dim)
1774 {
1775 if (!dim)
1776 return (int)arr.size() - 1;
1777
1778 if (!arr.size())
1779 return -1;
1780
1781 return upper_bound(arr[0], dim - 1);
1782 }
1783
1789 template <typename U, typename Alloc>
1790 static size_t recursive_size(const std::vector<U, Alloc>& v)
1791 {
1792 return v.size();
1793 }
1794
1802 template <typename U, typename Alloc1, typename Alloc2>
1803 static size_t recursive_size(const std::vector<std::vector<U, Alloc1>, Alloc2>& v)
1804 {
1805 size_t rv = 0;
1806 for (const auto &i : v)
1807 rv += recursive_size(i);
1808
1809 return rv;
1810 }
1811
1812protected:
1814 ~Array() override {}
1815
1816#ifdef __DBG_FOR_EACH_MEMBER
1817 public:
1820 void DBG_for_each_member(DBG::for_each_member_visitor &visitor) const override
1821 {
1822 visitor.add_self(this);
1823 DBG::for_each_of_Object(this, m_data, visitor);
1824 }
1826 const char* DBG_class_name() const override { return "Array<T>"; }
1827#endif
1828 };
1831 template <typename TTo>
1832 struct CastResult<Array<TTo>>
1833 {
1835 typedef ArrayPtr<TTo> type;
1836 };
1838
1839
1840 namespace Details {
1844 template <typename T>
1845 inline Array<T>* CreateArray(Array<T>*)
1846 {
1847 return new Array<T>(0);
1848 }
1849
1850 } // namespace Details
1851
1852} // namespace System
1853
1854#endif // _aspose_system_array_h_
Implements IEnumerator interface that enables enumeration of elements of an Array object....
Definition: array.h:332
virtual ~Enumerator()
Destructor.
Definition: array.h:347
Enumerator(const SharedPtr< Array< T > > &arr)
Constructs a new Enumerator object that represents the specified array.
Definition: array.h:344
virtual MakeConstRef_t< T > get_Current() const override
Returns a copy of the current element.
Definition: array.h:350
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:360
virtual void Reset() override
Resets the current element's index.
Definition: array.h:369
The dummy for System.Array class (abstract base class for all arrays) May be filled with functionalit...
Definition: array.h:204
static ArrayPtr< T > Empty()
Returns an empty array.
Definition: array.h:224
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:296
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:822
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:1119
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:777
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:1659
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:1016
void SetValue(const T &value, int index)
Sets value of the element at specified index.
Definition: array.h:1549
SharedPtr< Collections::Generic::IEnumerator< T > > EnumeratorPtr
An alias for shared pointer type pointing to IEnumerator object containing elements of type T.
Definition: array.h:325
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:1145
vector_t::iterator iterator
Iterator type.
Definition: array.h:1581
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:1411
reverse_iterator rbegin() noexcept
Returns a reverse iterator to the first element of the reversed container. It corresponds to the last...
Definition: array.h:1641
UnderlyingType Min() const
Finds the smallest element in the array using operator<() to compare elements.
Definition: array.h:1706
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:446
virtual bool Contains(const T &item) const override
Determines if the specified item is in the array.
Definition: array.h:535
vector_t::const_reverse_iterator const_reverse_iterator
Const reverse iterator type.
Definition: array.h:1587
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:1574
~Array() override
Destructor.
Definition: array.h:1814
virtual void Clear() override
Not supported because the array represented by the current object is read-only.
Definition: array.h:501
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:1307
iterator begin() noexcept
Returns an iterator to the first element of the container. If the container is empty,...
Definition: array.h:1592
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:598
static void Sort(const ArrayPtr< Type > &arr, const SharedPtr< System::Collections::Generic::IComparer< Y > > &comparator)
NOT IMPLEMENTED.
Definition: array.h:1420
vector_t m_data
The storage for array's elements.
Definition: array.h:317
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:805
ArrayPtr< T > Init(const T inits[])
Fills the array represented by the current object with the values from the specified array.
Definition: array.h:638
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:1456
int GetLength(int dimension)
Returns the number of elements in the specified dimension.
Definition: array.h:713
virtual EnumeratorPtr GetEnumerator() override
Returns a pointer to Enumerator object that provides IEnumerator interface to elements of the array r...
Definition: array.h:476
Array(vector_t &&value)
Move constructor.
Definition: array.h:426
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:1565
static void Reverse(const ArrayPtr< Type > &arr)
Reverses elements in the specified array.
Definition: array.h:1491
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:1355
const vector_t & data() const
Returns a constant reference to the internal data structure used to store the array elements.
Definition: array.h:1562
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:1371
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:466
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:1043
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:1187
SharedPtr< Collections::Generic::IEnumerable< T > > EnumerablePtr
An alias for shared pointer type pointing to IEnumerable object containing elements of type T.
Definition: array.h:323
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:437
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:311
void * raw_data_ptr() override
Returns pointer to the first element of single-dimension array. For multi-dimensional arrays result u...
Definition: array.h:1578
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:919
System::Details::VirtualizedIteratorBase< T > * virtualizeEndConstIterator() const override
Gets the implementation of end const iterator for the current container.
Definition: array.h:1748
ArrayPtr< T > Clone()
Clones the array.
Definition: array.h:680
virtual void Add(const T &) override
Not supported because the array represented by the current object is read-only.
Definition: array.h:494
vector_t & data()
Returns a reference to the internal data structure used to store the array elements.
Definition: array.h:1559
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:894
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:905
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:963
virtual bool Remove(const T &) override
Not supported because the array represented by the current object is read-only.
Definition: array.h:542
const_reverse_iterator rend() const noexcept
Returns a reverse iterator to the element following the last element of the reversed container....
Definition: array.h:1677
Array(const vector_t &assgn)
Copy constructor.
Definition: array.h:430
iterator end() noexcept
Returns an iterator to the element following the last element of the container. This element acts as ...
Definition: array.h:1616
static int BinarySearch(System::ArrayPtr< T > arr, const T &item)
Performs binary search in the sorted array.
Definition: array.h:697
UnderlyingType Max() const
Finds the largest element in the array using operator<() to compare elements.
Definition: array.h:1713
int32_t get_Rank() const
NOT IMPLEMENTED.
Definition: array.h:855
const_iterator end() const noexcept
Returns an iterator to the element following the last element of the const-qualified container....
Definition: array.h:1624
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:750
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:1029
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:1722
T ValueType
Alias for the type of the elements of the array.
Definition: array.h:305
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:1201
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:842
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:786
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:1070
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:1159
vector_t::reverse_iterator reverse_iterator
Reverse iterator type.
Definition: array.h:1585
Array(int count, const T &init=T())
Filling constructor.
Definition: array.h:405
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:872
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:1237
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginConstIterator() const override
Gets the implementation of begin const iterator for the current container.
Definition: array.h:1743
static void Sort(const ArrayPtr< Type > &arr, const System::Comparison< T > &comparison)
Sorts elements in the specified array using specified comparison.
Definition: array.h:1427
UnderlyingType const & operator[](int index) const
Returns an item at the specified index.
Definition: array.h:668
static SharedPtr< Collections::ObjectModel::ReadOnlyCollection< T > > AsReadOnly(const SharedPtr< Array< T > > &array)
Casts array to read only collection.
Definition: array.h:688
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:561
virtual bool get_IsReadOnly() const override
Indicates whether the array is read-only.
Definition: array.h:552
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:1439
void Initialize()
Fills the array with the default constructed objects of type T.
Definition: array.h:647
Array(int count, const T inits[])
Filling constructor.
Definition: array.h:418
virtual T idx_get(int index) const override
Returns the item at the specified index.
Definition: array.h:620
int GetLowerBound(int dimension) const
Returns the lower bound of the specified dimension.
Definition: array.h:729
System::Details::VirtualizedIteratorBase< T > * virtualizeEndIterator() override
Gets the implementation of end iterator for the current container.
Definition: array.h:1738
static void ForEach(const ArrayPtr< T > &arr, System::Action< T > action)
Performs specified action on each element of the specified array.
Definition: array.h:1000
int64_t GetLongLength(int dimension)
Returns the number of elements in the specified dimension as 64-bit integer.
Definition: array.h:721
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:1325
static int BinarySearch(System::ArrayPtr< T > arr, const Y &item, const SharedPtr< Collections::Generic::IComparer< Z > > &comparer)
NOT IMPLEMENTED.
Definition: array.h:705
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:1096
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:1226
virtual int get_Count() const override
Returns the size of the array.
Definition: array.h:487
typename System::Details::SelectType< T >::type UnderlyingType
Alias for the type used to represent each element of the array.
Definition: array.h:307
static void Sort(const ArrayPtr< Type > &arr)
Sorts elements in the specified array using default comparer.
Definition: array.h:1381
virtual void RemoveAt(int) override
Not supported because array represented by the current object is read-only.
Definition: array.h:612
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:628
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:1608
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:1173
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:460
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:879
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:859
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:1518
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:1215
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:1289
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:1632
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:1108
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:313
int GetUpperBound(int dimension)
Returns the upper bound of the specified dimension.
Definition: array.h:738
void SetTemplateWeakPtr(uint32_t argument) override
Makes array treat stored pointers as weak (if applicable).
Definition: array.h:508
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:1600
virtual void Insert(int, const T &) override
Not supported because array represented by the current object is read-only.
Definition: array.h:605
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:1253
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:1271
const_reverse_iterator crend() const noexcept
Returns a reverse iterator to the element following the last element of the reversed container....
Definition: array.h:1686
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:1391
vector_t::const_iterator const_iterator
Const iterator type.
Definition: array.h:1583
pointer_mode_t m_pointer_mode
Information on whether to treat array elements as shared or weak pointers, if applicable.
Definition: array.h:315
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:412
reverse_iterator rend() noexcept
Returns a reverse iterator to the element following the last element of the reversed container....
Definition: array.h:1668
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:1650
static void Reverse(const ArrayPtr< Type > &arr, int startIndex, int count)
Reverses a range of elements in the specified array.
Definition: array.h:1501
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:1340
Array()
Constructs an empty array.
Definition: array.h:400
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:454
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginIterator() override
Gets the implementation of begin iterator for the current container.
Definition: array.h:1733
int Count() const
Returns a number that represents the total number of all elements in all dimensions of the array.
Definition: array.h:886
UnderlyingType & operator[](int index)
Returns an item at the specified index.
Definition: array.h:656
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:20
Interface of read-only indexed container of elements. Objects of this class should only be allocated ...
Definition: iread_only_list.h:18
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:828
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:820
Object * GetObjectOrNull() const
Gets pointed object (if any) or nullptr. Same as get().
Definition: smart_ptr.h:773
int get_shared_count() const
Gets number of shared pointers existing to referenced object, including current one....
Definition: smart_ptr.h:793
Pointee_ * get_shared() const
Gets pointed object, but asserts that pointer is in shared mode.
Definition: smart_ptr.h:514
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:145
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:1640
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:114
System::ExceptionWrapper< Details_ArgumentException > ArgumentException
Definition: throw_helper.h:23
class ASPOSECPP_SHARED_CLASS Array
Definition: smart_ptr.h:22
System::ExceptionWrapper< Details_ArgumentOutOfRangeException > ArgumentOutOfRangeException
Definition: throw_helper.h:24
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