1
/////////////////////////////////////////////////////////////////
4
// STL vector with array bounds checking. To enable bounds
5
// checking, #define ENABLE_CHECKS.
6
/////////////////////////////////////////////////////////////////
14
/////////////////////////////////////////////////////////////////
17
// Class derived from the STL std::vector for bounds checking.
18
/////////////////////////////////////////////////////////////////
21
class SafeVector : public std::vector<TYPE>{
24
// miscellaneous constructors
26
SafeVector (size_t size) : std::vector<TYPE>(size) {}
27
SafeVector (size_t size, const TYPE &value) : std::vector<TYPE>(size, value) {}
28
SafeVector (const SafeVector &source) : std::vector<TYPE>(source) {}
32
// [] array bounds checking
33
TYPE &operator[](int index){
34
assert (index >= 0 && index < (int) size());
35
return std::vector<TYPE>::operator[] ((size_t) index);
38
// [] const array bounds checking
39
const TYPE &operator[] (int index) const {
40
assert (index >= 0 && index < (int) size());
41
return std::vector<TYPE>::operator[] ((size_t) index) ;
48
// some commonly used vector types
49
typedef SafeVector<int> VI;
50
typedef SafeVector<VI> VVI;
51
typedef SafeVector<VVI> VVVI;
52
typedef SafeVector<float> VF;
53
typedef SafeVector<VF> VVF;
54
typedef SafeVector<VVF> VVVF;