Add GLprobs and MSAprobs to binaries
[jabaws.git] / binaries / src / GLProbs-1.0 / SafeVector.h
diff --git a/binaries/src/GLProbs-1.0/SafeVector.h b/binaries/src/GLProbs-1.0/SafeVector.h
new file mode 100644 (file)
index 0000000..f42c2da
--- /dev/null
@@ -0,0 +1,65 @@
+/////////////////////////////////////////////////////////////////
+// SafeVector.h
+//
+// STL vector with array bounds checking.  To enable bounds
+// checking, #define ENABLE_CHECKS.
+/////////////////////////////////////////////////////////////////
+
+#ifndef SAFEVECTOR_H
+#define SAFEVECTOR_H
+
+#include <cassert>
+#include <vector>
+using namespace std;
+
+/////////////////////////////////////////////////////////////////
+// SafeVector
+//
+// Class derived from the STL std::vector for bounds checking.
+/////////////////////////////////////////////////////////////////
+
+template<class TYPE>
+class SafeVector: public std::vector<TYPE> {
+public:
+
+       // miscellaneous constructors
+       SafeVector() :
+                       std::vector<TYPE>() {
+       }
+       SafeVector(size_t size) :
+                       std::vector<TYPE>(size) {
+       }
+       SafeVector(size_t size, const TYPE &value) :
+                       std::vector<TYPE>(size, value) {
+       }
+       SafeVector(const SafeVector &source) :
+                       std::vector<TYPE>(source) {
+       }
+
+#ifdef ENABLE_CHECKS
+
+       // [] array bounds checking
+       TYPE &operator[](int index) {
+               assert (index >= 0 && index < (int) size());
+               return std::vector<TYPE>::operator[] ((size_t) index);
+       }
+
+       // [] const array bounds checking
+       const TYPE &operator[] (int index) const {
+               assert (index >= 0 && index < (int) size());
+               return std::vector<TYPE>::operator[] ((size_t) index);
+       }
+
+#endif
+
+};
+
+// some commonly used vector types
+typedef SafeVector<int> VI;
+typedef SafeVector<VI> VVI;
+typedef SafeVector<VVI> VVVI;
+typedef SafeVector<float> VF;
+typedef SafeVector<VF> VVF;
+typedef SafeVector<VVF> VVVF;
+
+#endif