diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/SVector.h | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/SVector.h b/src/SVector.h index d061fe274..c8edb513b 100644 --- a/src/SVector.h +++ b/src/SVector.h @@ -1,26 +1,31 @@ // Scintilla source code edit control -// SVector.h - a simple expandable vector +/** @file SVector.h + ** A simple expandable vector. + **/ // Copyright 1998-2001 by Neil Hodgson <neilh@hare.net.au> // The License.txt file describes the conditions under which this software may be distributed. #ifndef SVECTOR_H #define SVECTOR_H -// A simple expandable integer vector. -// Storage not allocated for elements until an element is used. -// This makes it very lightweight unless used so is a good match for optional features. - +/** + * A simple expandable integer vector. + * Storage not allocated for elements until an element is used. + * This makes it very lightweight unless used so is a good match for optional features. + */ class SVector { - int *v; - unsigned int size; // Number of elements allocated - unsigned int len; // Number of elements in vector - bool allocFailure; // A memory allocation call has failed + enum { allocSize = 4000 }; + + int *v; ///< The vector + unsigned int size; ///< Number of elements allocated + unsigned int len; ///< Number of elements used in vector + bool allocFailure; ///< A memory allocation call has failed - // Internally allocate more elements than the user wants to avoid - // thrashng the memory allocator + /** Internally allocate more elements than the user wants + * to avoid thrashing the memory allocator. */ void SizeTo(int newSize) { - if (newSize < 4000) - newSize += 4000; + if (newSize < allocSize) + newSize += allocSize; else newSize = (newSize * 3) / 2; int* newv = new int[newSize]; @@ -50,6 +55,7 @@ public: ~SVector() { Free(); } + /// Constructor from another vector. SVector(const SVector &other) { allocFailure = false; v = 0; @@ -64,6 +70,7 @@ public: } } } + /// Copy constructor. SVector &operator=(const SVector &other) { if (this != &other) { delete []v; @@ -82,6 +89,9 @@ public: } return *this; } + /** @brief Accessor. + * Allows to access values from the list, and grows it if accessing + * outside the current bounds. The returned value in this case is 0. */ int &operator[](unsigned int i) { if (i >= len) { if (i >= size) { @@ -91,12 +101,15 @@ public: } return v[i]; } + /// Reset vector. void Free() { delete []v; v = 0; size = 0; len = 0; } + /** @brief Grow vector size. + * Doesn't allow a vector to be shrinked. */ void SetLength(unsigned int newLength) { if (newLength > len) { if (newLength >= size) { @@ -105,6 +118,7 @@ public: } len = newLength; } + /// Get the current length (number of used elements) of the vector. int Length() const { return len; } |