ZFFramework
Loading...
Searching...
No Matches
ZFCoreArray.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFCoreArray_h_
7#define _ZFI_ZFCoreArray_h_
8
10#include "ZFComparer.h"
11#include "ZFCoreUtilMath.h"
12#include "ZFToken.h"
13
15
16template<typename T_Element, bool isPOD = zftIsPOD<T_Element>::Value>
17zfclassNotPOD _ZFP_ZFCoreArrayW {
18public:
19 static void objCreate(
20 ZF_IN T_Element *p
21 , ZF_IN T_Element *pEnd
22 ) {
23 while(p != pEnd) {
24 zfnewPlacement(p, T_Element);
25 ++p;
26 }
27 }
28 static void objCreate(
29 ZF_IN T_Element *p
30 , ZF_IN T_Element *pEnd
31 , ZF_IN const T_Element *src
32 ) {
33 while(p != pEnd) {
34 zfnewPlacement(p, T_Element, *src);
35 ++p;
36 ++src;
37 }
38 }
39 static void objMove(
40 ZF_IN T_Element *dst
41 , ZF_IN const T_Element *src
42 , ZF_IN zfindex count
43 ) {
44 zfmemmoveObject(dst, src, count);
45 }
46 static void objDestroy(
47 ZF_IN T_Element *p
48 , ZF_IN T_Element *pEnd
49 ) {
50 while(p != pEnd) {
52 ++p;
53 }
54 }
55};
56template<typename T_Element>
57zfclassNotPOD _ZFP_ZFCoreArrayW<T_Element, true> {
58public:
59 static void objCreate(
60 ZF_IN T_Element *p
61 , ZF_IN T_Element *pEnd
62 ) {
63 }
64 static void objCreate(
65 ZF_IN T_Element *p
66 , ZF_IN T_Element *pEnd
67 , ZF_IN const T_Element *src
68 ) {
69 zfmemcpy(p, src, (pEnd - p) * sizeof(T_Element));
70 }
71 static void objMove(
72 ZF_IN T_Element *dst
73 , ZF_IN const T_Element *src
74 , ZF_IN zfindex count
75 ) {
76 zfmemmove(dst, src, count * sizeof(T_Element));
77 }
78 static void objDestroy(
79 ZF_IN T_Element *p
80 , ZF_IN T_Element *pEnd
81 ) {
82 }
83};
84
85template<typename T_Element>
86zffinal zfclassNotPOD _ZFP_ZFCoreArrayPrivate {
87public:
88 zfuint refCount;
89 T_Element *buf;
90 zfuint capacity;
91 zfuint count;
92public:
93 _ZFP_ZFCoreArrayPrivate(void)
94 : refCount(1)
95 , buf(zfnull)
96 , capacity(0)
97 , count(0)
98 {
99 }
100 ~_ZFP_ZFCoreArrayPrivate(void) {
101 _ZFP_ZFCoreArrayW<T_Element>::objDestroy(this->buf, this->buf + this->count);
102 zfpoolFree(this->buf);
103 }
104};
105
106// ============================================================
111public:
112 virtual ~ZFCoreArrayBase(void) {}
120 virtual void refDelete(void) {
121 zfpoolDelete(this);
122 }
123
126 virtual void *refImpl(void) const zfpurevirtual;
127
129 virtual void objectInfoT(ZF_IN_OUT zfstring &ret) const {
130 this->objectInfoOfContentT(ret, 10);
131 }
132
133 virtual zfstring objectInfo(void) const {
134 zfstring ret;
135 this->objectInfoT(ret);
136 return ret;
137 }
138
142 , ZF_IN_OPT zfindex maxCount = zfindexMax()
144 ) const zfpurevirtual;
147 ZF_IN_OPT zfindex maxCount = zfindexMax()
149 ) const {
150 zfstring ret;
151 this->objectInfoOfContentT(ret, maxCount, token);
152 return ret;
153 }
154
156 virtual ZFCoreArrayBase &operator = (ZF_IN const ZFCoreArrayBase &ref) zfpurevirtual;
157 virtual zfbool operator == (ZF_IN const ZFCoreArrayBase &ref) const zfpurevirtual;
158 virtual zfbool operator != (ZF_IN const ZFCoreArrayBase &ref) const zfpurevirtual;
160
161public:
167 virtual void capacity(ZF_IN zfindex newCapacity) zfpurevirtual;
173 virtual void capacityTrim(void) zfpurevirtual;
177 virtual zfindex capacity(void) const zfpurevirtual;
178
183
187 virtual void remove(ZF_IN zfindex index) zfpurevirtual;
191 virtual void remove(
192 ZF_IN zfindex index
198 virtual void removeFirst(void) {
199 this->remove(0);
200 }
201
204 virtual void removeLast(void) {
205 this->remove(this->count() - 1);
206 }
207
210 virtual void removeAll(void) {
211 if(!this->isEmpty()) {
212 this->remove(0, this->count());
213 }
214 }
215
218 virtual void move(
219 ZF_IN zfindex fromIndex
220 , ZF_IN zfindex toIndexOrIndexMax
225 virtual zfindex count(void) const zfpurevirtual;
229 virtual zfbool isEmpty(void) const {
230 return this->count() != 0;
231 }
232
235 virtual void sort(
236 ZF_IN_OPT zfindex start = 0
242 virtual void sortReversely(
243 ZF_IN_OPT zfindex start = 0
246
247public:
253 virtual zfindex genericFind(ZF_IN const void *e) zfpurevirtual;
259 virtual void genericAdd(ZF_IN const void *e) {
260 this->genericAdd(e, zfindexMax());
261 }
262
263 virtual void genericAdd(
264 ZF_IN const void *e
265 , ZF_IN zfindex index
270 virtual void genericSet(
271 ZF_IN zfindex index
272 , ZF_IN const void *e
275 virtual const void *genericGet(ZF_IN zfindex index) const zfpurevirtual;
276};
277ZFOUTPUT_TYPE(ZFCoreArrayBase, {v.objectInfoT(s);})
278
279// ============================================================
296template<typename T_Element>
298public:
302 typedef T_Element ValueType;
303
304public:
308 ZFCoreArray(void) : d(zfnull) {}
312 ZFCoreArray(ZF_IN const zfnullT &dummy) : d(zfnull) {}
317 : d(ref.d)
318 {
319 if(d) {
320 ++(d->refCount);
321 }
322 }
323 virtual ~ZFCoreArray(void) {
324 if(d) {
325 --(d->refCount);
326 if(d->refCount == 0) {
327 zfpoolDelete(d);
328 }
329 }
330 }
334 ZFCoreArray<T_Element> &refPrepare(void) {if(d == zfnull) {d = zfpoolNew(_ZFP_ZFCoreArrayPrivate<T_Element>);} return *this;}
336 virtual ZFCoreArrayBase *refNew(void) const {return zfpoolNew(ZFCoreArray<T_Element>, *this);}
338 virtual void *refImpl(void) const {return d;}
343 _ZFP_ZFCoreArrayPrivate<T_Element> *dTmp = d;
344 d = ref.d;
345 if(d) {
346 ++(d->refCount);
347 }
348 if(dTmp) {
349 --(dTmp->refCount);
350 if(dTmp->refCount == 0) {
351 zfpoolDelete(dTmp);
352 }
353 }
354 return *this;
355 }
356
357 ZFCoreArray<T_Element> &operator = (ZF_IN const zfnullT &dummy) {
358 this->removeAll();
359 return *this;
360 }
361 zfbool operator == (ZF_IN const zfnullT &dummy) const {return this->isEmpty();}
362 zfbool operator != (ZF_IN const zfnullT &dummy) const {return !this->isEmpty();}
363 zfbool operator == (ZF_IN const ZFCoreArray<T_Element> &ref) const {return (d == ref.d);}
364 zfbool operator != (ZF_IN const ZFCoreArray<T_Element> &ref) const {return (d != ref.d);}
366 virtual ZFCoreArrayBase &operator = (ZF_IN const ZFCoreArrayBase &ref) {
367 return this->operator = ((const ZFCoreArray<T_Element> &)ref);
368 }
369 virtual zfbool operator == (ZF_IN const ZFCoreArrayBase &ref) const {
370 return this->operator == ((const ZFCoreArray<T_Element> &)ref);
371 }
372 virtual zfbool operator != (ZF_IN const ZFCoreArrayBase &ref) const {
373 return this->operator == ((const ZFCoreArray<T_Element> &)ref);
374 }
376
377public:
382 _ZFP_ZFCoreArrayPrivate<T_Element> *dTmp = d;
383 d = ref.d;
384 ref.d = dTmp;
385 }
386
391 if(d != ref.d) {
392 if(d && d->buf) {
393 _ZFP_ZFCoreArrayW<T_Element>::objDestroy(d->buf, d->buf + d->count);
394 d->count = 0;
395 }
396 if(ref.d) {
397 _capacityRequire(ref.count());
398 _ZFP_ZFCoreArrayW<T_Element>::objCreate(d->buf, d->buf + ref.count(), ref.arrayBuf());
399 d->count = (zfuint)ref.count();
400 }
401 }
402 }
403
406 zfindex objectRetainCount(void) const {return d ? d->refCount : 0;}
413
419 ) const {
420 if(d == ref.d) {
421 return ZFCompareEqual;
422 }
423 if(this->count() != ref.count()) {
425 }
426 for(zfindex i = this->count() - 1; i != zfindexMax(); --i) {
427 if(comparer(this->get(i), ref.get(i)) != ZFCompareEqual) {
429 }
430 }
431 return ZFCompareEqual;
432 }
433
434public:
438 , ZF_IN_OPT zfindex maxCount = zfindexMax()
440 ) const {
441 this->objectInfoOfContentT(ret, maxCount, token, zfnull);
442 }
445 ZF_IN_OPT zfindex maxCount = zfindexMax()
447 ) const {
448 zfstring ret;
449 this->objectInfoOfContentT(ret, maxCount, token, zfnull);
450 return ret;
451 }
452
456 , ZF_IN_OPT zfindex maxCount
457 , ZF_IN_OPT const ZFTokenForContainer &token
459 ) const {
460 zfindex count = 0;
461 ret += token.tokenLeft;
462 for(; count < this->count() && count < maxCount; ++count) {
463 if(count > 0) {
464 ret += token.tokenSeparator;
465 }
466 ret += token.tokenValueLeft;
467 if(infoGetter != zfnull) {
468 infoGetter(ret, this->get(count));
469 }
470 else {
471 zftToStringT(ret, this->get(count));
472 }
473 ret += token.tokenValueRight;
474 }
475 if(count < this->count()) {
476 if(count > 0) {
477 ret += token.tokenSeparator;
478 }
479 ret += token.tokenEtc;
480 }
481 ret += token.tokenRight;
482 }
483
485 ZF_IN_OPT zfindex maxCount
486 , ZF_IN_OPT const ZFTokenForContainer &token
488 ) const {
489 zfstring ret;
490 this->objectInfoOfContentT(ret, maxCount, token, infoGetter);
491 return ret;
492 }
493
494public:
496 virtual void capacity(ZF_IN zfindex newCapacity) {
497 _capacityRequire(newCapacity);
498 }
500 virtual void capacityTrim(void) {
501 zfindex capacity = this->count();
502 _capacityOptimize(capacity);
503 if(capacity != this->capacity()) {
504 _capacityDoChange(capacity);
505 }
506 }
508 virtual zfindex capacity(void) const {
509 return (zfindex)(d ? d->capacity : 0);
510 }
511
513 virtual void resize(ZF_IN zfindex count) {
514 if(this->count() > count) {
515 this->remove(count, zfindexMax());
516 }
517 else if(this->count() < count) {
518 _capacityRequire(count);
519 _ZFP_ZFCoreArrayW<T_Element>::objCreate(d->buf + d->count, d->buf + count);
520 d->count = (zfuint)count;
521 }
522 }
523
524public:
528 T_Element &add(void) {
529 _capacityRequire(this->count() + 1);
530 _ZFP_ZFCoreArrayW<T_Element>::objCreate(d->buf + d->count, d->buf + d->count + 1);
531 return d->buf[(d->count)++];
532 }
533
536 void add(ZF_IN T_Element const &e) {
537 _capacityRequire(this->count() + 1);
538 _ZFP_ZFCoreArrayW<T_Element>::objCreate(d->buf + d->count, d->buf + d->count + 1, &e);
539 ++(d->count);
540 }
541
544 void add(
545 ZF_IN T_Element const &e
546 , ZF_IN zfindex index
547 ) {
548 if(index == zfindexMax()) {
549 index = this->count();
550 }
551 else {
552 ZFCoreAssertIndexRange(index, this->count() + 1);
553 }
554 _capacityRequire(this->count() + 1);
555 _ZFP_ZFCoreArrayW<T_Element>::objCreate(d->buf + d->count, d->buf + d->count + 1);
556 T_Element *pos = d->buf + index;
557 _ZFP_ZFCoreArrayW<T_Element>::objMove(pos + 1, pos, this->count() - index);
558 ++(d->count);
559 *pos = e;
560 }
561
565 ZF_IN const T_Element *src
567 ) {
568 if(src == zfnull || count == 0) {
569 return;
570 }
571 if(d == zfnull || src < d->buf || src >= d->buf + d->capacity) {
572 _capacityRequire(this->count() + count);
573 _ZFP_ZFCoreArrayW<T_Element>::objCreate(d->buf + d->count, d->buf + d->count + count, src);
574 d->count += (zfuint)count;
575 }
576 else {
578 tmp.capacity(count);
579 tmp.addFrom(src, count);
580 this->addFrom(tmp.arrayBuf(), count);
581 }
582 }
583
588 if(d != ref.d) {
589 this->addFrom(ref.arrayBuf(), ref.count());
590 }
591 }
592
597 ZF_IN T_Element const &e
599 ) const {
600 if(d) {
601 for(T_Element *p = d->buf, *pEnd = d->buf + d->count; p < pEnd; ++p) {
602 if(comparer(*p, e) == ZFCompareEqual) {
603 return (p - d->buf);
604 }
605 }
606 }
607 return zfindexMax();
608 }
609
613 ZF_IN T_Element const &e
615 ) const {
616 if(d && d->buf) {
617 for(T_Element *p = d->buf + d->count - 1; p >= d->buf; --p) {
618 if(comparer(*p, e) == ZFCompareEqual) {
619 return (p - d->buf);
620 }
621 }
622 }
623 return zfindexMax();
624 }
625
628 template<typename T_Another>
630 ZF_IN T_Another const &e
632 ) const {
633 if(d) {
634 for(T_Element *p = d->buf, *pEnd = d->buf + d->count; p < pEnd; ++p) {
635 if(comparer(*p, e) == ZFCompareEqual) {
636 return (p - d->buf);
637 }
638 }
639 }
640 return zfindexMax();
641 }
642
645 template<typename T_Another>
647 ZF_IN T_Another const &e
649 ) const {
650 if(d && d->buf) {
651 for(T_Element *p = d->buf + d->count - 1; p >= d->buf; --p) {
652 if(comparer(*p, e) == ZFCompareEqual) {
653 return (p - d->buf);
654 }
655 }
656 }
657 return zfindexMax();
658 }
659
664 ZF_IN T_Element const &e
666 ) {
667 if(d) {
668 for(T_Element *p = d->buf, *pEnd = d->buf + d->count; p < pEnd; ++p) {
669 if(comparer(*p, e) == ZFCompareEqual) {
670 this->remove(p - d->buf);
671 return zftrue;
672 }
673 }
674 }
675 return zffalse;
676 }
677
680 template<typename T_Another>
682 ZF_IN T_Another const &e
684 ) {
685 if(d) {
686 for(T_Element *p = d->buf, *pEnd = d->buf + d->count; p < pEnd; ++p) {
687 if(comparer(*p, e) == ZFCompareEqual) {
688 this->remove(p - d->buf);
689 return zftrue;
690 }
691 }
692 }
693 return zffalse;
694 }
695
699 ZF_IN T_Element const &e
701 ) {
702 if(d && d->buf) {
703 for(T_Element *p = d->buf + d->count - 1; p >= d->buf; --p) {
704 if(comparer(*p, e) == ZFCompareEqual) {
705 this->remove(p - d->buf);
706 return zftrue;
707 }
708 }
709 }
710 return zffalse;
711 }
712
715 template<typename T_Another>
717 ZF_IN T_Another const &e
719 ) {
720 if(d && d->buf) {
721 for(T_Element *p = d->buf + d->count - 1; p >= d->buf; --p) {
722 if(comparer(*p, e) == ZFCompareEqual) {
723 this->remove(p - d->buf);
724 return zftrue;
725 }
726 }
727 }
728 return zffalse;
729 }
730
734 ZF_IN T_Element const &e
736 ) {
737 zfindex removedCount = 0;
738 if(d) {
739 for(T_Element *p = d->buf, *pEnd = d->buf + d->count; p < pEnd; ++p) {
740 if(comparer(*p, e) == ZFCompareEqual) {
741 ++removedCount;
742 this->remove(p - d->buf);
743 --p;
744 }
745 }
746 }
747 return removedCount;
748 }
749
752 template<typename T_Another>
754 ZF_IN T_Another const &e
756 ) {
757 zfindex removedCount = 0;
758 if(d) {
759 for(T_Element *p = d->buf, *pEnd = d->buf + d->count; p < pEnd; ++p) {
760 if(comparer(*p, e) == ZFCompareEqual) {
761 ++removedCount;
762 this->remove(p - d->buf);
763 --p;
764 }
765 }
766 }
767 return removedCount;
768 }
769
771 virtual void remove(ZF_IN zfindex index) {
772 ZFCoreAssertIndexRange(index, this->count());
773 _ZFP_ZFCoreArrayW<T_Element>::objMove(d->buf + index, d->buf + index + 1, this->count() - index - 1);
774 _ZFP_ZFCoreArrayW<T_Element>::objDestroy(d->buf + d->count - 1, d->buf + d->count);
775 --(d->count);
776 }
778 virtual void remove(
779 ZF_IN zfindex index
781 ) {
782 ZFCoreAssertIndexRange(index, this->count());
783 if(count > this->count() - index) {
784 count = this->count() - index;
785 }
786 _ZFP_ZFCoreArrayW<T_Element>::objMove(d->buf + index, d->buf + index + count, this->count() - (index + count));
787 _ZFP_ZFCoreArrayW<T_Element>::objDestroy(d->buf + d->count - count, d->buf + d->count);
788 d->count -= (zfuint)count;
789 }
790
793 T_Element removeAndGet(ZF_IN zfindex index) {
794 T_Element t = this->get(index);
795 this->remove(index);
796 return t;
797 }
798
802 T_Element removeFirstAndGet(void) {
803 T_Element t = this->getFirst();
804 this->removeFirst();
805 return t;
806 }
807
811 T_Element removeLastAndGet(void) {
812 T_Element t = this->getLast();
813 this->removeLast();
814 return t;
815 }
816
818 virtual void move(
819 ZF_IN zfindex fromIndex
820 , ZF_IN zfindex toIndexOrIndexMax
821 ) {
822 ZFCoreAssertIndexRange(fromIndex, this->count());
823 if(toIndexOrIndexMax == zfindexMax()) {
824 toIndexOrIndexMax = this->count() - 1;
825 }
826 else {
827 ZFCoreAssertIndexRange(toIndexOrIndexMax, this->count());
828 }
829 if(fromIndex == toIndexOrIndexMax) {
830 return;
831 }
832 T_Element t = d->buf[fromIndex];
833 if(fromIndex < toIndexOrIndexMax) {
834 _ZFP_ZFCoreArrayW<T_Element>::objMove(d->buf + fromIndex, d->buf + fromIndex + 1, toIndexOrIndexMax - fromIndex);
835 }
836 else {
837 _ZFP_ZFCoreArrayW<T_Element>::objMove(d->buf + toIndexOrIndexMax + 1, d->buf + toIndexOrIndexMax, fromIndex - toIndexOrIndexMax);
838 }
839 d->buf[toIndexOrIndexMax] = t;
840 }
841
842public:
846 void set(
847 ZF_IN zfindex index
848 , ZF_IN T_Element const &e
849 ) {
850 ZFCoreAssertIndexRange(index, this->count());
851 d->buf[index] = e;
852 }
853
854public:
858 T_Element &get(ZF_IN zfindex index) {
859 ZFCoreAssertIndexRange(index, this->count());
860 return d->buf[index];
861 }
862
865 T_Element const &get(ZF_IN zfindex index) const {
866 ZFCoreAssertIndexRange(index, this->count());
867 return d->buf[index];
868 }
869
872 T_Element &operator [] (ZF_IN zfindex index) {
873 ZFCoreAssertIndexRange(index, this->count());
874 return d->buf[index];
875 }
876
879 T_Element const &operator [] (ZF_IN zfindex index) const {
880 ZFCoreAssertIndexRange(index, this->count());
881 return d->buf[index];
882 }
883
886 T_Element const &getFirst(void) const {
887 ZFCoreAssertIndexRange(0, this->count());
888 return *(d->buf);
889 }
890
893 T_Element const &getLast(void) const {
894 ZFCoreAssertIndexRange(0, this->count());
895 return *(d->buf + d->count - 1);
896 }
897
904 T_Element *arrayBuf(void) {return d ? d->buf : zfnull;}
908 const T_Element *arrayBuf(void) const {return d ? d->buf : zfnull;}
909
911 virtual zfindex count(void) const {return (zfindex)(d ? d->count : 0);}
913 virtual zfbool isEmpty(void) const {return (d == zfnull || d->count == 0);}
916 ZF_IN T_Element const &e
918 ) const {
919 return this->find(e, comparer) != zfindexMax();
920 }
921
922public:
924 virtual void sort(
925 ZF_IN_OPT zfindex start = 0
927 ) {
928 this->sort(start, count, ZFComparerDefault);
929 }
931 virtual void sortReversely(
932 ZF_IN_OPT zfindex start = 0
934 ) {
936 }
937
940 void sort(
941 ZF_IN zfindex start
943 , ZF_IN typename ZFComparer<T_Element>::Comparer comparer
944 ) {
945 if(!this->isEmpty() && start + 1 < this->count() && count > 1) {
947 d->buf
948 , start
949 , (count > this->count() - start) ? (this->count() - 1) : (start + count - 1)
950 , comparer
951 );
952 }
953 }
954
958 ZF_IN zfindex start
960 , ZF_IN typename ZFComparer<T_Element>::Comparer comparer
961 ) {
962 if(!this->isEmpty() && start + 1 < this->count() && count > 1) {
964 d->buf
965 , start
966 , (count > this->count() - start) ? (this->count() - 1) : (start + count - 1)
967 , comparer
968 );
969 }
970 }
971
972public:
976 virtual void genericCopyFrom(ZF_IN const ZFCoreArrayBase &ref) {this->copyFrom((const ZFCoreArray<T_Element> &)ref);}
978 virtual zfindex genericFind(ZF_IN const void *e) {return this->find(*(const T_Element *)e);}
980 virtual zfindex genericFindReversely(ZF_IN const void *e) {return this->findReversely(*(const T_Element *)e);}
982 virtual zfindex genericRemoveElementAll(ZF_IN const void *e) {return this->removeElementAll(*(const T_Element *)e);}
984 virtual void genericAdd(
985 ZF_IN const void *e
986 , ZF_IN zfindex index
987 ) {this->add(*(const T_Element *)e, index);}
989 virtual void genericAddFrom(ZF_IN const ZFCoreArrayBase &ref) {this->addFrom((const ZFCoreArray<T_Element> &)ref);}
991 virtual void genericSet(
992 ZF_IN zfindex index
993 , ZF_IN const void *e
994 ) {this->set(index, *(const T_Element *)e);}
996 virtual const void *genericGet(ZF_IN zfindex index) const {return &(this->get(index));}
997
998private:
999 _ZFP_ZFCoreArrayPrivate<T_Element> *d;
1000private:
1001 inline void _capacityOptimize(ZF_IN_OUT zfindex &capacity) {
1003 }
1004 inline void _capacityRequire(ZF_IN zfindex capacity) {
1005 _capacityOptimize(capacity);
1006 if(capacity > this->capacity()) {
1007 _capacityDoChange(capacity);
1008 }
1009 }
1010 void _capacityDoChange(ZF_IN zfindex capacity) {
1011 if(capacity == 0) {
1012 if(d) {
1013 _ZFP_ZFCoreArrayW<T_Element>::objDestroy(d->buf, d->buf + d->count);
1014 zfpoolFree(d->buf);
1015 d->buf = zfnull;
1016 d->capacity = 0;
1017 d->count = 0;
1018 }
1019 }
1020 else {
1021 if(d == zfnull) {
1022 d = zfpoolNew(_ZFP_ZFCoreArrayPrivate<T_Element>);
1023 }
1024
1025 T_Element *oldBuf = d->buf;
1026 zfuint oldCount = d->count;
1027
1028 T_Element *newBuf = (T_Element *)zfpoolMalloc(capacity * sizeof(T_Element));
1029 _ZFP_ZFCoreArrayW<T_Element>::objCreate(newBuf, newBuf + oldCount, oldBuf);
1030
1031 d->buf = newBuf;
1032 d->capacity = (zfuint)capacity;
1033 d->count = oldCount;
1034
1035 _ZFP_ZFCoreArrayW<T_Element>::objDestroy(oldBuf, oldBuf + oldCount);
1036 zfpoolFree(oldBuf);
1037 }
1038 }
1039};
1040ZFOUTPUT_TYPE_TEMPLATE(typename T_Element, ZFCoreArray<T_Element>, {v.objectInfoT(s);})
1041
1042template<typename T_Element>
1043zfclassLikePOD _ZFP_ZFCoreArrayCreate {
1044public:
1045 inline _ZFP_ZFCoreArrayCreate<T_Element> &add(ZF_IN T_Element const &v) {
1046 this->v.add(v);
1047 return *this;
1048 }
1049
1050public:
1052};
1053#define _ZFP_ZFCoreArrayCreate_action_expand(value) .add(value)
1054#define _ZFP_ZFCoreArrayCreate_action(CreatorType, values, ...) \
1055 CreatorType() ZFM_FIX_PARAM(_ZFP_ZFCoreArrayCreate_action_expand, ZFM_EMPTY, values, ##__VA_ARGS__) .v
1064#define ZFCoreArrayCreate(ElementType, values, ...) _ZFP_ZFCoreArrayCreate_action(_ZFP_ZFCoreArrayCreate<ElementType>, values, ##__VA_ARGS__)
1065
1067
1068#endif // #ifndef _ZFI_ZFCoreArray_h_
1069
common comparer for ZFFramework
#define ZFComparerDefault
default comparer for common types, see ZFComparer
Definition ZFComparer.h:262
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
common log messages for ZFFramework
#define ZFCoreAssertIndexRange(index, range)
log that likes "[file function (line)] index i out of range [0, n)"
Definition ZFCoreLog_CommonLog.h:115
#define zffinal
dummy macro shows that a method or class is designed must not to be overrided
Definition ZFCoreTypeDef_ClassType.h:63
#define zfclassLikePOD
shows the class is not a POD type, but you may use it like a POD except memset it to 0
Definition ZFCoreTypeDef_ClassType.h:41
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define zfnewPlacement(buf, Type,...)
placement new defined for future use, see zfnew for more info
Definition ZFCoreTypeDef_ClassType.h:123
#define zfpurevirtual
dummy macro shows that a method is pure virtual method
Definition ZFCoreTypeDef_ClassType.h:68
#define zfoverride
dummy macro shows that method override parent's method
Definition ZFCoreTypeDef_ClassType.h:58
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:198
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:202
void * zfmemmove(void *dst, const void *src, zfindex size)
wrapper to memmove
Definition ZFCoreTypeDef_ClassType.h:160
#define zfdeletePlacement(instance)
placement delete (instance->~Type()) defined for future use, see zfnew for more info
Definition ZFCoreTypeDef_ClassType.h:127
#define zfclassNotPOD
shows the class is not a POD type, you should not memset it or declare it in stack or copy value by c...
Definition ZFCoreTypeDef_ClassType.h:48
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:214
T_Element * zfmemmoveObject(T_Element *dst, const T_Element *src, zfindex count)
memmove for common object type, object must support operator =
Definition ZFCoreTypeDef_ClassType.h:170
void * zfmemcpy(void *dst, const void *src, zfindex size)
wrapper to memcpy
Definition ZFCoreTypeDef_ClassType.h:158
#define zfnullT
type for zfnull, can be used for function overload
Definition ZFCoreTypeDef_CoreType.h:85
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
#define zftrue
bool true type
Definition ZFCoreTypeDef_CoreType.h:107
#define zfindexMax()
(zfindex)-1, indicate a max index value, see zfindex
Definition ZFCoreTypeDef_CoreType.h:159
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
_ZFT_t_zfuint zfuint
same as unsigned int, see zfindex
Definition ZFCoreTypeDef_CoreType.h:169
#define ZFOUTPUT_TYPE(T_Type, outputAction)
declare your custom type conversion to string, convenient for debug
Definition ZFCoreTypeDef_OtherType.h:221
#define ZFOUTPUT_TYPE_TEMPLATE(T_typenameList, T_Type, outputAction)
see ZFOUTPUT_TYPE
Definition ZFCoreTypeDef_OtherType.h:262
ZFCompareResult
compare result of two ZFObjects
Definition ZFCoreTypeDef_OtherType.h:28
@ ZFCompareUncomparable
Definition ZFCoreTypeDef_OtherType.h:29
@ ZFCompareEqual
Definition ZFCoreTypeDef_OtherType.h:31
void zftToStringT(zfstring &s, T_Type const &v)
util function to obtain object info
Definition ZFCoreTypeDef_OtherType.h:182
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
math utilities for ZFFramework
zfbool zfmSortReversely(T_Holder &holder, zfindex left, zfindex right, T_Comparer const &comparer)
sort with custom comparer in range [left, right], holder must support operator []
Definition ZFCoreUtilMath.h:205
zfbool zfmSort(T_Holder &holder, zfindex left, zfindex right, T_Comparer const &comparer)
sort with custom comparer in range [left, right], holder must support operator []
Definition ZFCoreUtilMath.h:179
#define zfpoolDelete(obj)
see zfnew
Definition ZFMemPool.h:63
#define zfpoolFree(p)
see zfnew
Definition ZFMemPool.h:77
#define zfpoolNew(T_Type,...)
see zfnew
Definition ZFMemPool.h:62
#define zfpoolMalloc(size)
see zfnew
Definition ZFMemPool.h:75
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
string token util
#define ZFTokenForContainerDefault()
see ZFTokenForContainer, modifyable, ZFTokenForContainerTrim by default
Definition ZFToken.h:107
ZFCompareResult(*) Comparer(T_Comparable const &e0, T_Comparable2 const &e1)
see ZFComparer
Definition ZFCoreTypeDef_OtherType.h:130
dummy base for ZFCoreArray
Definition ZFCoreArray.h:110
virtual void objectInfoOfContentT(zfstring &ret, zfindex maxCount=((zfindex) -1), const ZFTokenForContainer &token=_ZFP_ZFTokenForContainerDefault) const =0
return content info
virtual void resize(zfindex count)=0
modify to hold specified count of element
virtual zfstring objectInfo(void) const
return object info
Definition ZFCoreArray.h:133
virtual ZFCoreArrayBase * refNew(void) const =0
new reference
virtual void refDelete(void)
delete reference
Definition ZFCoreArray.h:120
virtual zfindex genericFind(const void *e)=0
generic version
virtual void objectInfoT(zfstring &ret) const
see objectInfo
Definition ZFCoreArray.h:129
virtual void genericCopyFrom(const ZFCoreArrayBase &ref)=0
generic version
virtual void capacityTrim(void)=0
trim current capacity
virtual void genericAdd(const void *e, zfindex index)=0
generic version
virtual void removeFirst(void)
remove first, assert fail if out of range
Definition ZFCoreArray.h:198
virtual void * refImpl(void) const =0
get the impl
virtual void sort(zfindex start=0, zfindex count=((zfindex) -1))=0
sort
virtual void capacity(zfindex newCapacity)=0
change capacity to hold at least newCapacity
virtual void genericSwap(ZFCoreArrayBase &ref)=0
generic version
virtual void genericAdd(const void *e)
generic version
Definition ZFCoreArray.h:259
virtual void sortReversely(zfindex start=0, zfindex count=((zfindex) -1))=0
sort reversely
virtual const void * genericGet(zfindex index) const =0
generic version
virtual zfindex genericRemoveElementAll(const void *e)=0
generic version
virtual void remove(zfindex index)=0
remove element at index with count, assert fail if out of range
virtual void removeLast(void)
remove last, assert fail if out of range
Definition ZFCoreArray.h:204
virtual zfindex genericFindReversely(const void *e)=0
generic version
virtual void genericAddFrom(const ZFCoreArrayBase &ref)=0
generic version
virtual void move(zfindex fromIndex, zfindex toIndexOrIndexMax)=0
move element
virtual zfindex count(void) const =0
element count of this array
virtual zfstring objectInfoOfContent(zfindex maxCount=((zfindex) -1), const ZFTokenForContainer &token=_ZFP_ZFTokenForContainerDefault) const
return content info
Definition ZFCoreArray.h:146
virtual void remove(zfindex index, zfindex count)=0
remove element at index with count, assert fail if out of range
virtual zfbool isEmpty(void) const
true if empty
Definition ZFCoreArray.h:229
virtual void genericSet(zfindex index, const void *e)=0
generic version
virtual void removeAll(void)
remove all content
Definition ZFCoreArray.h:210
virtual zfindex capacity(void) const =0
get capacity
light weight array
Definition ZFCoreArray.h:297
virtual void capacityTrim(void)
trim current capacity
Definition ZFCoreArray.h:500
ZFCoreArray(void)
main constructor
Definition ZFCoreArray.h:308
virtual void capacity(zfindex newCapacity)
change capacity to hold at least newCapacity
Definition ZFCoreArray.h:496
zfindex removeElementAll(T_Element const &e, typename ZFComparer< T_Element >::Comparer comparer=_ZFP_CmpDef)
remove all matched element, return number of removed element
Definition ZFCoreArray.h:733
virtual void genericAddFrom(const ZFCoreArrayBase &ref)
generic version
Definition ZFCoreArray.h:989
virtual zfbool isEmpty(void) const
true if empty
Definition ZFCoreArray.h:913
zfbool removeElementReversely(T_Element const &e, typename ZFComparer< T_Element >::Comparer comparer=_ZFP_CmpDef)
remove last matched element, return whether the element removed
Definition ZFCoreArray.h:698
T_Element const & getLast(void) const
try to get first element, assert fail if empty
Definition ZFCoreArray.h:893
virtual void genericAdd(const void *e, zfindex index)
generic version
Definition ZFCoreArray.h:984
zfindex removeElementAll(T_Another const &e, typename ZFComparer< T_Element, T_Another >::Comparer comparer)
remove all matched element, return number of removed element
Definition ZFCoreArray.h:753
T_Element & get(zfindex index)
get element's reference at index
Definition ZFCoreArray.h:858
zfindex objectRetainCount(void) const
get retain count
Definition ZFCoreArray.h:406
virtual void objectInfoOfContentT(zfstring &ret, zfindex maxCount=((zfindex) -1), const ZFTokenForContainer &token=_ZFP_ZFTokenForContainerDefault) const
return content info
Definition ZFCoreArray.h:436
void add(T_Element const &e)
add element
Definition ZFCoreArray.h:536
virtual zfstring objectInfoOfContent(zfindex maxCount=((zfindex) -1), const ZFTokenForContainer &token=_ZFP_ZFTokenForContainerDefault) const
return content info
Definition ZFCoreArray.h:444
void sortReversely(zfindex start, zfindex count, typename ZFComparer< T_Element >::Comparer comparer)
sort element
Definition ZFCoreArray.h:957
zfbool removeElementReversely(T_Another const &e, typename ZFComparer< T_Element, T_Another >::Comparer comparer)
remove last matched element, return whether the element removed
Definition ZFCoreArray.h:716
virtual void genericCopyFrom(const ZFCoreArrayBase &ref)
generic version
Definition ZFCoreArray.h:976
void add(T_Element const &e, zfindex index)
add element at index
Definition ZFCoreArray.h:544
virtual zfbool isContain(T_Element const &e, typename ZFComparer< T_Element >::Comparer comparer=_ZFP_CmpDef) const
true if contains element
Definition ZFCoreArray.h:915
zfindex findReversely(T_Another const &e, typename ZFComparer< T_Element, T_Another >::Comparer comparer) const
find element reversely
Definition ZFCoreArray.h:646
virtual void remove(zfindex index)
remove element at index with count, assert fail if out of range
Definition ZFCoreArray.h:771
T_Element const & get(zfindex index) const
get element's const reference at index
Definition ZFCoreArray.h:865
T_Element & add(void)
add element and return reference
Definition ZFCoreArray.h:528
virtual zfindex genericFindReversely(const void *e)
generic version
Definition ZFCoreArray.h:980
void addFrom(const ZFCoreArray< T_Element > &ref)
add from another array
Definition ZFCoreArray.h:587
zfstring objectInfoOfContent(zfindex maxCount, const ZFTokenForContainer &token, typename ZFCoreInfoGetter< T_Element >::InfoGetter infoGetter) const
return content info
Definition ZFCoreArray.h:484
zfbool removeElement(T_Another const &e, typename ZFComparer< T_Element, T_Another >::Comparer comparer)
remove first matched element, return whether the element removed
Definition ZFCoreArray.h:681
T_Element removeAndGet(zfindex index)
remove and return the removed value
Definition ZFCoreArray.h:793
T_Element removeLastAndGet(void)
remove last and return the removed value, or assert fail if empty
Definition ZFCoreArray.h:811
virtual zfindex capacity(void) const
get capacity
Definition ZFCoreArray.h:508
T_Element const & getFirst(void) const
try to get first element, assert fail if empty
Definition ZFCoreArray.h:886
virtual const void * genericGet(zfindex index) const
generic version
Definition ZFCoreArray.h:996
zfindex findReversely(T_Element const &e, typename ZFComparer< T_Element >::Comparer comparer=_ZFP_CmpDef) const
find element reversely
Definition ZFCoreArray.h:612
zfindex find(T_Element const &e, typename ZFComparer< T_Element >::Comparer comparer=_ZFP_CmpDef) const
find element
Definition ZFCoreArray.h:596
virtual void move(zfindex fromIndex, zfindex toIndexOrIndexMax)
move element
Definition ZFCoreArray.h:818
ZFCoreArray(const ZFCoreArray< T_Element > &ref)
construct from another array
Definition ZFCoreArray.h:316
void set(zfindex index, T_Element const &e)
set element at index, or assert fail if index out of range
Definition ZFCoreArray.h:846
T_Element removeFirstAndGet(void)
remove first and return the removed value, or assert fail if empty
Definition ZFCoreArray.h:802
void swap(ZFCoreArray< T_Element > &ref)
swap internal data
Definition ZFCoreArray.h:381
virtual void genericSet(zfindex index, const void *e)
generic version
Definition ZFCoreArray.h:991
void objectInfoOfContentT(zfstring &ret, zfindex maxCount, const ZFTokenForContainer &token, typename ZFCoreInfoGetter< T_Element >::InfoGetter infoGetter) const
see objectInfoOfContent
Definition ZFCoreArray.h:454
virtual void remove(zfindex index, zfindex count)
remove element at index with count, assert fail if out of range
Definition ZFCoreArray.h:778
void sort(zfindex start, zfindex count, typename ZFComparer< T_Element >::Comparer comparer)
sort element
Definition ZFCoreArray.h:940
virtual zfindex genericFind(const void *e)
generic version
Definition ZFCoreArray.h:978
void addFrom(const T_Element *src, zfindex count)
add elements, src can be part of this array's buffer
Definition ZFCoreArray.h:564
T_Element * arrayBuf(void)
directly access the array
Definition ZFCoreArray.h:904
void copyFrom(const ZFCoreArray< T_Element > &ref)
copy all settings and contents from another array
Definition ZFCoreArray.h:390
const T_Element * arrayBuf(void) const
see arrayBuf
Definition ZFCoreArray.h:908
zfbool removeElement(T_Element const &e, typename ZFComparer< T_Element >::Comparer comparer=_ZFP_CmpDef)
remove first matched element, return whether the element removed
Definition ZFCoreArray.h:663
virtual void genericSwap(ZFCoreArrayBase &ref)
generic version
Definition ZFCoreArray.h:974
ZFCoreArray(const zft_zfnullT &dummy)
dummy constructor
Definition ZFCoreArray.h:312
virtual void sort(zfindex start=0, zfindex count=((zfindex) -1))
sort
Definition ZFCoreArray.h:924
virtual ZFCoreArrayBase * refNew(void) const
new reference
Definition ZFCoreArray.h:336
ZFCompareResult objectCompare(const ZFCoreArray< T_Element > &ref) const
compare by instance
Definition ZFCoreArray.h:410
virtual zfindex count(void) const
element count of this array
Definition ZFCoreArray.h:911
virtual void sortReversely(zfindex start=0, zfindex count=((zfindex) -1))
sort reversely
Definition ZFCoreArray.h:931
T_Element ValueType
value type
Definition ZFCoreArray.h:302
ZFCompareResult objectCompareValue(const ZFCoreArray< T_Element > &ref, typename ZFComparer< T_Element >::Comparer comparer=_ZFP_CmpDef) const
compare by content
Definition ZFCoreArray.h:416
virtual void * refImpl(void) const
get the impl
Definition ZFCoreArray.h:338
zfindex find(T_Another const &e, typename ZFComparer< T_Element, T_Another >::Comparer comparer) const
find element
Definition ZFCoreArray.h:629
virtual void resize(zfindex count)
modify to hold specified count of element
Definition ZFCoreArray.h:513
virtual zfindex genericRemoveElementAll(const void *e)
generic version
Definition ZFCoreArray.h:982
ZFCoreArray< T_Element > & refPrepare(void)
prepare instance to make it able to be shared between each copy
Definition ZFCoreArray.h:334
void(*) InfoGetter(zfstring &ret, T_Type const &v)
proto type for obtain object info, see zftToStringT
Definition ZFCoreTypeDef_OtherType.h:151
util class to hold string tokens
Definition ZFToken.h:17
void ZFCoreCapacityOptimize(zfindex &capacity)
util to optimize capacity
Definition zfstring.h:20