/*
* NICE-Core - efficient algebra and computer vision methods
* - libbasicvector - A simple vector library
* See file License for license information.
*/
#ifndef _CHECKEDEVECTOR_H_
#define _CHECKEDEVECTOR_H_
#include "core/vector/VectorT.h"
namespace NICE {
/**
* @brief This subclass of \c VectorT performs additional checks at runtime,
* especially range checks for element access.
*
* Theses checks are implemented via "non-virtual overriding".
* This means that checked versions of methods
* (in this class as opposed to un-checked versions in \c VectorT)
* are only called if the object is CheckedVectorT in the static
* context. Example:
* @verbatim
* CheckedVectorT v(10, 4.5);
* VectorT& w = v;
* try {
* v[10]; // will throw range_exception
* } catch (std::range_exception) {
* }
* w[10]; // will NOT throw an exception
* // and (probably) cause a segmentation fault
* @endverbatim
*
* See base class for further documentation.
*/
template
class CheckedVectorT : public VectorT {
public:
inline CheckedVectorT() : VectorT() {}
explicit CheckedVectorT(const size_t size) : VectorT(size) {}
CheckedVectorT(const size_t size, const ElementType& element)
: VectorT(size, element) {}
CheckedVectorT(const ElementType* _data, const size_t size)
: VectorT(_data, size) {}
CheckedVectorT(ElementType* _data, const size_t size,
const typename VectorT::Mode mode = VectorT::copy)
: VectorT(_data, size, mode) {}
explicit CheckedVectorT(std::istream& input)
: VectorT(input) {}
CheckedVectorT(const CheckedVectorT& v)
: VectorT(v) {}
CheckedVectorT(const VectorT& v)
: VectorT(v) {}
inline typename VectorT::reference
operator[](const ptrdiff_t i) {
if (i < 0 || static_cast(i) >= this->size()) {
throw std::out_of_range("VectorT () access out of range");
}
return this->data[i];
}
virtual ~CheckedVectorT();
};
template
CheckedVectorT::~CheckedVectorT() {
}
}
#endif //_CHECKEDEVECTOR_H_