source: trunk/GDE/MAFFT/mafft-7.055-with-extensions/extensions/mxscarna_src/probconsRNA/SafeVector.h

Last change on this file was 10371, checked in by aboeckma, 11 years ago

updated mafft version. Added extensions (no svn ignore, yet)

File size: 1.5 KB
Line 
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
14/////////////////////////////////////////////////////////////////
15// SafeVector
16//
17// Class derived from the STL std::vector for bounds checking.
18/////////////////////////////////////////////////////////////////
19namespace MXSCARNA {
20template<class TYPE>
21class SafeVector : public std::vector<TYPE>{
22 public:
23
24  // miscellaneous constructors
25  SafeVector() : std::vector<TYPE>() {}
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) {}
29
30#ifdef ENABLE_CHECKS
31
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);
36  }
37
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) ;
42  }
43
44#endif
45
46};
47
48// some commonly used vector types
49typedef SafeVector<int> VI;
50typedef SafeVector<VI> VVI;
51typedef SafeVector<VVI> VVVI;
52typedef SafeVector<float> VF;
53typedef SafeVector<VF> VVF;
54typedef SafeVector<VVF> VVVF;
55}
56#endif
Note: See TracBrowser for help on using the repository browser.