/************************************************************************* * * HTCd - Copyright (C) 1998-2006 Henrik Rydberg * * This program 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 2 of the License, or * (at your option) any later version. * * This program 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, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef MVECH #define MVECH #include #include #include const int mv_mincaps=16; template class mrvec { public: typedef T* iterator; typedef const T* const_iterator; mrvec(): map((T*)malloc(mv_mincaps*sizeof(T))),dim(0),caps(mv_mincaps) {} mrvec(int n): map((T*)malloc(mv_mincaps*sizeof(T))),dim(0),caps(mv_mincaps) { resize(n); } ~mrvec() { free(map); } int size() const { return dim; } int capacity() const { return caps; } bool empty() const { return dim==0; } bool nempty() const { return dim!=0; } T& at(int pos) { return map[pos]; } const T& at(int pos) const { return map[pos]; } T& operator[](int pos) { return map[pos]; } const T& operator[](int pos) const { return map[pos]; } iterator begin() { return map; } const_iterator begin() const { return map; } iterator end() { return map+dim; } const_iterator end() const { return map+dim; } T& front() { return map[0]; } const T& front() const { return map[0]; } T& back() { return map[dim?dim-1:0]; } const T& back() const { return map[dim?dim-1:0]; } //////////////////////////////////////////////////////////////// void clear() { dim=0; } iterator insert(iterator it,const T& s) { int pos=it-map; ins(pos,1); return &(map[pos]=s); } void insert(iterator it,int n,const T& s) { int pos=it-map; ins(pos,n); while(n--) map[pos++]=s; } void insert(iterator it,const_iterator p,const_iterator e) { int pos=it-map; ins(pos,e-p); while(p class msvec : public mrvec { public: using mrvec::map; using mrvec::dim; typedef typename mrvec::iterator iterator; typedef typename mrvec::const_iterator const_iterator; msvec() : mrvec() {} msvec(int n) : mrvec(n) { for(int i=0;i::ins(pos,1); return new(map+pos) T(s); } void insert(iterator it,int n,const T& s) { int pos=it-map; mrvec::ins(pos,n); while(n--) new(map+pos++) T(s); } void insert(iterator it,const_iterator p,const_iterator e) { int pos=it-map; mrvec::ins(pos,e-p); while(p~T(); int pos=it-map; mrvec::ins(pos+1,-1); return map+pos; } void push_back(const T& s) { mrvec::reserve(dim+1); new(map+dim++) T(s); } void pop_back(const T& s) { if(dim) map[--dim].~T(); } //////////////////////////////////////////////////////////////// void resize(int n) { while(dim>n) map[--dim].~T(); mrvec::reserve(n); while(dim