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
182 virtual void remove(ZF_IN zfindex index) zfpurevirtual;
186 virtual void remove(
187 ZF_IN zfindex index
193 virtual void removeFirst(void) {
194 this->remove(0);
195 }
196
199 virtual void removeLast(void) {
200 this->remove(this->count() - 1);
201 }
202
205 virtual void removeAll(void) {
206 if(!this->isEmpty()) {
207 this->remove(0, this->count());
208 }
209 }
210
213 virtual void move(
214 ZF_IN zfindex fromIndex
215 , ZF_IN zfindex toIndexOrIndexMax
220 virtual zfindex count(void) const zfpurevirtual;
224 virtual zfbool isEmpty(void) const {
225 return this->count() != 0;
226 }
227
230 virtual void sort(
231 ZF_IN_OPT zfindex start = 0
237 virtual void sortReversely(
238 ZF_IN_OPT zfindex start = 0
241
242public:
248 virtual zfindex genericFind(ZF_IN const void *e) zfpurevirtual;
254 virtual void genericAdd(ZF_IN const void *e) {
255 this->genericAdd(e, zfindexMax());
256 }
257
258 virtual void genericAdd(
259 ZF_IN const void *e
260 , ZF_IN zfindex index
265 virtual void genericSet(
266 ZF_IN zfindex index
267 , ZF_IN const void *e
270 virtual const void *genericGet(ZF_IN zfindex index) const zfpurevirtual;
271};
272ZFOUTPUT_TYPE(ZFCoreArrayBase, {v.objectInfoT(s);})
273
274// ============================================================
291template<typename T_Element>
293public:
297 typedef T_Element ValueType;
298
299public:
303 ZFCoreArray(void) : d(zfnull) {}
307 ZFCoreArray(ZF_IN const zfnullT &dummy) : d(zfnull) {}
312 : d(ref.d)
313 {
314 if(d) {
315 ++(d->refCount);
316 }
317 }
318 virtual ~ZFCoreArray(void) {
319 if(d) {
320 --(d->refCount);
321 if(d->refCount == 0) {
322 zfpoolDelete(d);
323 }
324 }
325 }
329 ZFCoreArray<T_Element> &refPrepare(void) {if(d == zfnull) {d = zfpoolNew(_ZFP_ZFCoreArrayPrivate<T_Element>);} return *this;}
331 virtual ZFCoreArrayBase *refNew(void) const {return zfpoolNew(ZFCoreArray<T_Element>, *this);}
333 virtual void *refImpl(void) const {return d;}
338 _ZFP_ZFCoreArrayPrivate<T_Element> *dTmp = d;
339 d = ref.d;
340 if(d) {
341 ++(d->refCount);
342 }
343 if(dTmp) {
344 --(dTmp->refCount);
345 if(dTmp->refCount == 0) {
346 zfpoolDelete(dTmp);
347 }
348 }
349 return *this;
350 }
351
352 ZFCoreArray<T_Element> &operator = (ZF_IN const zfnullT &dummy) {
353 this->removeAll();
354 return *this;
355 }
356 zfbool operator == (ZF_IN const zfnullT &dummy) const {return this->isEmpty();}
357 zfbool operator != (ZF_IN const zfnullT &dummy) const {return !this->isEmpty();}
358 zfbool operator == (ZF_IN const ZFCoreArray<T_Element> &ref) const {return (d == ref.d);}
359 zfbool operator != (ZF_IN const ZFCoreArray<T_Element> &ref) const {return (d != ref.d);}
361 virtual ZFCoreArrayBase &operator = (ZF_IN const ZFCoreArrayBase &ref) {
362 return this->operator = ((const ZFCoreArray<T_Element> &)ref);
363 }
364 virtual zfbool operator == (ZF_IN const ZFCoreArrayBase &ref) const {
365 return this->operator == ((const ZFCoreArray<T_Element> &)ref);
366 }
367 virtual zfbool operator != (ZF_IN const ZFCoreArrayBase &ref) const {
368 return this->operator == ((const ZFCoreArray<T_Element> &)ref);
369 }
371
372public:
377 _ZFP_ZFCoreArrayPrivate<T_Element> *dTmp = d;
378 d = ref.d;
379 ref.d = dTmp;
380 }
381
386 if(d != ref.d) {
387 if(d && d->buf) {
388 _ZFP_ZFCoreArrayW<T_Element>::objDestroy(d->buf, d->buf + d->count);
389 d->count = 0;
390 }
391 if(ref.d) {
392 _capacityRequire(ref.count());
393 _ZFP_ZFCoreArrayW<T_Element>::objCreate(d->buf, d->buf + ref.count(), ref.arrayBuf());
394 d->count = (zfuint)ref.count();
395 }
396 }
397 }
398
401 zfindex objectRetainCount(void) const {return d ? d->refCount : 0;}
408
414 ) const {
415 if(d == ref.d) {
416 return ZFCompareEqual;
417 }
418 if(this->count() != ref.count()) {
420 }
421 for(zfindex i = this->count() - 1; i != zfindexMax(); --i) {
422 if(comparer(this->get(i), ref.get(i)) != ZFCompareEqual) {
424 }
425 }
426 return ZFCompareEqual;
427 }
428
429public:
433 , ZF_IN_OPT zfindex maxCount = zfindexMax()
435 ) const {
436 this->objectInfoOfContentT(ret, maxCount, token, zfnull);
437 }
440 ZF_IN_OPT zfindex maxCount = zfindexMax()
442 ) const {
443 zfstring ret;
444 this->objectInfoOfContentT(ret, maxCount, token, zfnull);
445 return ret;
446 }
447
451 , ZF_IN_OPT zfindex maxCount
452 , ZF_IN_OPT const ZFTokenForContainer &token
454 ) const {
455 zfindex count = 0;
456 ret += token.tokenLeft;
457 for(; count < this->count() && count < maxCount; ++count) {
458 if(count > 0) {
459 ret += token.tokenSeparator;
460 }
461 ret += token.tokenValueLeft;
462 if(infoGetter != zfnull) {
463 infoGetter(ret, this->get(count));
464 }
465 else {
466 zftToStringT(ret, this->get(count));
467 }
468 ret += token.tokenValueRight;
469 }
470 if(count < this->count()) {
471 if(count > 0) {
472 ret += token.tokenSeparator;
473 }
474 ret += token.tokenEtc;
475 }
476 ret += token.tokenRight;
477 }
478
480 ZF_IN_OPT zfindex maxCount
481 , ZF_IN_OPT const ZFTokenForContainer &token
483 ) const {
484 zfstring ret;
485 this->objectInfoOfContentT(ret, maxCount, token, infoGetter);
486 return ret;
487 }
488
489public:
491 virtual void capacity(ZF_IN zfindex newCapacity) {
492 _capacityRequire(newCapacity);
493 }
495 virtual void capacityTrim(void) {
496 zfindex capacity = this->count();
497 _capacityOptimize(capacity);
498 if(capacity != this->capacity()) {
499 _capacityDoChange(capacity);
500 }
501 }
503 virtual zfindex capacity(void) const {
504 return (zfindex)(d ? d->capacity : 0);
505 }
506
507public:
511 void add(ZF_IN T_Element const &e) {
512 _capacityRequire(this->count() + 1);
513 _ZFP_ZFCoreArrayW<T_Element>::objCreate(d->buf + d->count, d->buf + d->count + 1, &e);
514 ++(d->count);
515 }
516
519 void add(
520 ZF_IN T_Element const &e
521 , ZF_IN zfindex index
522 ) {
523 if(index == zfindexMax()) {
524 index = this->count();
525 }
526 else {
527 ZFCoreAssertIndexRange(index, this->count() + 1);
528 }
529 _capacityRequire(this->count() + 1);
530 _ZFP_ZFCoreArrayW<T_Element>::objCreate(d->buf + d->count, d->buf + d->count + 1);
531 T_Element *pos = d->buf + index;
532 _ZFP_ZFCoreArrayW<T_Element>::objMove(pos + 1, pos, this->count() - index);
533 ++(d->count);
534 *pos = e;
535 }
536
540 ZF_IN const T_Element *src
542 ) {
543 if(src == zfnull || count == 0) {
544 return;
545 }
546 if(d == zfnull || src < d->buf || src >= d->buf + d->capacity) {
547 _capacityRequire(this->count() + count);
548 _ZFP_ZFCoreArrayW<T_Element>::objCreate(d->buf + d->count, d->buf + d->count + count, src);
549 d->count += (zfuint)count;
550 }
551 else {
553 tmp.capacity(count);
554 tmp.addFrom(src, count);
555 this->addFrom(tmp.arrayBuf(), count);
556 }
557 }
558
563 if(d != ref.d) {
564 this->addFrom(ref.arrayBuf(), ref.count());
565 }
566 }
567
572 ZF_IN T_Element const &e
574 ) const {
575 if(d) {
576 for(T_Element *p = d->buf, *pEnd = d->buf + d->count; p < pEnd; ++p) {
577 if(comparer(*p, e) == ZFCompareEqual) {
578 return (p - d->buf);
579 }
580 }
581 }
582 return zfindexMax();
583 }
584
588 ZF_IN T_Element const &e
590 ) const {
591 if(d && d->buf) {
592 for(T_Element *p = d->buf + d->count - 1; p >= d->buf; --p) {
593 if(comparer(*p, e) == ZFCompareEqual) {
594 return (p - d->buf);
595 }
596 }
597 }
598 return zfindexMax();
599 }
600
603 template<typename T_Another>
605 ZF_IN T_Another const &e
607 ) const {
608 if(d) {
609 for(T_Element *p = d->buf, *pEnd = d->buf + d->count; p < pEnd; ++p) {
610 if(comparer(*p, e) == ZFCompareEqual) {
611 return (p - d->buf);
612 }
613 }
614 }
615 return zfindexMax();
616 }
617
620 template<typename T_Another>
622 ZF_IN T_Another const &e
624 ) const {
625 if(d && d->buf) {
626 for(T_Element *p = d->buf + d->count - 1; p >= d->buf; --p) {
627 if(comparer(*p, e) == ZFCompareEqual) {
628 return (p - d->buf);
629 }
630 }
631 }
632 return zfindexMax();
633 }
634
639 ZF_IN T_Element const &e
641 ) {
642 if(d) {
643 for(T_Element *p = d->buf, *pEnd = d->buf + d->count; p < pEnd; ++p) {
644 if(comparer(*p, e) == ZFCompareEqual) {
645 this->remove(p - d->buf);
646 return zftrue;
647 }
648 }
649 }
650 return zffalse;
651 }
652
655 template<typename T_Another>
657 ZF_IN T_Another const &e
659 ) {
660 if(d) {
661 for(T_Element *p = d->buf, *pEnd = d->buf + d->count; p < pEnd; ++p) {
662 if(comparer(*p, e) == ZFCompareEqual) {
663 this->remove(p - d->buf);
664 return zftrue;
665 }
666 }
667 }
668 return zffalse;
669 }
670
674 ZF_IN T_Element const &e
676 ) {
677 if(d && d->buf) {
678 for(T_Element *p = d->buf + d->count - 1; p >= d->buf; --p) {
679 if(comparer(*p, e) == ZFCompareEqual) {
680 this->remove(p - d->buf);
681 return zftrue;
682 }
683 }
684 }
685 return zffalse;
686 }
687
690 template<typename T_Another>
692 ZF_IN T_Another const &e
694 ) {
695 if(d && d->buf) {
696 for(T_Element *p = d->buf + d->count - 1; p >= d->buf; --p) {
697 if(comparer(*p, e) == ZFCompareEqual) {
698 this->remove(p - d->buf);
699 return zftrue;
700 }
701 }
702 }
703 return zffalse;
704 }
705
709 ZF_IN T_Element const &e
711 ) {
712 zfindex removedCount = 0;
713 if(d) {
714 for(T_Element *p = d->buf, *pEnd = d->buf + d->count; p < pEnd; ++p) {
715 if(comparer(*p, e) == ZFCompareEqual) {
716 ++removedCount;
717 this->remove(p - d->buf);
718 --p;
719 }
720 }
721 }
722 return removedCount;
723 }
724
727 template<typename T_Another>
729 ZF_IN T_Another const &e
731 ) {
732 zfindex removedCount = 0;
733 if(d) {
734 for(T_Element *p = d->buf, *pEnd = d->buf + d->count; p < pEnd; ++p) {
735 if(comparer(*p, e) == ZFCompareEqual) {
736 ++removedCount;
737 this->remove(p - d->buf);
738 --p;
739 }
740 }
741 }
742 return removedCount;
743 }
744
746 virtual void remove(ZF_IN zfindex index) {
747 ZFCoreAssertIndexRange(index, this->count());
748 _ZFP_ZFCoreArrayW<T_Element>::objMove(d->buf + index, d->buf + index + 1, this->count() - index - 1);
749 _ZFP_ZFCoreArrayW<T_Element>::objDestroy(d->buf + d->count - 1, d->buf + d->count);
750 --(d->count);
751 }
753 virtual void remove(
754 ZF_IN zfindex index
756 ) {
757 ZFCoreAssertIndexRange(index, this->count());
758 if(count > this->count() - index) {
759 count = this->count() - index;
760 }
761 _ZFP_ZFCoreArrayW<T_Element>::objMove(d->buf + index, d->buf + index + count, this->count() - (index + count));
762 _ZFP_ZFCoreArrayW<T_Element>::objDestroy(d->buf + d->count - count, d->buf + d->count);
763 d->count -= (zfuint)count;
764 }
765
768 T_Element removeAndGet(ZF_IN zfindex index) {
769 T_Element t = this->get(index);
770 this->remove(index);
771 return t;
772 }
773
777 T_Element removeFirstAndGet(void) {
778 T_Element t = this->getFirst();
779 this->removeFirst();
780 return t;
781 }
782
786 T_Element removeLastAndGet(void) {
787 T_Element t = this->getLast();
788 this->removeLast();
789 return t;
790 }
791
793 virtual void move(
794 ZF_IN zfindex fromIndex
795 , ZF_IN zfindex toIndexOrIndexMax
796 ) {
797 ZFCoreAssertIndexRange(fromIndex, this->count());
798 if(toIndexOrIndexMax == zfindexMax()) {
799 toIndexOrIndexMax = this->count() - 1;
800 }
801 else {
802 ZFCoreAssertIndexRange(toIndexOrIndexMax, this->count());
803 }
804 if(fromIndex == toIndexOrIndexMax) {
805 return;
806 }
807 T_Element t = d->buf[fromIndex];
808 if(fromIndex < toIndexOrIndexMax) {
809 _ZFP_ZFCoreArrayW<T_Element>::objMove(d->buf + fromIndex, d->buf + fromIndex + 1, toIndexOrIndexMax - fromIndex);
810 }
811 else {
812 _ZFP_ZFCoreArrayW<T_Element>::objMove(d->buf + toIndexOrIndexMax + 1, d->buf + toIndexOrIndexMax, fromIndex - toIndexOrIndexMax);
813 }
814 d->buf[toIndexOrIndexMax] = t;
815 }
816
817public:
821 void set(
822 ZF_IN zfindex index
823 , ZF_IN T_Element const &e
824 ) {
825 ZFCoreAssertIndexRange(index, this->count());
826 d->buf[index] = e;
827 }
828
829public:
833 T_Element &get(ZF_IN zfindex index) {
834 ZFCoreAssertIndexRange(index, this->count());
835 return d->buf[index];
836 }
837
840 T_Element const &get(ZF_IN zfindex index) const {
841 ZFCoreAssertIndexRange(index, this->count());
842 return d->buf[index];
843 }
844
847 T_Element &operator [] (ZF_IN zfindex index) {
848 ZFCoreAssertIndexRange(index, this->count());
849 return d->buf[index];
850 }
851
854 T_Element const &operator [] (ZF_IN zfindex index) const {
855 ZFCoreAssertIndexRange(index, this->count());
856 return d->buf[index];
857 }
858
861 T_Element const &getFirst(void) const {
862 ZFCoreAssertIndexRange(0, this->count());
863 return *(d->buf);
864 }
865
868 T_Element const &getLast(void) const {
869 ZFCoreAssertIndexRange(0, this->count());
870 return *(d->buf + d->count - 1);
871 }
872
879 T_Element *arrayBuf(void) {return d ? d->buf : zfnull;}
883 const T_Element *arrayBuf(void) const {return d ? d->buf : zfnull;}
884
886 virtual zfindex count(void) const {return (zfindex)(d ? d->count : 0);}
888 virtual zfbool isEmpty(void) const {return (d == zfnull || d->count == 0);}
891 ZF_IN T_Element const &e
893 ) const {
894 return this->find(e, comparer) != zfindexMax();
895 }
896
897public:
899 virtual void sort(
900 ZF_IN_OPT zfindex start = 0
902 ) {
903 this->sort(start, count, ZFComparerDefault);
904 }
906 virtual void sortReversely(
907 ZF_IN_OPT zfindex start = 0
909 ) {
911 }
912
915 void sort(
916 ZF_IN zfindex start
918 , ZF_IN typename ZFComparer<T_Element>::Comparer comparer
919 ) {
920 if(!this->isEmpty() && start + 1 < this->count() && count > 1) {
922 d->buf
923 , start
924 , (count > this->count() - start) ? (this->count() - 1) : (start + count - 1)
925 , comparer
926 );
927 }
928 }
929
933 ZF_IN zfindex start
935 , ZF_IN typename ZFComparer<T_Element>::Comparer comparer
936 ) {
937 if(!this->isEmpty() && start + 1 < this->count() && count > 1) {
939 d->buf
940 , start
941 , (count > this->count() - start) ? (this->count() - 1) : (start + count - 1)
942 , comparer
943 );
944 }
945 }
946
947public:
951 virtual void genericCopyFrom(ZF_IN const ZFCoreArrayBase &ref) {this->copyFrom((const ZFCoreArray<T_Element> &)ref);}
953 virtual zfindex genericFind(ZF_IN const void *e) {return this->find(*(const T_Element *)e);}
955 virtual zfindex genericFindReversely(ZF_IN const void *e) {return this->findReversely(*(const T_Element *)e);}
957 virtual zfindex genericRemoveElementAll(ZF_IN const void *e) {return this->removeElementAll(*(const T_Element *)e);}
959 virtual void genericAdd(
960 ZF_IN const void *e
961 , ZF_IN zfindex index
962 ) {this->add(*(const T_Element *)e, index);}
964 virtual void genericAddFrom(ZF_IN const ZFCoreArrayBase &ref) {this->addFrom((const ZFCoreArray<T_Element> &)ref);}
966 virtual void genericSet(
967 ZF_IN zfindex index
968 , ZF_IN const void *e
969 ) {this->set(index, *(const T_Element *)e);}
971 virtual const void *genericGet(ZF_IN zfindex index) const {return &(this->get(index));}
972
973private:
974 _ZFP_ZFCoreArrayPrivate<T_Element> *d;
975private:
976 inline void _capacityOptimize(ZF_IN_OUT zfindex &capacity) {
978 }
979 inline void _capacityRequire(ZF_IN zfindex capacity) {
980 _capacityOptimize(capacity);
981 if(capacity > this->capacity()) {
982 _capacityDoChange(capacity);
983 }
984 }
985 void _capacityDoChange(ZF_IN zfindex capacity) {
986 if(capacity == 0) {
987 if(d) {
988 _ZFP_ZFCoreArrayW<T_Element>::objDestroy(d->buf, d->buf + d->count);
989 zfpoolFree(d->buf);
990 d->buf = zfnull;
991 d->capacity = 0;
992 d->count = 0;
993 }
994 }
995 else {
996 if(d == zfnull) {
997 d = zfpoolNew(_ZFP_ZFCoreArrayPrivate<T_Element>);
998 }
999
1000 T_Element *oldBuf = d->buf;
1001 zfuint oldCount = d->count;
1002
1003 T_Element *newBuf = (T_Element *)zfpoolMalloc(capacity * sizeof(T_Element));
1004 _ZFP_ZFCoreArrayW<T_Element>::objCreate(newBuf, newBuf + oldCount, oldBuf);
1005
1006 d->buf = newBuf;
1007 d->capacity = (zfuint)capacity;
1008 d->count = oldCount;
1009
1010 _ZFP_ZFCoreArrayW<T_Element>::objDestroy(oldBuf, oldBuf + oldCount);
1011 zfpoolFree(oldBuf);
1012 }
1013 }
1014};
1015ZFOUTPUT_TYPE_TEMPLATE(typename T_Element, ZFCoreArray<T_Element>, {v.objectInfoT(s);})
1016
1017template<typename T_Element>
1018zfclassLikePOD _ZFP_ZFCoreArrayCreate {
1019public:
1020 inline _ZFP_ZFCoreArrayCreate<T_Element> &add(ZF_IN T_Element const &v) {
1021 this->v.add(v);
1022 return *this;
1023 }
1024
1025public:
1027};
1028#define _ZFP_ZFCoreArrayCreate_action_expand(value) .add(value)
1029#define _ZFP_ZFCoreArrayCreate_action(CreatorType, values, ...) \
1030 CreatorType() ZFM_FIX_PARAM(_ZFP_ZFCoreArrayCreate_action_expand, ZFM_EMPTY, values, ##__VA_ARGS__) .v
1039#define ZFCoreArrayCreate(ElementType, values, ...) _ZFP_ZFCoreArrayCreate_action(_ZFP_ZFCoreArrayCreate<ElementType>, values, ##__VA_ARGS__)
1040
1042
1043#endif // #ifndef _ZFI_ZFCoreArray_h_
1044
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:116
#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:122
#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:196
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:200
void * zfmemmove(void *dst, const void *src, zfindex size)
wrapper to memmove
Definition ZFCoreTypeDef_ClassType.h:158
#define zfdeletePlacement(instance)
placement delete (instance->~Type()) defined for future use, see zfnew for more info
Definition ZFCoreTypeDef_ClassType.h:125
#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:212
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:168
void * zfmemcpy(void *dst, const void *src, zfindex size)
wrapper to memcpy
Definition ZFCoreTypeDef_ClassType.h:156
#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:81
#define zfpoolFree(p)
see zfnew
Definition ZFMemPool.h:100
#define zfpoolNew(T_Type,...)
see zfnew
Definition ZFMemPool.h:80
#define zfpoolMalloc(size)
see zfnew
Definition ZFMemPool.h:98
#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 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:193
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:254
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:199
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:224
virtual void genericSet(zfindex index, const void *e)=0
generic version
virtual void removeAll(void)
remove all content
Definition ZFCoreArray.h:205
virtual zfindex capacity(void) const =0
get capacity
light weight array
Definition ZFCoreArray.h:292
virtual void capacityTrim(void)
trim current capacity
Definition ZFCoreArray.h:495
ZFCoreArray(void)
main constructor
Definition ZFCoreArray.h:303
virtual void capacity(zfindex newCapacity)
change capacity to hold at least newCapacity
Definition ZFCoreArray.h:491
virtual void genericAddFrom(const ZFCoreArrayBase &ref)
generic version
Definition ZFCoreArray.h:964
virtual zfbool isEmpty(void) const
true if empty
Definition ZFCoreArray.h:888
T_Element const & getLast(void) const
try to get first element, assert fail if empty
Definition ZFCoreArray.h:868
virtual void genericAdd(const void *e, zfindex index)
generic version
Definition ZFCoreArray.h:959
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:728
T_Element & get(zfindex index)
get element's reference at index
Definition ZFCoreArray.h:833
zfindex objectRetainCount(void) const
get retain count
Definition ZFCoreArray.h:401
virtual void objectInfoOfContentT(zfstring &ret, zfindex maxCount=((zfindex) -1), const ZFTokenForContainer &token=_ZFP_ZFTokenForContainerDefault) const
return content info
Definition ZFCoreArray.h:431
void add(T_Element const &e)
add element
Definition ZFCoreArray.h:511
zfbool removeElementReversely(T_Element const &e, typename ZFComparer< T_Element >::Comparer comparer=_ZFP_ZFComparerDefault)
remove last matched element, return whether the element removed
Definition ZFCoreArray.h:673
virtual zfstring objectInfoOfContent(zfindex maxCount=((zfindex) -1), const ZFTokenForContainer &token=_ZFP_ZFTokenForContainerDefault) const
return content info
Definition ZFCoreArray.h:439
void sortReversely(zfindex start, zfindex count, typename ZFComparer< T_Element >::Comparer comparer)
sort element
Definition ZFCoreArray.h:932
virtual zfbool isContain(T_Element const &e, typename ZFComparer< T_Element >::Comparer comparer=_ZFP_ZFComparerDefault) const
true if contains element
Definition ZFCoreArray.h:890
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:691
virtual void genericCopyFrom(const ZFCoreArrayBase &ref)
generic version
Definition ZFCoreArray.h:951
void add(T_Element const &e, zfindex index)
add element at index
Definition ZFCoreArray.h:519
zfindex findReversely(T_Another const &e, typename ZFComparer< T_Element, T_Another >::Comparer comparer) const
find element reversely
Definition ZFCoreArray.h:621
virtual void remove(zfindex index)
remove element at index with count, assert fail if out of range
Definition ZFCoreArray.h:746
T_Element const & get(zfindex index) const
get element's const reference at index
Definition ZFCoreArray.h:840
virtual zfindex genericFindReversely(const void *e)
generic version
Definition ZFCoreArray.h:955
zfindex find(T_Element const &e, typename ZFComparer< T_Element >::Comparer comparer=_ZFP_ZFComparerDefault) const
find element
Definition ZFCoreArray.h:571
void addFrom(const ZFCoreArray< T_Element > &ref)
add from another array
Definition ZFCoreArray.h:562
zfstring objectInfoOfContent(zfindex maxCount, const ZFTokenForContainer &token, typename ZFCoreInfoGetter< T_Element >::InfoGetter infoGetter) const
return content info
Definition ZFCoreArray.h:479
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:656
T_Element removeAndGet(zfindex index)
remove and return the removed value
Definition ZFCoreArray.h:768
T_Element removeLastAndGet(void)
remove last and return the removed value, or assert fail if empty
Definition ZFCoreArray.h:786
virtual zfindex capacity(void) const
get capacity
Definition ZFCoreArray.h:503
T_Element const & getFirst(void) const
try to get first element, assert fail if empty
Definition ZFCoreArray.h:861
virtual const void * genericGet(zfindex index) const
generic version
Definition ZFCoreArray.h:971
virtual void move(zfindex fromIndex, zfindex toIndexOrIndexMax)
move element
Definition ZFCoreArray.h:793
ZFCoreArray(const ZFCoreArray< T_Element > &ref)
construct from another array
Definition ZFCoreArray.h:311
ZFCompareResult objectCompareValue(const ZFCoreArray< T_Element > &ref, typename ZFComparer< T_Element >::Comparer comparer=_ZFP_ZFComparerDefault) const
compare by content
Definition ZFCoreArray.h:411
void set(zfindex index, T_Element const &e)
set element at index, or assert fail if index out of range
Definition ZFCoreArray.h:821
T_Element removeFirstAndGet(void)
remove first and return the removed value, or assert fail if empty
Definition ZFCoreArray.h:777
zfindex removeElementAll(T_Element const &e, typename ZFComparer< T_Element >::Comparer comparer=_ZFP_ZFComparerDefault)
remove all matched element, return number of removed element
Definition ZFCoreArray.h:708
void swap(ZFCoreArray< T_Element > &ref)
swap internal data
Definition ZFCoreArray.h:376
virtual void genericSet(zfindex index, const void *e)
generic version
Definition ZFCoreArray.h:966
void objectInfoOfContentT(zfstring &ret, zfindex maxCount, const ZFTokenForContainer &token, typename ZFCoreInfoGetter< T_Element >::InfoGetter infoGetter) const
see objectInfoOfContent
Definition ZFCoreArray.h:449
virtual void remove(zfindex index, zfindex count)
remove element at index with count, assert fail if out of range
Definition ZFCoreArray.h:753
void sort(zfindex start, zfindex count, typename ZFComparer< T_Element >::Comparer comparer)
sort element
Definition ZFCoreArray.h:915
virtual zfindex genericFind(const void *e)
generic version
Definition ZFCoreArray.h:953
void addFrom(const T_Element *src, zfindex count)
add elements, src can be part of this array's buffer
Definition ZFCoreArray.h:539
T_Element * arrayBuf(void)
directly access the array
Definition ZFCoreArray.h:879
zfbool removeElement(T_Element const &e, typename ZFComparer< T_Element >::Comparer comparer=_ZFP_ZFComparerDefault)
remove first matched element, return whether the element removed
Definition ZFCoreArray.h:638
void copyFrom(const ZFCoreArray< T_Element > &ref)
copy all settings and contents from another array
Definition ZFCoreArray.h:385
const T_Element * arrayBuf(void) const
see arrayBuf
Definition ZFCoreArray.h:883
zfindex findReversely(T_Element const &e, typename ZFComparer< T_Element >::Comparer comparer=_ZFP_ZFComparerDefault) const
find element reversely
Definition ZFCoreArray.h:587
virtual void genericSwap(ZFCoreArrayBase &ref)
generic version
Definition ZFCoreArray.h:949
ZFCoreArray(const zft_zfnullT &dummy)
dummy constructor
Definition ZFCoreArray.h:307
virtual void sort(zfindex start=0, zfindex count=((zfindex) -1))
sort
Definition ZFCoreArray.h:899
virtual ZFCoreArrayBase * refNew(void) const
new reference
Definition ZFCoreArray.h:331
ZFCompareResult objectCompare(const ZFCoreArray< T_Element > &ref) const
compare by instance
Definition ZFCoreArray.h:405
virtual zfindex count(void) const
element count of this array
Definition ZFCoreArray.h:886
virtual void sortReversely(zfindex start=0, zfindex count=((zfindex) -1))
sort reversely
Definition ZFCoreArray.h:906
T_Element ValueType
value type
Definition ZFCoreArray.h:297
virtual void * refImpl(void) const
get the impl
Definition ZFCoreArray.h:333
zfindex find(T_Another const &e, typename ZFComparer< T_Element, T_Another >::Comparer comparer) const
find element
Definition ZFCoreArray.h:604
virtual zfindex genericRemoveElementAll(const void *e)
generic version
Definition ZFCoreArray.h:957
ZFCoreArray< T_Element > & refPrepare(void)
prepare instance to make it able to be shared between each copy
Definition ZFCoreArray.h:329
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