/** * \file container_tpl.h * * \brief ein Template das als Behälter für alles mögliche dient. * * \author Georg Steffers [gs] * * \date 16.12.2003 * * \version ..2002 [gs]: erste Implementation * \version 16.12.2003 [gs]: */ /* * Copyright (C)2003 Georg Steffers * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using namespace std; #include #include "container.h" template container::container() : content(NULL), count(0) { //content=new C[1]; } template container::container(const C& c) : count(1) { content=new C[1]; content[0]=c; } template container::container(const C* c, unsigned co) : count(co) { if(count > 0) content=new C[count]; else content=NULL; for(unsigned i=0; i container::container(const container& c) : count(c.count) { if(count > 0) content=new C[count]; else content=NULL; for(unsigned i=0; i container::~container() { if(content) { delete [] content; content=NULL; } count=0; } template const container& container::operator=(const container& c) { if(this==&c) return *this; if(count != c.count) { delete [] content; if(c.count > 0) content=new C[c.count]; else content=NULL; } count=c.count; for(unsigned i=0; i const C& container::operator[](unsigned index) const { if(index+1 > count) return content[0]; return content[index]; } template C& container::operator[](unsigned index) { if(index+1 > count) { C* content_tmp=new C[index+1]; for(unsigned i=0; isize. template void container::resize(unsigned size) { C* content_tmp; if(size>0) { content_tmp=new C[size]; for(unsigned i=0; i void container::insert(unsigned idx, const C& value) { C* content_tmp=new C[count+1]; memcpy(content_tmp, content, idx*sizeof(C)); content_tmp[idx]=value; for(unsigned i=0; i