src/tron/gVectorExtra.h

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023   
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #ifndef ARMAGETRONAD_VECTOREXTRA_H
00029 #define ARMAGETRONAD_VECTOREXTRA_H
00030 
00031 #include <vector>
00032 
00033 template <typename T>
00034 class gVectorExtra: public std::vector<T>
00035 {
00036 public:
00037     gVectorExtra();
00038     gVectorExtra(std::vector<T> const oldOne);
00039     virtual ~gVectorExtra() {};
00040     void remove(T el);
00041     void removeAll(std::vector<T> els);
00042     void insertAll(std::vector<T> els);
00043 };
00044 
00045 template <typename T>
00046 void
00047 gVectorExtra<T>::remove(T singleElement) {
00048     typename gVectorExtra<T>::iterator it;
00049     for(it = this->begin();
00050             it != this->end();
00051             it++) {
00052         if ( *it == singleElement ) {
00053             this->erase(it);
00054             if (it == this->end())
00055                 break;
00056         }
00057     }
00058 }
00059 
00060 template <typename T>
00061 void
00062 gVectorExtra<T>::removeAll(std::vector<T> multipleElements) {
00063     typename gVectorExtra<T>::iterator it;
00064     typename std::vector<T>::iterator elsIt;
00065     for(elsIt = multipleElements.begin();
00066             elsIt != multipleElements.end();
00067             elsIt++) {
00068         for(it = this->begin();
00069                 it != this->end();
00070                 it++) {
00071             if (*elsIt == *it) {
00072                 this->erase(it);
00073                 if (it == this->end())
00074                     break;
00075             }
00076         }
00077     }
00078 }
00079 
00080 template <typename T>
00081 void
00082 gVectorExtra<T>::insertAll(std::vector<T> multipleElements) {
00083     this->insert(this->end(), multipleElements.begin(), multipleElements.end());
00084 }
00085 
00086 
00087 template <typename T>
00088 gVectorExtra<T>::gVectorExtra() : std::vector<T>() {}
00089 
00090 template <typename T>
00091 gVectorExtra<T>::gVectorExtra(std::vector<T> const oldOne) {
00092     typename std::vector<T>::const_iterator iter;
00093     for(iter = oldOne.begin();
00094             iter != oldOne.end();
00095             iter++) {
00096         push_back((*iter));
00097     }
00098 }
00099 
00100 
00101 
00102 #endif

Generated on Sat Mar 15 22:56:10 2008 for Armagetron Advanced by  doxygen 1.5.4