00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef TG_UTIL_H
00019 #define TG_UTIL_H
00020
00021 #include <iostream>
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
00038
00039
00040
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