Util.h

00001 // ----------------------------------------------------------------------------
00002 //
00003 // tagGame - Example code from the book:
00004 //
00005 //           Artficial Intelligence for Computer Games: An Introduction
00006 //           by John David Funge
00007 //
00008 //           www.ai4games.org
00009 //
00010 // Source code distributed under the Copyright (c) 2003-2007, John David Funge
00011 // Original author: John David Funge (www.jfunge.com)
00012 //
00013 // Licensed under the Academic Free License version 3.0 
00014 // (for details see LICENSE.txt in this directory).
00015 //
00016 // ----------------------------------------------------------------------------
00017 
00018 #ifndef TG_UTIL_H
00019 #define TG_UTIL_H
00020 
00021 #include <iostream> // TODO: replace with iosfwd
00022 #include <cstdlib>
00023 #include <cassert>
00024 #include <string>
00025 
00026 #undef TG_USE_TR1
00027 #if defined(__GNUC__) && (__GNUC__ >= 4)
00028 #define TG_USE_TR1 1
00029 #endif
00030 
00031 #if defined(TG_USE_TR1)
00032 #include <tr1/memory>
00033 #endif
00034 
00035 namespace tagGame
00036 {
00037    // The purpose of these typedefs is to reduce the number of code changes
00038    // involved in replacing these boost data structures with equivalent ones
00039    // (the additional struct syntax is needed because C++ doesn't allow us to
00040    // directly define typedef templates).
00041 
00042    template<class T>
00043    struct SharedPtr
00044    {
00045 #ifdef TG_USE_TR1
00046       typedef std::tr1::shared_ptr<T> type;
00047 #else
00048       typedef T* type;
00049 #endif
00050    };
00051 
00052    struct DeleteObject
00053    {
00054       template <typename T>
00055       void operator()(T* p) { delete p;}
00056    };
00057 
00059    class Util
00060    {
00061    public:
00062 
00064       static void warn(std::string const& message);
00065 
00067       static void error(std::string const& message);
00068 
00070       static void error(std::string const& errorStr, int const line, std::string const& filename, std::string const& message = "");
00071 
00073       static void warn(bool const condition, std::string const& message);
00074 
00076       static std::string itos(int n);
00077 
00078    protected:
00079    private:
00080    };
00081 }
00082 
00083 #if defined(DEBUG)
00084    #define TG_ASSERT(c) ((c) ? (void)0 : tagGame::Util::error(#c, __LINE__, __FILE__))
00085    #define TG_ASSERT_MSG(c, s) ((c) ? (void)0 : tagGame::Util::error(#c, __LINE__, __FILE__, s))
00086 #else
00087    #define TG_ASSERT(c)
00088    #define TG_ASSERT_MSG(c, s)
00089 #endif
00090 
00091 #define TG_ARRAY_COUNT(x) (sizeof(x)/sizeof((x)[0]))
00092 
00093 #endif

Generated on Sat Mar 31 22:30:54 2007 for tagGame by  doxygen 1.5.1