]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/SVector.h
12a7d5d401fb8ef6a5c7058e5d0836102bc20c36
1 // Scintilla source code edit control
3 ** A simple expandable vector.
5 // Copyright 1998-2001 by Neil Hodgson <neilh@hare.net.au>
6 // The License.txt file describes the conditions under which this software may be distributed.
16 * A simple expandable integer vector.
17 * Storage not allocated for elements until an element is used.
18 * This makes it very lightweight unless used so is a good match for optional features.
21 enum { allocSize
= 4000 };
23 int *v
; ///< The vector
24 unsigned int size
; ///< Number of elements allocated
25 unsigned int len
; ///< Number of elements used in vector
27 /** Internally allocate more elements than the user wants
28 * to avoid thrashing the memory allocator. */
29 void SizeTo(int newSize
) {
30 if (newSize
< allocSize
)
33 newSize
= (newSize
* 3) / 2;
34 int *newv
= new int[newSize
];
56 /// Constructor from another vector.
57 SVector(const SVector
&other
) {
61 if (other
.Length() > 0) {
62 SizeTo(other
.Length());
63 for (int i
=0; i
<other
.Length(); i
++)
69 SVector
&operator=(const SVector
&other
) {
75 if (other
.Length() > 0) {
76 SizeTo(other
.Length());
77 for (int i
=0; i
<other
.Length(); i
++)
85 * Allows to access values from the list, and grows it if accessing
86 * outside the current bounds. The returned value in this case is 0. */
87 int &operator[](unsigned int i
) {
103 /** @brief Grow vector size.
104 * Doesn't allow a vector to be shrinked. */
105 void SetLength(unsigned int newLength
) {
106 if (newLength
> len
) {
107 if (newLength
>= size
) {
113 /// Get the current length (number of used elements) of the vector.