1
1
/* -*-C++-*-
2
-
3
2
!!! NOTE: this version has been hacked up to work with SwitchActor.
4
3
5
4
This file is part of a set of general purpose libraries to extend C++,
21
20
22
21
_CC_NO_INLINE_LOOPS -> 1 if compiler does NOT inline loops,
23
22
0 (default) if inlining of loops is done.
24
-
25
- BUGS:
26
23
*/
27
- #ifndef _cxArray_h
28
- #define _cxArray_h
24
+ #pragma once
29
25
30
26
#define SA_HACK 1 // 1 to use the hacks for SwitchActor.
31
27
@@ -114,7 +110,6 @@ inline void cxBitCopyRange(T* dst, T* src, int start, int end)
114
110
memmove (dst, src, sizeof (T)*(end-start));
115
111
}
116
112
117
-
118
113
// ----------------------------------------------------------------------
119
114
// class array
120
115
// type safe and access safe array data type
@@ -132,30 +127,20 @@ class cxBaseAB
132
127
cxBaseAB () {}
133
128
// this function should return non-zero if the destructor should be called.
134
129
// when old data arrays are deleted, or when ~cxArrayB is called.
135
- #if 1
136
130
static int destroyArray () { return 1 ; }
137
- #else
138
- static const int destroyArray() { return 1; }
139
- #endif
140
131
// static int destroyArray(cxArrayB<T,AB>&)
141
132
142
133
// this function should return non-zero if the assignment operator
143
134
// should be used to copy elements between old and new arrays.
144
135
// Other bitwise copy (using mem moves) will be used.
145
- #if 1
146
136
static int assignToCopy () { return 1 ; }
147
- #else
148
- static const int assignToCopy() { return 1; }
149
- #endif
150
137
151
138
static void assertionFailed (const char * test, const char * file, int line)
152
139
{
153
140
#ifdef VSS_IRIX
154
141
__assert (test,file,line);
155
142
#endif
156
143
}
157
-
158
-
159
144
};
160
145
class cxHeapAB : public cxBaseAB , public cxHeapMB { };
161
146
class cxNewDeleteAB : public cxBaseAB , public cxNewDeleteMB { };
@@ -396,7 +381,6 @@ class cxArrayB
396
381
ostream& dumpOn (ostream& os, unsigned int printCount=10 );
397
382
};
398
383
399
-
400
384
/* ------------------------------------------------------------
401
385
This function will call the destructors for every element
402
386
of the array.
@@ -543,10 +527,6 @@ template <class T,class AB> class cxArrayIterB
543
527
}
544
528
};
545
529
546
-
547
-
548
-
549
-
550
530
// ----------------------------------------------------------------------
551
531
// class cxArray implementation
552
532
// ----------------------------------------------------------------------
@@ -589,16 +569,13 @@ template <class T,class AB> cxArrayB<T,AB>::cxArrayB(const cxArrayB<T,AB> & sour
589
569
data[i] = source.data [i];
590
570
}
591
571
592
-
593
-
594
572
template <class T ,class AB > cxArrayB<T,AB>::~cxArrayB ()
595
573
{
596
574
// free the dynamic memory buffer
597
575
CXA_delete (AB,data,T,size);
598
576
// data = 0;
599
577
}
600
578
601
-
602
579
template <class T ,class AB > cxArrayB<T,AB> & cxArrayB<T,AB>::operator =
603
580
(const cxArrayB<T,AB> & right)
604
581
{
@@ -617,8 +594,6 @@ template <class T,class AB> cxArrayB<T,AB> & cxArrayB<T,AB>::operator=
617
594
return *this ;
618
595
}
619
596
620
-
621
-
622
597
#if 1 // attempting trySetCapacity
623
598
// Set the capacity of array to exactly newSize. Create new array
624
599
// if the new size is different from the requested size, and copy
@@ -636,14 +611,12 @@ unsigned int cxArrayB<T,AB>::trySetCapacity(unsigned int newSize)
636
611
// first create the new data area
637
612
T* newData = 0 ;
638
613
if (newSize > 0 ) {
639
-
640
614
#if 1
641
615
newData = CXA_new (AB, T, newSize);
642
616
#else
643
617
cxVoidp mp = AB::alloc(sizeof(T)*newSize);
644
618
newData = new(mp) T[newSize];
645
619
#endif
646
-
647
620
if (newData==0 ) {
648
621
return size;
649
622
// !!! Change this? to some out-of-mem check or error handler?
@@ -688,7 +661,6 @@ unsigned int cxArrayB<T,AB>::setCapacity(unsigned int newSize)
688
661
return size;
689
662
}
690
663
691
-
692
664
#else
693
665
// Set the capacity of array to exactly newSize. Create new array
694
666
// if the new size is different from the requested size, and copy
@@ -738,8 +710,6 @@ unsigned int cxArrayB<T,AB>::setCapacity(unsigned int newSize)
738
710
}
739
711
#endif
740
712
741
-
742
-
743
713
// Set the count and expand the capacity of the array if needed.
744
714
template <class T ,class AB > void cxArrayB<T,AB>::count(int newCount)
745
715
{
@@ -748,7 +718,6 @@ template <class T,class AB> void cxArrayB<T,AB>::count(int newCount)
748
718
numElements = newCount;
749
719
}
750
720
751
-
752
721
// This increases the array capacity, if needed, by successively doubling
753
722
// the current size, until it meets or exceeds the minSize.
754
723
template <class T ,class AB > void cxArrayB<T,AB>::expandTo(unsigned int minSize)
@@ -814,7 +783,6 @@ template <class T,class AB> void cxArrayB<T,AB>::shift(int idx, int numToShift)
814
783
numElements += numToShift;
815
784
}
816
785
817
-
818
786
/*
819
787
Fill a range of positions with a value.
820
788
j points one PAST the last index to be filled.
@@ -844,7 +812,6 @@ void cxArrayB<T,AB>::atDeleteWith(int idx, int numToDel, const T& fillVal)
844
812
data[i] = fillVal;
845
813
}
846
814
847
-
848
815
// extern void *memmove(void *, const void *, size_t sz);
849
816
850
817
/* Copy elements from src, from indexes srcStart to srcEnd-1,
@@ -947,7 +914,6 @@ template <class T,class AB> ostream& cxArrayB<T,AB>::dumpOn(ostream& os, unsigne
947
914
return os;
948
915
}
949
916
950
-
951
917
template <class T ,class AB >
952
918
void cxArrayB<T,AB>::dumpAll()
953
919
{
@@ -965,7 +931,6 @@ void cxArrayB<T,AB>::dump()
965
931
this , size, numElements, data);
966
932
}
967
933
968
-
969
934
#if !SA_HACK
970
935
/*
971
936
Search forward from startIdx, up to and not including endIdx,
@@ -1040,8 +1005,6 @@ int cxArrayB<T,AB>::removeFirst(const T& elm)
1040
1005
}
1041
1006
#endif
1042
1007
1043
-
1044
-
1045
1008
// ----------------------------------------------------------------------
1046
1009
// class cxArrayIterB implementation
1047
1010
// ----------------------------------------------------------------------
@@ -1107,47 +1070,25 @@ template <class T,class AB> void cxArrayIterB<T,AB>::initIdx(int startIdx)
1107
1070
}
1108
1071
}
1109
1072
1110
-
1111
- // *******************************************************
1112
1073
// template functions
1113
1074
// Cfront demands these are in a different file,
1114
1075
// g++ and borland want them in this file.
1115
- // *******************************************************
1116
-
1117
- # ifdef __GNUG__
1118
-
1076
+ #ifdef __GNUG__
1119
1077
// # include <array.c>
1120
-
1121
- # endif
1122
-
1123
- # ifndef __GNUG__
1124
-
1078
+ #else
1125
1079
template <class VecType , class EleType >
1126
1080
int binarySearch (VecType data, EleType ele, unsigned int max);
1127
-
1128
1081
template <class T ,class AB > void swap ( cxArrayB<T,AB> & data, int i, int j);
1129
-
1130
1082
template <class T ,class AB > void bubbleSort (cxArrayB<T,AB> & data);
1131
-
1132
1083
template <class T ,class AB > void selectionSort (cxArrayB<T,AB> & data);
1133
-
1134
1084
template <class T ,class AB > void insertionSort (cxArrayB<T,AB> & data);
1135
-
1136
- template <class T ,class AB >
1137
- int partition (cxArrayB<T,AB> & v, int low, int high, int pivotIndex);
1138
-
1139
- template <class T ,class AB >
1140
- T findElement (cxArrayB<T,AB> & v, int N, int low, int high);
1141
-
1142
- template <class T ,class AB >
1143
- void quackSort (cxArrayB<T,AB> & v, int low, int high);
1144
-
1085
+ template <class T ,class AB > int partition (cxArrayB<T,AB> & v, int low, int high, int pivotIndex);
1086
+ template <class T ,class AB > T findElement (cxArrayB<T,AB> & v, int N, int low, int high);
1087
+ template <class T ,class AB > void quackSort (cxArrayB<T,AB> & v, int low, int high);
1145
1088
template <class T ,class AB >
1146
1089
void quackSort (cxArrayB<T,AB> & v);
1147
-
1148
1090
# endif
1149
1091
1150
-
1151
1092
/* instantiation of cxArray with allocation from the heap.
1152
1093
This will probably be most common instantiation.
1153
1094
*/
@@ -1180,5 +1121,3 @@ class cxArrayIter : public cxArrayIterB<T,cxDefaultAB>
1180
1121
cxArrayIter (cxArray<T>& anArray, int startIdx)
1181
1122
: base(anArray, startIdx) {}
1182
1123
};
1183
-
1184
- #endif /* _cxArray_h */
0 commit comments