--- deliantra/server/include/util.h 2007/06/04 13:04:00 1.49
+++ deliantra/server/include/util.h 2007/07/13 15:54:40 1.53
@@ -1,21 +1,20 @@
/*
- * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game.
+ * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
*
* Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
*
- * Crossfire TRT 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.
+ * Crossfire TRT 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 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.
+ * 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 Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
*
* The authors can be reached via e-mail to
*/
@@ -408,9 +407,9 @@
};
// Mostly the same as std::vector, but insert/erase can reorder
-// the elements, making insret/remove O(1) instead of O(n).
+// the elements, making append(=insert)/remove O(1) instead of O(n).
//
-// NOTE: only some forms of erase/insert are available
+// NOTE: only some forms of erase are available
template
struct unordered_vector : std::vector >
{
@@ -442,27 +441,34 @@
// - only works for pointers to structs
//
// NOTE: only some forms of erase/insert are available
-template
+typedef int object_vector_index;
+
+template
struct object_vector : std::vector >
{
typedef typename object_vector::iterator iterator;
bool contains (const T *obj) const
{
- return obj->*index;
+ return obj->*indexmember;
}
iterator find (const T *obj)
{
- return obj->*index
- ? this->begin () + obj->*index - 1
+ return obj->*indexmember
+ ? this->begin () + obj->*indexmember - 1
: this->end ();
}
+ void push_back (T *obj)
+ {
+ std::vector >::push_back (obj);
+ obj->*indexmember = this->size ();
+ }
+
void insert (T *obj)
{
push_back (obj);
- obj->*index = this->size ();
}
void insert (T &obj)
@@ -472,13 +478,13 @@
void erase (T *obj)
{
- unsigned int pos = obj->*index;
- obj->*index = 0;
+ unsigned int pos = obj->*indexmember;
+ obj->*indexmember = 0;
if (pos < this->size ())
{
(*this)[pos - 1] = (*this)[this->size () - 1];
- (*this)[pos - 1]->*index = pos;
+ (*this)[pos - 1]->*indexmember = pos;
}
this->pop_back ();
@@ -486,7 +492,7 @@
void erase (T &obj)
{
- errase (&obj);
+ erase (&obj);
}
};