/* * AP_Vector.h * Copyright (C) James Goppert 2010 * * This file is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #ifndef AP_Vector_H #define AP_Vector_H #include #include #include #ifdef ASSERT const static char vectorSource[] ="AP_Vector.hpp"; #endif // vector template class AP_Vector { private: size_t size; size_t extraAllocationSize; // extra space to add after each allocation size_t sizeAllocated; // total allocated size dataType* data; public: // default constructor AP_Vector(const size_t & size=0, const size_t & extraAllocationSize=0) : size(0), extraAllocationSize(extraAllocationSize), sizeAllocated(0), data(NULL) { setSize(size); } // 3 vector constructor AP_Vector(const dataType & a, const dataType & b, const dataType & c) : size(3), extraAllocationSize(extraAllocationSize), sizeAllocated(0), data(NULL) { setSize(size); (*this)(0)=a; (*this)(1)=b; (*this)(2)=c; } // construct from array AP_Vector(const dataType* array, const size_t & size, const size_t & extraAllocationSize=0) : size(0), extraAllocationSize(extraAllocationSize), sizeAllocated(0), data(NULL) { setSize(size); for (size_t i=0; i toFloat() const { AP_Vector v(getSize()); for (size_t i=0; isizeAllocated) { dataType * newData = new dataType[n+extraAllocationSize]; memcpy(newData,data,sizeof(dataType)/sizeof(char)*getSize()); memset(newData+size,0,sizeof(dataType)/sizeof(char)*(n-getSize())); delete[] data; data = newData; sizeAllocated=n+extraAllocationSize; } size=n; } // return size const size_t & getSize() const { return size; } // insert void insert(const size_t index, const dataType value) { //Serial.println("insert called"); #ifdef ASSERT assert(index