1 /* 2 * Copyright 2006-2008 The FLWOR Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 #ifndef ZORBA_CHECKED_VECTOR_H 18 #define ZORBA_CHECKED_VECTOR_H 19 20 #include <cstddef> 21 #include <vector> 22 23 #include <zorba/config.h> 24 25 namespace zorba { 26 27 template<typename T> 28 class checked_vector : public std::vector<T> 29 { 30 public: checked_vector()31 checked_vector () {} checked_vector(size_t n)32 checked_vector (size_t n) : std::vector<T> (n) {} checked_vector(const std::vector<T> & other)33 checked_vector (const std::vector<T> &other) 34 : std::vector<T> (other) 35 {} checked_vector(const checked_vector<T> & other)36 checked_vector (const checked_vector<T> &other) 37 : std::vector<T> (other) 38 {} 39 40 checked_vector<T> &operator= (const std::vector<T> &other) { 41 std::vector<T>::operator= (other); 42 return *this; 43 } 44 45 checked_vector<T> &operator= (const checked_vector<T> &other) { 46 std::vector<T>::operator= (other); 47 return *this; 48 } 49 50 #ifndef NDEBUG 51 T &operator[] (typename std::vector<T>::size_type i) { return std::vector<T>::at (i); } 52 53 const T &operator[] (typename std::vector<T>::size_type i) const { return std::vector<T>::at (i); } 54 #endif 55 }; 56 57 58 } 59 60 #endif 61 62 /* 63 * Local variables: 64 * mode: c++ 65 * End: 66 */ 67 /* vim:set et sw=2 ts=2: */ 68