1 /////////////////////////////////////////////////////////////////
4 // STL vector with array bounds checking. To enable bounds
5 // checking, #define ENABLE_CHECKS.
6 /////////////////////////////////////////////////////////////////
15 /////////////////////////////////////////////////////////////////
18 // Class derived from the STL std::vector for bounds checking.
19 /////////////////////////////////////////////////////////////////
22 class SafeVector: public std::vector<TYPE> {
25 // miscellaneous constructors
29 SafeVector(size_t size) :
30 std::vector<TYPE>(size) {
32 SafeVector(size_t size, const TYPE &value) :
33 std::vector<TYPE>(size, value) {
35 SafeVector(const SafeVector &source) :
36 std::vector<TYPE>(source) {
41 // [] array bounds checking
42 TYPE &operator[](int index) {
43 assert (index >= 0 && index < (int) size());
44 return std::vector<TYPE>::operator[] ((size_t) index);
47 // [] const array bounds checking
48 const TYPE &operator[] (int index) const {
49 assert (index >= 0 && index < (int) size());
50 return std::vector<TYPE>::operator[] ((size_t) index);
57 // some commonly used vector types
58 typedef SafeVector<int> VI;
59 typedef SafeVector<VI> VVI;
60 typedef SafeVector<VVI> VVVI;
61 typedef SafeVector<float> VF;
62 typedef SafeVector<VF> VVF;
63 typedef SafeVector<VVF> VVVF;