]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/SVector.h
c8edb513bc3fdca89e6ef43f7341ee4a73f5ed13
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.
12 * A simple expandable integer vector.
13 * Storage not allocated for elements until an element is used.
14 * This makes it very lightweight unless used so is a good match for optional features.
17 enum { allocSize
= 4000 };
19 int *v
; ///< The vector
20 unsigned int size
; ///< Number of elements allocated
21 unsigned int len
; ///< Number of elements used in vector
22 bool allocFailure
; ///< A memory allocation call has failed
24 /** Internally allocate more elements than the user wants
25 * to avoid thrashing the memory allocator. */
26 void SizeTo(int newSize
) {
27 if (newSize
< allocSize
)
30 newSize
= (newSize
* 3) / 2;
31 int* newv
= new int[newSize
];
58 /// Constructor from another vector.
59 SVector(const SVector
&other
) {
64 if (other
.Length() > 0) {
65 SizeTo(other
.Length());
67 for (int i
=0;i
<other
.Length();i
++)
74 SVector
&operator=(const SVector
&other
) {
81 if (other
.Length() > 0) {
82 SizeTo(other
.Length());
84 for (int i
=0;i
<other
.Length();i
++)
93 * Allows to access values from the list, and grows it if accessing
94 * outside the current bounds. The returned value in this case is 0. */
95 int &operator[](unsigned int i
) {
111 /** @brief Grow vector size.
112 * Doesn't allow a vector to be shrinked. */
113 void SetLength(unsigned int newLength
) {
114 if (newLength
> len
) {
115 if (newLength
>= size
) {
121 /// Get the current length (number of used elements) of the vector.