acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
pointer_array.h
1#pragma once
2
3
4//#include "pointer_array_process.h"
5#include "acme/prototype/collection/array_base.h"
6//#include "acme/prototype/prototype/pointer.h"
7//#include "comparable_eq_array.h"
8//#include "comparable_array.h"
9
10
11
12
13
14template < class T, typename ARG_T, typename ARRAY_BASE >
15class pointer_array_base :
16 public ø < pointer_array_process < comparable_array_base < ::pointer < T >, ARG_T, comparable_eq_array_base < ::pointer < T >, ARG_T, ARRAY_BASE > > , T > >
17{
18public:
19
20 using BASE_ARRAY = ø < pointer_array_process < comparable_array_base < ::pointer < T >, ARG_T, comparable_eq_array_base < ::pointer < T >, ARG_T, ARRAY_BASE > > , T > >;
21 using MAIN_TYPE = T;
22 //using ref_iterator = typename ARRAY_BASE::ref_iterator;
24
25 //using comparable_array < ::pointer < T >, const T * >::operator &=;
26 //using comparable_array < ::pointer < T >, const T * >::operator -=;
27 //using comparable_array < ::pointer < T >, const T * >::operator |=;
28 //using comparable_array < ::pointer < T >, const T * >::operator -;
29// using comparable_array < ::pointer<T > > ::operator ==;
30// using comparable_array < ::pointer<T > > ::operator !=;
31
32 using BASE_ARRAY::BASE_ARRAY;
33 using BASE_ARRAY::operator =;
34
35 // pointer_array_base()
36 // {
37 //
38 // }
39 //
40 //
41 // explicit pointer_array_base(nullptr_t)
42 // {
43 //
44 // }
45 //
46 //
47 // virtual ~pointer_array_base()
48 // {
49 //
50 // this->erase_all();
51 //
52 // }
53 //
54 //
55 // pointer_array_base(const pointer_array_base & a) : BASE_ARRAY(a) { }
56 //
57 // pointer_array_base(pointer_array_base && a) : BASE_ARRAY(::transfer(a)) { }
58
59
60 template < typename OTHER >
61 pointer_array_base(const pointer_array_base < OTHER > & a)
62 {
63
64 for(auto & p : a)
65 {
66
67 pointer < T > pNew = p;
68
69 if(pNew)
70 {
71
72 add(pNew);
73
74 }
75
76 }
77
78 }
79
80
81 // pointer_array_base(const std::initializer_list < ::pointer<T >>& list_base)
82 // {
83 //
84 // for(auto & p : list_base)
85 // {
86 //
87 // add(p);
88 //
89 // }
90 //
91 // }
92
93
94 pointer < T >& add_new()
95 {
96
97 return BASE_ARRAY::add_new();
98
99 }
100
101
102 template < typename OBJECT >
103 pointer < T > & add_construct(OBJECT * pparticle)
104 {
105
106 pointer < T > & p = BASE_ARRAY::add_new();
107
108 pparticle->constructø(p);
109
110 return p;
111
112 }
113
114
115 template < typename... Args >
116 pointer<T> & main_add(Args... args)
117 {
118
119 auto pNew = allocateø T (args...);
120
121 auto iIndex = this->add(pNew);
122
123 return this->element_at(iIndex);
124
125 }
126
127
128
129 ::collection::count set_size(::collection::count nNewSize, ::collection::count nGrowBy = -1)
130 {
131
132 return BASE_ARRAY :: set_size(nNewSize);
133
134 }
135
136 template < typename OBJECT >
137 ::collection::count set_size_create(OBJECT * pparticle, ::collection::count nNewSize, ::collection::count nGrowBy = -1);
138
139
140 template < class DERIVED >
141 ::pointer<DERIVED>get(::collection::index iStart = 0)
142 {
143
144 ::pointer<DERIVED>pderived;
145
146 for(::collection::index i = iStart; i < this->get_count(); i++)
147 {
148
149 try
150 {
151
152 pderived = this->element_at(i);
153
154 }
155 catch(...)
156 {
157
158 }
159
160 if (pderived.is_set())
161 {
162
163 return pderived;
164
165 }
166
167 }
168
169 return nullptr;
170
171 }
172
173
174 template < class DERIVED >
175 ::pointer<DERIVED>typed_ptr_at(::collection::index iIndex)
176 {
177
178 return this->element_at(iIndex);
179
180 }
181
182
184 inline ::collection::index add_item(const pointer < T > & p)
185 {
186
187 ::collection::index nIndex = this->size();
188
189 this->allocate(nIndex + 1, false, false, p);
190
191 return nIndex;
192
193 }
194
195
197 inline ::collection::index add_item(pointer < T > && p)
198 {
199
200 ::collection::index nIndex = this->size();
201
202 this->allocate(nIndex + 1, false, false, p);
203
204 return nIndex;
205
206 }
207
208 template < prototype_container CONTAINER >
209 ::collection::index append(const CONTAINER & a)
210 {
211
212 return BASE_ARRAY::append(a);
213
214 }
215
216
217 //::collection::index add(T * p)
218 //{
219
220 // return this->add_item(p);
221
222 //}
223
224
226 ::collection::index add(const pointer < T > & p)
227 {
228
229 return this->add_item(p);
230
231 }
232
233
235 ::collection::index add(pointer < T > && p)
236 {
237
238 return this->add_item(::transfer(p));
239
240 }
241
242
244 ::collection::index add_non_null(T* p)
245 {
246
247 if (::is_null(p))
248 {
249
250 return -1;
251
252 }
253
254 return this->add_item(p);
255
256 }
257
258
260 void insert_at(::collection::index i, T* p)
261 {
262
263 //::collection::index nIndex = this->size();
264
265 BASE_ARRAY::insert_at(i, p);
266
267 //this->element_at(i)->add_reference_item();
268
269 }
270
271
272 bool insert_unique_at(::collection::index i, T * p);
273
274
276 template < typename T2 >
277 bool add_unique(const T2 * p2)
278 {
279
280 if (::is_null(p2))
281 {
282
283 return false;
284
285 }
286
287 auto p = dynamic_cast <T*> ((T2*)p2);
288
289 if (::is_null(p))
290 {
291
292 return false;
293
294 }
295
296 if (contains(p))
297 {
298
299 return false;
300
301 }
302
303 this->add_item(p);
304
305 return true;
306
307 }
308
309
311 template < typename T2 >
312 bool add_unique(const ::pointer < T2 > & p2)
313 {
314
315 return this->add_unique(p2.m_p);
316
317 }
318
319
320 template < typename T2 >
321 ::collection::count add_unique(const pointer_array_base < T2 > & a)
322 {
323
324 ::collection::count c = 0;
325
326 for(auto & p : a)
327 {
328
329 if (this->add_unique(p))
330 {
331
332 c++;
333
334 }
335
336 }
337
338 return c;
339
340 }
341
342
343 template < typename TYPE >
344 ::pointer<TYPE>find_first() const
345 {
346
347 for (auto & pointer : this->ptra())
348 {
349
350 ::pointer<TYPE> ptype = pointer;
351
352 if(ptype)
353 {
354
355 return ptype;
356
357 }
358
359 }
360
361 return nullptr;
362
363 }
364
365 template < typename TYPE >
366 bool contains() const
367 {
368
369 return find_first < TYPE >();
370
371 }
372
373
374 template < typename TYPE >
375 bool has() const
376 {
377
378 return contains < TYPE >();
379
380 }
381
382
383 bool contains(const T * p, ::collection::index iStart = 0, ::collection::count nCount = -1) const
384 {
385
386 return find_first(p, iStart, nCount) >= 0;
387
388 }
389
390
391 ::collection::index find_first(const T * p, ::collection::index iStart = 0, ::collection::count inCountLastOut = -1) const
392 {
393
394 this->prepare_first_in_count_last_out(iStart, inCountLastOut);
395
396 for(::collection::index i = iStart; i <= inCountLastOut; i++)
397 {
398
399 auto& pointer = this->element_at(i);
400
401 if (pointer && pointer.m_p == p)
402 {
403
404 return i;
405
406 }
407
408 }
409
410 return -1;
411
412 }
413
414
415 void call_member(enum_id eid, ::collection::index iStart = 0, ::collection::count inCountLastOut = -1)
416 {
417
418 this->prepare_first_in_count_last_out(iStart, inCountLastOut);
419
420 //::collection::count cFailed = 0;
421
422 //::collection::count cSucceeded = 0;
423
424 for (::collection::index i = iStart; i <= inCountLastOut; i++)
425 {
426
427 auto p = this->element_at(i);
428
429 p->call_member(eid);
430
431 }
432
433 //auto estatus = _003CountStatus(cSucceeded, cFailed);
434
435 //return estatus;
436
437 }
438
439
440 ::collection::index comp_find_first(const T & t, ::collection::index (* pfnCompare)(const T *, const T *), ::collection::index iStart = 0, ::collection::count nCount = -1) const
441 {
442
443 return this->comp_find_first(&t, pfnCompare, iStart, nCount);
444
445 }
446
447
448 ::collection::index comp_find_first(const T * p, ::collection::index (* pfnCompare)(const T *, const T *), ::collection::index iStart = 0, ::collection::count inCountLastOut = -1) const
449 {
450
451 this->prepare_first_in_count_last_out(iStart, inCountLastOut);
452
453 for(::collection::index i = iStart; i <= inCountLastOut; i++)
454 {
455
456 if (pfnCompare(this->element_at(i).m_p, p) == 0)
457 {
458
459 return i;
460
461 }
462
463 }
464
465 return -1;
466
467 }
468
469
470 // template < class DERIVED >
471 // pointer_array_base & operator -= (DERIVED * p)
472 // {
473 //
474 // this->erase(dynamic_cast < T * > (p));
475 //
476 // return *this;
477 //
478 // }
479
480
482 ::collection::count erase(T* p)
483 {
484
485 return this->erase_item(p);
486
487 }
488
489
490 ::collection::count erase_item(T * p)
491 {
492
493 ::collection::count ca = 0;
494
495 ::collection::index iFind = 0;
496
497 while((iFind = this->find_first(p, iFind)) >= 0)
498 {
499
500 ca++;
501
502 this->erase_at(iFind);
503
504 }
505
506 return ca;
507
508 }
509
510
511 //inline const pointer < T > & element_at(::collection::index i) const { return ARRAY_BASE::element_at(i); }
512 //inline pointer < T > & element_at(::collection::index i) { return ARRAY_BASE::element_at(i); }
513
514
515 template < typename TYPE >
516 ::collection::count erase_type(TYPE *)
517 {
518
519 ::collection::count c = 0;
520
521 for (::collection::index i = this->get_upper_bound(); i >= 0; i--)
522 {
523
524 if (typeid(*this->element_at(i).m_p) == ::type<TYPE>())
525 {
526
527 this->erase_at(i);
528
529 c++;
530
531 }
532
533 }
534
535 return c;
536
537 }
538
539
540
541 template < typename PRED >
542 ::collection::index predicate_erase_first(PRED pred, ::collection::index iStart = 0)
543 {
544
545 for (::collection::index i = iStart; i < this->get_count(); i++)
546 {
547
548 if (pred(this->m_begin[i]))
549 {
550
551 this->erase_at(i);
552
553 return i;
554
555 }
556
557 }
558
559 return -1;
560
561 }
562
563
564 template < typename PRED >
565 ::collection::index predicate_erase_last(PRED pred, ::collection::index iStart = 0)
566 {
567
568 for (::collection::index i = this->get_upper_bound(); i >= 0; i--)
569 {
570
571 if (pred(this->m_begin[i]))
572 {
573
574 this->erase_at(i);
575
576 return i;
577
578 }
579
580 }
581
582 return -1;
583
584 }
585
586 template < typename PRED >
587 pointer < T > predicate_erase_all_get_first(PRED pred, ::collection::index iStart = 0, ::collection::index iEnd = -1)
588 {
589
590 pointer < T > sp;
591
592 if (iEnd < 0)
593 {
594
595 iEnd += this->get_count();
596
597 }
598
599 if (iEnd >= this->get_count())
600 {
601
602 iEnd = this->get_count() - 1;
603
604 }
605
606
607 for (::collection::index i = iStart; i <= iEnd;)
608 {
609
610 if (pred(this->m_pData[i]))
611 {
612
613 if (sp.is_null())
614 {
615
616 sp = this->m_pData[i];
617
618 }
619
620 this->erase_at(i);
621
622 }
623 else
624 {
625
626 i++;
627
628 }
629
630 }
631
632 return sp;
633
634 }
635
636
637
638 pointer < T > sp_at(::collection::index nIndex) const
639 {
640
641 if (nIndex < 0 || nIndex >= this->size())
642 {
643
644 return {};
645
646 }
647
648 return this->BASE_ARRAY ::element_at(nIndex);
649
650 }
651
652
653 pointer < T > & sp_at(::collection::index nIndex)
654 {
655
656// if (nIndex < 0 || nIndex >= this->size())
657// {
658//
659// return *((pointer < T > *)nullptr);
660//
661// }
662
663 return this->BASE_ARRAY ::element_at(nIndex);
664
665 }
666
667
668 T * ptr_at(::collection::index nIndex) const
669 {
670
671 if (nIndex < 0 || nIndex >= this->size())
672 {
673
674 return nullptr;
675
676 }
677
678 return this->BASE_ARRAY ::element_at(nIndex).m_p;
679
680 }
681
682
683 T * ptr_at(::collection::index nIndex)
684 {
685
686 return this->sp_at(nIndex);
687
688 }
689
690
691 T & at(::collection::index nIndex) const
692 {
693
694 return *this->ptr_at(nIndex);
695
696 }
697
698
699 T & at(::collection::index nIndex)
700 {
701
702 return *this->ptr_at(nIndex);
703
704 }
705
706 T * get_first_pointer(::collection::index n = 0) const
707 {
708
709 return this->is_empty() ? nullptr : this->comparable_array_base < ::pointer<T >, const T *> ::first(n);
710
711 }
712
713
714 pointer < T > pop_first(::collection::index n = 0)
715 {
716
717 auto p = ::transfer(this->BASE_ARRAY ::first(n));
718
719 this->BASE_ARRAY ::erase_at(n);
720
721 return p;
722
723 }
724
725
726 pointer < T > & first_pointer(::collection::index n = 0)
727 {
728
729 return this->BASE_ARRAY ::first(n);
730
731 }
732
733
734 T * first_ptr(::collection::index n = 0) const
735 {
736
737 if (this->is_empty())
738 {
739
740 return nullptr;
741
742 }
743
744 return this->get_first_pointer(n);
745
746 }
747
748
749 T * first_ptr(::collection::index n = 0)
750 {
751
752 return this->first_pointer(n);
753
754 }
755
756
757 T * get_last_pointer(::collection::index n = -1) const
758 {
759
760 return this->is_empty() ? nullptr : this->BASE_ARRAY ::last(n);
761
762 }
763
764
765 pointer < T > & last_pointer(::collection::index n = -1)
766 {
767
768 return this->BASE_ARRAY ::last(n);
769
770 }
771
772
773 T * last_ptr(::collection::index n = -1) const
774 {
775
776 return this->get_last_pointer(n);
777
778 }
779
780
781 T * last_ptr(::collection::index n = -1)
782 {
783
784 return this->last_pointer(n);
785
786 }
787
788
789 const T & operator() (::collection::index nIndex) const
790 {
791
792 return *this->sp_at(nIndex);
793
794 }
795
796
797 T & operator() (::collection::index nIndex)
798 {
799
800 return *this->sp_at(nIndex);
801
802 }
803
804
805
806 template < typename PRED >
807 T * predicate_ptr_first(PRED pred)
808 {
809
810 ::collection::index i = this->predicate_find_first(pred);
811
812 if(i < 0)
813 return nullptr;
814
815 return this->ptr_at(i);
816
817 }
818
819
820
821 //template < prototype_container ARRAY >
822 //::collection::count add(const ARRAY * pa)
823 //{
824
825 // ::collection::count c = pa->get_count(); // allow to append to itself one time
826
827 // for(::collection::index i = 0; i < c; i++)
828 // {
829 // this->add(pa->element_at(i));
830 // }
831
832 // return c;
833
834 //}
835
836 template < prototype_container ARRAY >
837 ::collection::count add(const ::pointer<ARRAY>& pa)
838 {
839
840 ::collection::count c = pa->get_count(); // allow to append to itself one time
841
842 for(::collection::index i = 0; i < c; i++)
843 {
844 this->add(pa->element_at(i));
845 }
846
847 return c;
848
849 }
850
851 template < prototype_container ARRAY >
852 ::collection::count add(const ARRAY & a)
853 {
854
855 ::collection::count c = a.get_count(); // allow to append to itself one time
856
857 for(::collection::index i = 0; i < c; i++)
858 {
859 this->add(a.element_at(i));
860 }
861
862 return c;
863
864 }
865
866
867 ::collection::count append(const pointer_array_base & a)
868 {
869
870 ::collection::count c = a.get_count(); // allow to append to itself one time
871
872 for(::collection::index i = 0; i < c; i++)
873 {
874
875 this->add(a.sp_at(i));
876
877 }
878
879 return c;
880
881 }
882
883
884 template < prototype_container ARRAY >
885 ::collection::count append_ptra(const ARRAY* pptra)
886 {
887
888 ::collection::count c = pptra->get_count(); // allow to append to itself one time
889
890 for(::collection::index i = 0; i < c; i++)
891 {
892 this->add(*pptra->element_at(i));
893 }
894
895 return c;
896
897 }
898
899 //template < class ARRAY >
900 //pointer_array_base & copy(const ARRAY * pa)
901 //{
902
903 // if(pa == dynamic_cast < ARRAY * > (this))
904 // return *this;
905
906 // this->erase_all();
907
908 // this->append(pa);
909
910 // return *this;
911
912 //}
913
914 template < class ARRAY >
915 pointer_array_base & copy(const ::pointer<ARRAY>& pa)
916 {
917
918 if(pa == dynamic_cast < ARRAY * > (this))
919 return *this;
920
921 this->erase_all();
922
923 this->append(pa);
924
925 return *this;
926
927 }
928
929
930 ::collection::count erase_all()
931 {
932
933 //auto size = this->size();
934
935 for (::collection::index i = 0; i < this->get_size(); i++)
936 {
937
938 try
939 {
940
941 auto & p = this->element_at(i);
942
943 if (p)
944 {
945
946 p.release();
947
948 }
949
950 }
951 catch (...)
952 {
953
954 }
955
956 }
957
958 return BASE_ARRAY ::erase_all();
959
960 }
961
962 //template < class ARRAY >
963 //pointer_array_base & copy(const ARRAY & a)
964 //{
965
966 // this->erase_all();
967
968 // this->append(a);
969
970 // return *this;
971
972 //}
973
974 pointer_array_base & copy(const pointer_array_base & a)
975 {
976
977 if(&a == this)
978 return *this;
979
980 this->erase_all();
981
982 this->append(a);
983
984 return *this;
985
986 }
987
988 template < class ARRAY >
989 pointer_array_base & copy_ptra(const ARRAY * pptra)
990 {
991
992 if(pptra == dynamic_cast < ARRAY * > (this))
993 return *this;
994
995 this->erase_all();
996
997 this->append(pptra);
998
999 return *this;
1000
1001 }
1002
1003};
1004
1005
1006//
1007//
1008//
1012//* pugixml parser - version 1.5
1013//* --------------------------------------------------------
1014//* Copyright (C) 2006-2014, by Arseny Kapoulkine ([email protected])
1015//* Report bugs and download ___new versions at http://pugixml.org/
1016//*
1017//* This library is distributed under the MIT License. See notice at the end
1018//* of this file.
1019//*
1020//* This work is based on the pugxml parser, which is:
1021//* Copyright (C) 2003, by Kristen Wegner ([email protected])
1022//*/
1023//
1024//template < typename Iterator > class smart_pointer_range2
1025//{
1026//public:
1027//
1028// Iterator m_beg;
1029// Iterator m_end;
1030//
1031// smart_pointer_range2(Iterator beg,Iterator end): m_beg(beg),m_end(end)
1032// {
1033// }
1034//
1035// Iterator begin() const { return m_beg; }
1036// Iterator end() const { return m_end; }
1037//
1038//private:
1039//
1040//};
1041//
1042//
1043//template < class T, typename ARG_T, typename ARRAY_BASE >
1044//class smart_pointer_array2:
1045// public comparable_array < ::pointer<T >>
1046//{
1047//public:
1048//
1049//
1050// class ref_iterator
1051// {
1052// public:
1053//
1054// typedef T BASE_TYPE;
1055// typedef const T & BASE_ARG_TYPE;
1056// typedef smart_pointer_array2 BASE_ARRAY;
1057//
1058// ::collection::index m_i32;
1059// BASE_ARRAY * m_parray;
1060//
1061// ref_iterator()
1062// {
1063// m_i32 = 0;
1064// m_parray = nullptr;
1065// }
1066//
1067// ref_iterator(::collection::index i,BASE_ARRAY * parray)
1068// {
1069// m_i32 = i;
1070// m_parray = parray;
1071// }
1072//
1073// ref_iterator(const ref_iterator & it)
1074// {
1075// operator = (it);
1076// }
1077//
1078//
1079// ref_iterator & operator = (const ref_iterator & it)
1080// {
1081// if(this != &it)
1082// {
1083// m_i32 = it.m_i32;
1084// m_parray = it.m_parray;
1085// }
1086// return *this;
1087// }
1088//
1089// bool operator == (const ref_iterator & it)
1090// {
1091// if(this == &it)
1092// return true;
1093// if(m_parray != it.m_parray)
1094// return false;
1095// if(m_i32 >= m_parray->get_size() && it.m_i32 >= m_parray->get_size())
1096// return true;
1097// if(m_i32 <= 0 && it.m_i32 <= 0)
1098// return true;
1099// return m_i32 == it.m_i32;
1100// }
1101//
1102// bool operator != (const ref_iterator & it)
1103// {
1104// return !operator==(it);
1105// }
1106//
1107// ref_iterator operator ++(::i32)
1108// {
1109// ref_iterator it = *this;
1110// operator ++();
1111// return it;
1112// }
1113//
1114// ref_iterator operator --(::i32)
1115// {
1116// ref_iterator it = *this;
1117// operator --();
1118// return it;
1119// }
1120//
1121// ref_iterator & operator ++()
1122// {
1123// m_i32++;
1124// if(m_i32 >= m_parray->get_size())
1125// m_i32 = m_parray->get_size();
1126// return *this;
1127// }
1128//
1129// ref_iterator & operator +(::collection::index i)
1130// {
1131// m_i32 += i;
1132// if(m_i32 >= m_parray->get_size())
1133// m_i32 = m_parray->get_size();
1134// return *this;
1135// }
1136//
1137// ref_iterator & operator --()
1138// {
1139// m_i32--;
1140// if(m_i32 < 0)
1141// m_i32 = 0;
1142// return *this;
1143// }
1144//
1145// ref_iterator mid(const ref_iterator & i) const
1146// {
1147// return ref_iterator((m_i32 + i.m_i32 + 1) / 2,m_parray);
1148// }
1149//
1150// ref_iterator & operator -(::collection::count c)
1151// {
1152// m_i32-=c;
1153// if(m_i32 < 0)
1154// m_i32 = 0;
1155// return *this;
1156// }
1157//
1158// bool operator < (const ref_iterator & i) const
1159// {
1160//
1161// return m_i32 < i.m_i32;
1162//
1163// }
1164//
1165// ::collection::count get_count() const
1166// {
1167// return m_parray->get_count();
1168// }
1169//
1170//
1171// T & operator * ()
1172// {
1173// return m_parray->at(m_i32);
1174// }
1175//
1176// const T & operator * () const
1177// {
1178// return m_parray->at(m_i32);
1179// }
1180//
1181//
1182// };
1183//
1184// typedef smart_pointer_range2 < ref_iterator > ref_range;
1185//
1186//
1187// smart_pointer_array2()
1188// {
1189//
1190// }
1191//
1192// virtual ~smart_pointer_array2()
1193// {
1194//
1195// this->erase_all();
1196//
1197// }
1198//
1199//#if defined(MOVE_SEMANTICS)
1200//
1201// smart_pointer_array2(smart_pointer_array2 && a)
1202// {
1203//
1204// comparable_array < ::pointer<T > > ::operator = (a);
1205//
1206// }
1207//
1208// inline smart_pointer_array2 & operator = (smart_pointer_array2 && a)
1209// {
1210//
1211// comparable_array < ::pointer<T > > ::operator = (a);
1212//
1213// return *this;
1214//
1215// }
1216//
1217//#endif
1218//
1219// smart_pointer_array2(const smart_pointer_array2 & a):
1220// comparable_array < ::pointer<T >>a)
1221// {
1222//
1223// comparable_array < ::pointer<T > > ::operator = (a);
1224//
1225// }
1226//
1227// inline smart_pointer_array2 & operator = (const smart_pointer_array2 & a)
1228// {
1229//
1230// copy(a);
1231//
1232// return *this;
1233//
1234// }
1235//
1236//
1237// smart_pointer_array2(::particle * pparticle):
1238// ::matter(pparticle),
1239// comparable_array < ::pointer<T >>pparticle)
1240// {
1241// }
1242//
1243// pointer < T > & add_new()
1244// {
1245//
1246// pointer < T > & sp = comparable_array < ::pointer<T > > ::add_new();
1247//
1248// sp.alloc(this->create_new, this);
1249//
1250// return sp;
1251//
1252// }
1253//
1254//
1255// ::collection::count set_size(::collection::count nNewSize,::collection::count nGrowBy = -1)
1256// {
1257//
1258// return comparable_array < ::pointer<T > > ::: set_size(nNewSize);
1259//
1260// }
1261//
1262// ::collection::count set_size_create(::collection::count nNewSize,::collection::count nGrowBy = -1)
1263// {
1264// ::collection::index i = this->get_size();
1265// comparable_array < ::pointer<T > > ::: set_size(nNewSize);
1266// ::collection::count ca = this->get_size();
1267// for(; i < ca; i++)
1268// {
1269// this->element_at(i).alloc(this->create_new, this);
1270// }
1271// return ca;
1272// }
1273//
1274//
1275// template < class DERIVED >
1276// DERIVED * get(::collection::index iStart = 0)
1277// {
1278//
1279// DERIVED * pderived = nullptr;
1280//
1281// for(::collection::index i = iStart; i < this->get_count(); i++)
1282// {
1283//
1284// try
1285// {
1286//
1287// pderived = dynamic_cast < DERIVED * > (this->element_at(i).m_p);
1288//
1289// }
1290// catch(...)
1291// {
1292//
1293// }
1294//
1295// if(pderived != nullptr)
1296// return pderived;
1297//
1298// }
1299//
1300// return nullptr;
1301//
1302// }
1303//
1304// template < class DERIVED >
1305// DERIVED * typed_ptr_at(::collection::index iIndex)
1306// {
1307//
1308// return dynamic_cast < DERIVED * > (this->element_at(iIndex).m_p);
1309//
1310// }
1311//
1312// pointer < T > & add(T * p)
1313// {
1314//
1315// return comparable_array < ::pointer<T > > ::add_new() = p;
1316//
1317// }
1318//
1319//
1320// bool add_unique(T * p)
1321// {
1322//
1323// if(contains(p))
1324// return false;
1325//
1326// this->add(p);
1327//
1328// return true;
1329//
1330// }
1331//
1332// ::collection::count add_unique(const smart_pointer_array2 & a)
1333// {
1334//
1335// ::collection::count c = 0;
1336//
1337// for(::collection::index i = 0; i < a.get_count(); i++)
1338// {
1339//
1340// if(add_unique((T *)a[i]))
1341// c++;
1342//
1343// }
1344//
1345// return c;
1346//
1347// }
1348//
1349// bool contains(const T * p,::collection::index iStart = 0,::collection::count nCount = -1) const
1350// {
1351//
1352// return find_first(p,iStart,nCount) >= 0;
1353//
1354// }
1355//
1356// ::collection::index find_first(const T * p,::collection::index iStart = 0,::collection::count nCount = -1) const
1357// {
1358//
1359// ::collection::index iEnd;
1360//
1361// if(nCount < 0)
1362// iEnd = this->get_upper_bound(nCount);
1363// else
1364// iEnd = iStart + nCount - 1;
1365//
1366// for(::collection::index i = iStart; i <= iEnd; i++)
1367// {
1368//
1369// if(this->element_at(i).m_p == p)
1370// return i;
1371//
1372// }
1373//
1374// return -1;
1375//
1376// }
1377//
1378//
1379// ::collection::index find_first(const T & t,::collection::index(* pfnCompare)(const T *,const T *),::collection::index iStart = 0,::collection::count nCount = -1) const
1380//
1381// {
1382//
1383// return this->find_first(&t,pfnCompare,iStart,nCount);
1384//
1385//
1386// }
1387//
1388//
1389// ::collection::index find_first(const T * p,::collection::index(* pfnCompare)(const T *,const T *),::collection::index iStart = 0,::collection::count nCount = -1) const
1390//
1391// {
1392//
1393// ::collection::index iEnd;
1394//
1395// if(nCount < 0)
1396// iEnd = this->get_upper_bound(nCount);
1397// else
1398// iEnd = iStart + nCount - 1;
1399//
1400// for(::collection::index i = iStart; i <= iEnd; i++)
1401// {
1402//
1403// if(pfnCompare(this->element_at(i).m_p,p) == 0)
1404//
1405// return i;
1406//
1407// }
1408//
1409// return -1;
1410//
1411// }
1412//
1413// template < class DERIVED >
1414// smart_pointer_array2 & operator -= (DERIVED * p)
1415// {
1416//
1417// this->erase(dynamic_cast < T * > (p));
1418//
1419// return *this;
1420//
1421// }
1422//
1423// ::collection::count erase(T * p)
1424// {
1425//
1426// ::collection::count ca = 0;
1427//
1428// ::collection::index iFind = 0;
1429//
1430// while((iFind = this->find_first(p,iFind)) >= 0)
1431// {
1432//
1433// ca++;
1434//
1435// this->erase_at(iFind);
1436//
1437// }
1438//
1439// return ca;
1440//
1441// }
1442//
1443//
1444// template < typename TYPE >
1445// ::collection::count erase_type(TYPE *)
1446// {
1447//
1448// ::collection::count c = 0;
1449//
1450// for(::collection::index i = this->get_upper_bound(); i >= 0; i--)
1451// {
1452//
1453// if(typeid(*this->element_at(i).m_p) == ::type<TYPE>())
1454// {
1455//
1456// this->erase_at(i);
1457//
1458// c++;
1459//
1460// }
1461//
1462// }
1463//
1464// return c;
1465//
1466// }
1467//
1468// // overloaded operator helpers
1469// T & element_at(::collection::index nIndex) const
1470// {
1471//
1472// return *this->comparable_array < ::pointer<T > > ::element_at(nIndex).m_p;
1473//
1474// }
1475//
1476// T & element_at(::collection::index nIndex)
1477// {
1478//
1479// return *this->comparable_array < ::pointer<T > > ::element_at(nIndex).m_p;
1480//
1481// }
1482//
1483// const pointer < T > & sp_at(::collection::index nIndex) const
1484// {
1485//
1486// return this->comparable_array < ::pointer<T > > ::element_at(nIndex);
1487//
1488// }
1489//
1490//
1491// pointer < T > & sp_at(::collection::index nIndex)
1492// {
1493//
1494// return this->comparable_array < ::pointer<T > > ::element_at(nIndex);
1495//
1496// }
1497//
1498//
1499// T * ptr_at(::collection::index nIndex) const
1500// {
1501//
1502// return this->sp_at(nIndex);
1503//
1504// }
1505//
1506//
1507// T * ptr_at(::collection::index nIndex)
1508// {
1509//
1510// return this->sp_at(nIndex);
1511//
1512// }
1513//
1514//
1515// T & at(::collection::index nIndex) const
1516// {
1517//
1518// return *this->ptr_at(nIndex);
1519//
1520// }
1521//
1522//
1523// T & at(::collection::index nIndex)
1524// {
1525//
1526// return *this->ptr_at(nIndex);
1527//
1528// }
1529//
1530// const pointer < T > & first_pointer(::collection::index n = 0) const
1531// {
1532//
1533// return this->comparable_array < ::pointer<T > > ::first(n);
1534//
1535// }
1536//
1537//
1538// pointer < T > & first_pointer(::collection::index n = 0)
1539// {
1540//
1541// return this->comparable_array < ::pointer<T > > ::first(n);
1542//
1543// }
1544//
1545//
1546// T * first_ptr(::collection::index n = 0) const
1547// {
1548//
1549// return this->first_pointer(n);
1550//
1551// }
1552//
1553//
1554// T * first_ptr(::collection::index n = 0)
1555// {
1556//
1557// return this->first_pointer(n);
1558//
1559// }
1560//
1561//
1562// T & first(::collection::index n = 0) const
1563// {
1564//
1565// return *this->first_ptr(n);
1566//
1567// }
1568//
1569//
1570// T & first(::collection::index n = 0)
1571// {
1572//
1573// return *this->first_ptr(n);
1574//
1575// }
1576//
1577//
1578// T * last_pointer(::collection::index n = -1) const
1579// {
1580//
1581// return this->comparable_array < ::pointer<T > > ::last(n);
1582//
1583// }
1584//
1585//
1586// pointer < T > & last_pointer(::collection::index n = -1)
1587// {
1588//
1589// return this->comparable_array < ::pointer<T > > ::last(n);
1590//
1591// }
1592//
1593//
1594// T * last_ptr(::collection::index n = -1) const
1595// {
1596//
1597// return this->last_pointer(n);
1598//
1599// }
1600//
1601//
1602// T * last_ptr(::collection::index n = -1)
1603// {
1604//
1605// return this->last_pointer(n);
1606//
1607// }
1608//
1609//
1610// T & last(::collection::index n = -1) const
1611// {
1612//
1613// return *last_ptr(n);
1614//
1615// }
1616//
1617//
1618// T & last(::collection::index n = -1)
1619// {
1620//
1621// return *this->last_ptr(n);
1622//
1623// }
1624//
1625//
1626// const T & operator() (::collection::index nIndex) const
1627// {
1628//
1629// return *this->sp_at(nIndex);
1630//
1631// }
1632//
1633//
1634// T & operator() (::collection::index nIndex)
1635// {
1636//
1637// return *this->sp_at(nIndex);
1638//
1639// }
1640//
1641//
1642// template < class ARRAY >
1643// smart_pointer_array2 & append(const ARRAY * pa)
1644// {
1645//
1646// ::collection::count c = pa->get_count(); // allow to append to itself one time
1647//
1648// for(::collection::index i = 0; i < c; i++)
1649// {
1650// this->add(pa->element_at(i));
1651// }
1652//
1653// return *this;
1654//
1655// }
1656//
1657// template < class ARRAY >
1658// smart_pointer_array2 & append(const ::pointer<ARRAY>& pa)
1659// {
1660//
1661// ::collection::count c = pa->get_count(); // allow to append to itself one time
1662//
1663// for(::collection::index i = 0; i < c; i++)
1664// {
1665// this->add(pa->element_at(i));
1666// }
1667//
1668// return *this;
1669//
1670// }
1671//
1672// template < class ARRAY >
1673// smart_pointer_array2 & append(const ARRAY & a)
1674// {
1675//
1676// ::collection::count c = a.get_count(); // allow to append to itself one time
1677//
1678// for(::collection::index i = 0; i < c; i++)
1679// {
1680// this->add(a.element_at(i));
1681// }
1682//
1683// return *this;
1684//
1685// }
1686//
1687//
1688// smart_pointer_array2 & append(const smart_pointer_array2 & a)
1689// {
1690//
1691// ::collection::count c = a.get_count(); // allow to append to itself one time
1692//
1693// for(::collection::index i = 0; i < c; i++)
1694// {
1695//
1696// this->add(a.sp_at(i));
1697//
1698// }
1699//
1700// return *this;
1701//
1702// }
1703//
1704//
1705// template < class ARRAY >
1706// smart_pointer_array2 & append_ptra(const ARRAY * pptra)
1707// {
1708//
1709// ::collection::count c = pptra->get_count(); // allow to append to itself one time
1710//
1711// for(::collection::index i = 0; i < c; i++)
1712// {
1713// this->add(*pptra->element_at(i));
1714// }
1715//
1716// return *this;
1717//
1718// }
1719//
1720// template < class ARRAY >
1721// smart_pointer_array2 & copy(const ARRAY * pa)
1722// {
1723//
1724// if(pa == dynamic_cast < ARRAY * > (this))
1725// return *this;
1726//
1727// this->erase_all();
1728//
1729// this->append(pa);
1730//
1731// return *this;
1732//
1733// }
1734//
1735// template < class ARRAY >
1736// smart_pointer_array2 & copy(const ::pointer<ARRAY>& pa)
1737// {
1738//
1739// if(pa == dynamic_cast < ARRAY * > (this))
1740// return *this;
1741//
1742// this->erase_all();
1743//
1744// this->append(pa);
1745//
1746// return *this;
1747//
1748// }
1749//
1750// template < class ARRAY >
1751// smart_pointer_array2 & copy(const ARRAY & a)
1752// {
1753//
1754// if(&a == dynamic_cast < ARRAY * > (this))
1755// return *this;
1756//
1757// this->erase_all();
1758//
1759// this->append(a);
1760//
1761// return *this;
1762//
1763// }
1764//
1765// smart_pointer_array2 & copy(const smart_pointer_array2 & a)
1766// {
1767//
1768// if(&a == this)
1769// return *this;
1770//
1771// this->erase_all();
1772//
1773// this->append(a);
1774//
1775// return *this;
1776//
1777// }
1778//
1779// template < class ARRAY >
1780// smart_pointer_array2 & copy_ptra(const ARRAY * pptra)
1781// {
1782//
1783// if(pptra == dynamic_cast < ARRAY * > (this))
1784// return *this;
1785//
1786// this->erase_all();
1787//
1788// this->append(pptra);
1789//
1790// return *this;
1791//
1792// }
1793//
1794// ref_iterator ref_it(::collection::index iStart) { return ref_iterator(iStart,this); }
1795// ref_iterator ref_it(::collection::index iStart,::collection::count cCount) { return ref_iterator(iStart + (cCount < 0 ? this->get_count() + cCount + 1 : cCount),this); }
1796//
1797// ref_range refa(::collection::index iStart = 0,::collection::count cCount = -1) { return smart_pointer_range2 < ref_iterator >(ref_it(iStart),ref_it(iStart,cCount)); }
1798//
1799//};
1800
1801//#define sspa(TYPE) base_array < ::pointer<TYPE >>
1802//#define spa2(TYPE) ::smart_pointer_array2 < TYPE >
1804
1805typedef pointer_array_base < matter > object_pointera;
1806
1807typedef pointer_array_base < matter > simple_object_pointera;
1808
1809
1810template < class T, typename ARG_T, typename ARRAY_BASE >
1811bool pointer_array_base < T, ARG_T, ARRAY_BASE > ::insert_unique_at(::collection::index i, T * p)
1812{
1813
1814 if (i < 0 || i > this->get_size())
1815 {
1816
1817 throw_exception(error_bad_argument);
1818
1819 }
1820
1821 auto iFind = this->find_first(p);
1822
1823 if (iFind < 0)
1824 {
1825
1826 this->insert_at(i, p);
1827
1828 return true;
1829
1830 }
1831
1832 if (iFind < i)
1833 {
1834
1835 this->erase_at(iFind);
1836
1837 this->insert_at(i - 1, p);
1838
1839 }
1840 else if(iFind > i)
1841 {
1842
1843 this->erase_at(iFind);
1844
1845 this->insert_at(i, p);
1846
1847 }
1848
1849 return false;
1850
1851}
1852
1853
1854
1855
1856template < class T, typename ARG_T, typename ARRAY_BASE >
1857template < typename OBJECT >
1858::collection::count pointer_array_base < T, ARG_T, ARRAY_BASE > ::set_size_create(OBJECT * pparticle, ::collection::count nNewSize, ::collection::count nGrowBy)
1859{
1860
1861 ::collection::index i = this->get_size();
1862
1863 BASE_ARRAY::set_size(nNewSize);
1864
1865 ::collection::count c = this->get_size();
1866
1867 for (; i < c; i++)
1868 {
1869
1870 pparticle->constructø(this->element_at(i));
1871
1872 }
1873
1874 return c;
1875
1876}
1877
1878
1879template < class T, typename ARG_T, typename ARRAY_BASE >
1881 public ::array_particle < pointer_array_base < T, ARG_T, ARRAY_BASE > >
1882{
1883public:
1884
1885
1886 using POINTER_ARRAY_BASE = ::pointer_array_base < T, ARG_T, ARRAY_BASE >;
1887
1888
1889 using BASE_ARRAY = ::array_particle < POINTER_ARRAY_BASE >;
1890
1891
1892 using BASE_ARRAY::BASE_ARRAY;
1893 using BASE_ARRAY::operator =;
1894
1895 using POINTER_ARRAY_BASE::operator[];
1896 using POINTER_ARRAY_BASE::operator();
1897
1898 using POINTER_ARRAY_BASE::call_member;
1899
1900
1901};
Definition pointer_container.h:83
::collection::index add(pointer< T > &&p)
referer is transferred?
Definition pointer_array.h:235
inline ::collection::index add_item(const pointer< T > &p)
consumes a referer
Definition pointer_array.h:184
::collection::index add_non_null(T *p)
consumes a referer
Definition pointer_array.h:244
bool add_unique(const ::pointer< T2 > &p2)
consumes a referer
Definition pointer_array.h:312
void insert_at(::collection::index i, T *p)
consumes a referer
Definition pointer_array.h:260
bool add_unique(const T2 *p2)
consumes a referer
Definition pointer_array.h:277
::collection::index add(const pointer< T > &p)
consumes a referer
Definition pointer_array.h:226
::collection::count erase(T *p)
consumes a releaser
Definition pointer_array.h:482
inline ::collection::index add_item(pointer< T > &&p)
referer is transfered?
Definition pointer_array.h:197
Definition pointer_array.h:1882