Add GLprobs and MSAprobs to binaries
[jabaws.git] / binaries / src / MSAProbs-0.9.7 / MSAProbs / SafeVector.h
1 /////////////////////////////////////////////////////////////////
2 // SafeVector.h
3 //
4 // STL vector with array bounds checking.  To enable bounds
5 // checking, #define ENABLE_CHECKS.
6 /////////////////////////////////////////////////////////////////
7
8 #ifndef SAFEVECTOR_H
9 #define SAFEVECTOR_H
10
11 #include <cassert>
12 #include <vector>
13 using namespace std;
14
15 /////////////////////////////////////////////////////////////////
16 // SafeVector
17 //
18 // Class derived from the STL std::vector for bounds checking.
19 /////////////////////////////////////////////////////////////////
20
21 template<class TYPE>
22 class SafeVector: public std::vector<TYPE> {
23 public:
24
25         // miscellaneous constructors
26         SafeVector() :
27                         std::vector<TYPE>() {
28         }
29         SafeVector(size_t size) :
30                         std::vector<TYPE>(size) {
31         }
32         SafeVector(size_t size, const TYPE &value) :
33                         std::vector<TYPE>(size, value) {
34         }
35         SafeVector(const SafeVector &source) :
36                         std::vector<TYPE>(source) {
37         }
38
39 #ifdef ENABLE_CHECKS
40
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);
45         }
46
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);
51         }
52
53 #endif
54
55 };
56
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;
64
65 #endif