vec.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2000-2001  The Exult Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef VEC_H
00020 #define VEC_H
00021 
00022 #include  <vector>
00023 
00024 template <class T>
00025 class Exult_vector : public std::vector<T>
00026 {
00027 private:
00028   typedef std::vector<T>  baseClass;
00029 public:
00030   typedef typename    baseClass::size_type       size_type;
00031   typedef typename    baseClass::iterator      iterator;
00032 
00033   Exult_vector<T>() : baseClass()
00034     {}
00035   Exult_vector<T>(size_type n) : baseClass()
00036     { reserve(n); }
00037 
00038 #ifndef MACOS /* should be something like PROPER_STD_CPP_LIB or so */
00039   T& at(int i) { return (*this)[i]; }
00040 #endif
00041   void put(int i, T& v)   // Set i'th entry.
00042     {
00043       if (i >= (int)this->size())
00044         {
00045         insert(this->begin() + this->size(), i - this->size(), 0);
00046         push_back(v);
00047         }
00048       else
00049         (*this)[i] = v;
00050     }
00051   int put(T& v)     // Put in a free spot & return it.
00052     {
00053       int i = find(0);
00054       if (i < 0)
00055         i = this->size();
00056       put(i, v);
00057       return (i);
00058     }
00059   size_type find( const T& obj ) const
00060     {
00061       size_type pos = 0;
00062       for (const T *X = &*this->begin(); X != &*this->end(); ++X, ++pos)
00063         {
00064         if( *X == obj )
00065           return pos;
00066         }
00067       return -1;
00068     }
00069 
00070   size_type append( const T& obj )
00071     {
00072       push_back( obj );
00073       return this->size() - 1;
00074     }
00075 
00076   void    remove( const T& obj )
00077     {
00078       // Correct way. An iterator isn't a pointer, necessarily
00079       for(iterator X = this->begin(); X != this->end(); ++X)
00080       {
00081         if( *X == obj )
00082         {
00083           erase(X);
00084           return;
00085         }
00086       }
00087     }
00088 };
00089 
00090 
00091 class Game_object;
00092 class Egg_object;
00093 class Actor;
00094 
00095 typedef Exult_vector<Game_object*>  Game_object_vector;
00096 typedef Exult_vector<Egg_object*> Egg_vector;
00097 typedef Exult_vector<Actor*>    Actor_vector;
00098 
00099 
00100 #endif

Generated on Mon Jul 9 14:42:52 2007 for ExultEngine by  doxygen 1.5.1