]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/SVector.h
49fc376ddacbe0ddc8b8bed3e6c6c6276a35985d
1 // Scintilla source code edit control
2 // SVector.h - a simple expandable vector
3 // Copyright 1998-1999 by Neil Hodgson <neilh@hare.net.au>
4 // The License.txt file describes the conditions under which this software may be distributed.
9 // A simple expandable vector.
10 // T must support assignment.
11 // Storage not allocated for elements until an element is used.
12 // This makes it very lightweight unless used so is a good match for optional features.
13 template<class T
, int sizeIncrement
>
16 unsigned int size
; // Number of elements allocated
17 unsigned int len
; // Number of elements in vector
18 bool allocFailure
; // A memory allocation call has failed
20 // Internally allocate more elements than the user wants to avoid
21 // thrashng the memory allocator
22 void SizeTo(int newSize
) {
23 if (newSize
< sizeIncrement
)
24 newSize
+= sizeIncrement
;
26 newSize
= (newSize
* 3) / 2;
27 T
* newv
= new T
[newSize
];
33 for (int i
=0; i
<len
; i
++) {
50 SVector(const SVector
&other
) {
55 if (other
.Length() > 0) {
56 SizeTo(other
.Length());
58 for (int i
=0;i
<other
.Length();i
++)
64 SVector
&operator=(const SVector
&other
) {
71 if (other
.Length() > 0) {
72 SizeTo(other
.Length());
74 for (int i
=0;i
<other
.Length();i
++)
82 T
&operator[](unsigned int i
) {
97 void SetLength(int newLen
) {