5template <
class Elem,
int DefElmCount=16>
9 Elem StackValues[DefElmCount];
14 typedef Elem* iterator;
19 return Values + NValues;
25 Elem* operator + (
int idx);
29 int Add(
const Elem& V);
30 int Add(
const Elem& V,
int NTimes);
31 void RemoveAt(
int pos,
int N);
32 int find(
const Elem& v);
33 bool Insert(
int pos,
const Elem& V);
34 bool Move(
int from,
int to);
35 Elem& operator [](
int pos);
36 Elem operator [](
int pos)
const;
38 void operator += (Elem V);
40 void AddRange(Elem* Data,
int N);
52 void ToBS(BinStream& BS);
53 void FromBS(BinStream& BS,
int ne);
54 void reverse(
int start,
int finish);
57template <
class Elem,
int DefElmCount>
59 Values = &StackValues[0];
61 MaxValues = DefElmCount;
66template <
class Elem,
int DefElmCount>
70 for(
int i=0;i<src.Count();i++) {
75template <
class Elem,
int DefElmCount>
78 MaxValues=N+DefElmCount+MaxValues/2;
79 Elem* tmp=(Elem*)_ExMalloc(MaxValues*
sizeof(Elem));
81 memcpy(tmp,Values,NValues*
sizeof(Elem));
83 if(AllocElem)_ExFree(AllocElem);
88template <
class Elem,
int DefElmCount>
90 assert(idx>=0&&idx<NValues);
95template <
class Elem,
int DefElmCount>
97 Values=&StackValues[0];
99 MaxValues=DefElmCount;
103template <
class Elem,
int DefElmCount>
105 Values=&StackValues[0];
107 MaxValues=DefElmCount;
111template <
class Elem,
int DefElmCount>
116template <
class Elem,
int DefElmCount>
124template <
class Elem,
int DefElmCount>
126 Check(NValues+NTimes);
127 for(
int i=0;i<NTimes;i++){
128 memcpy(&Values[NValues],&V,
sizeof(Elem));
134template <
class Elem,
int DefElmCount>
140 if(N<=0||pos>=NValues)
return;
141 if(pos+N>NValues)N=NValues-pos;
142 if(pos+N<NValues)memcpy(Values+pos,Values+pos+N,(NValues-pos-N)*
sizeof(Elem));
146template <
class Elem,
int DefElmCount>
148 for(
int i=0;i<NValues;i++)
if(v==Values[i])
return i;
152template <
class Elem,
int DefElmCount>
154 if(pos<0||pos>NValues)
return false;
156 if(pos<NValues)memmove(Values+pos+1,Values+pos,(NValues-pos)*
sizeof(Elem));
162template <
class Elem,
int DefElmCount>
164 if(from>=NValues) from=NValues-1;
else if(from<0) from=0;
165 if(to>=NValues) to=NValues-1;
else if(to<0) to=0;
166 if(from==to)
return false;
169 memcpy(Values+from,Values+from+1,(to-from)*
sizeof(Elem));
171 memmove(Values+to+1,Values+to,(from-to)*
sizeof(Elem));
177template <
class Elem,
int DefElmCount>
179 assert(pos>=0&&pos<NValues);
181 if(pos<0||pos>=NValues)
return Values[0];
186template <
class Elem,
int DefElmCount>
188 assert(pos>=0&&pos<NValues);
190 if(pos<0||pos>=NValues)
return Values[pos];
195template <
class Elem,
int DefElmCount>
197 AddRange(A.Values,A.NValues);
200template <
class Elem,
int DefElmCount>
205template <
class Elem,
int DefElmCount>
210template <
class Elem,
int DefElmCount>
213 memcpy(Values+NValues,Data,N*
sizeof(Elem));
217template <
class Elem,
int DefElmCount>
222template <
class Elem,
int DefElmCount>
224 if(AllocElem)_ExFree(AllocElem);
225 Values=&StackValues[0];
227 MaxValues=DefElmCount;
231template <
class Elem,
int DefElmCount>
236template <
class Elem,
int DefElmCount>
238 memset(Values,Value,NValues*
sizeof(Elem));
241template <
class Elem,
int DefElmCount>
245 if(NValues==0)
return Values[0];
250template <
class Elem,
int DefElmCount>
258 return Values[NValues-1];
261template <
class Elem,
int DefElmCount>
264 return Values[--NValues];
265 }
else return Values[0];
268template <
class Elem,
int DefElmCount>
271 memcpy(dest.Values,Values,NValues*
sizeof(Elem));
272 dest.NValues=NValues;
275template <
class Elem,
int DefElmCount>
279 dest.NValues=NValues;
284template <
class Elem,
int DefElmCount>
289template <
class Elem,
int DefElmCount>
298template <
class Elem,
int DefElmCount>
300 if (start >= 0 && start < NValues && finish >= 0 && finish <= NValues) {
301 if (start > finish)std::swap(start, finish);
302 for (
int i = start, j = finish; i < j; i++, j--) {
303 std::swap(Values[i], Values[j]);
Definition stackarray.h:6