// Utils.H -*- C++ -*-
// Copyright (c) 1997, 1998 Etienne BERNARD
-// Copyright (c) 2002,2005 Clinton Ebadi
+// Copyright (c) 2002,2005,2008 Clinton Ebadi
// 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
// 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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+// 02110-1301, USA.
#ifndef UTILS_H
#define UTILS_H
#include "config.h"
#endif
-#include <ctime>
+#include <algorithm>
+#include <list>
#include <string>
-#include "Bot.H"
+#include <ctime>
+
+class Bot;
#ifdef USESCRIPTS
#include <libguile.h>
std::string scm2str (SCM);
SCM str2scm (std::string);
#endif
+
+ // Class to compare *i1 / *i2 in heaps etc.
+ template<typename T, typename C> class IndirectPred
+ {
+ C compare;
+ public:
+ bool operator() (const T * i1, const T * i2) const
+ { return compare (*i1, *i2); }
+
+ typedef T* first_argument_type;
+ typedef T* second_argument_type;
+ typedef bool result_type;
+ };
+
+ template<typename T, typename C>
+ void push_sorted (std::list<T> & storage, T item, C compare)
+ {
+ storage.insert (std::find_if (storage.begin (), storage.end (),
+ std::bind1st (compare, item)),
+ item);
+
+ }
}
#endif