Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GNASH_UTILITY_H
00021 #define GNASH_UTILITY_H
00022
00023
00024 #ifdef HAVE_CONFIG_H
00025 #include "gnashconfig.h"
00026 #endif
00027
00028 #include <cstdlib>
00029 #include <cassert>
00030 #include <cstring>
00031 #include <string>
00032 #include <typeinfo>
00033
00034 #ifdef HAVE_PTHREADS
00035 #include <pthread.h>
00036 #endif
00037
00038 #if defined(__GNUC__) && __GNUC__ > 2
00039 # include <cxxabi.h>
00040 #endif
00041
00042 #if defined(_WIN32) || defined(WIN32)
00043 #ifndef NDEBUG
00044
00045
00046
00047 #ifndef __MINGW32__
00048 #undef assert
00049 #define assert(x) if (!(x)) { __asm { int 3 } }
00050 #endif
00051 #endif // not NDEBUG
00052 #endif // _WIN32
00053
00054 #ifdef __amigaos4__
00055 #undef UNUSED //to avoid "already defined" messages
00056 #define SHUT_RDWR 0
00057
00058 namespace std
00059 {
00060 typedef std::basic_string<wchar_t> wstring;
00061 };
00062 #endif
00063
00064 #if defined(__HAIKU__)
00065 namespace std {
00066 class wstring : public std::basic_string<char>
00067 {
00068 public:
00069 wstring(const char *t)
00070 : std::basic_string<char>(t)
00071 {
00072 }
00073 wstring()
00074 {
00075 }
00076 wstring(const wstring &that)
00077 : std::basic_string<char>(that.c_str())
00078 {
00079 }
00080 wstring(const std::basic_string<char> &that)
00081 : std::basic_string<char>(that)
00082 {
00083 }
00084 };
00085 };
00086 #endif
00087
00088 namespace gnash {
00089
00092 template <class T>
00093 std::string typeName(const T& inst)
00094 {
00095 std::string typeName = typeid(inst).name();
00096 #if defined(__GNUC__) && __GNUC__ > 2
00097 int status;
00098 char* typeNameUnmangled =
00099 abi::__cxa_demangle (typeName.c_str(), NULL, NULL,
00100 &status);
00101 if (status == 0)
00102 {
00103 typeName = typeNameUnmangled;
00104 std::free(typeNameUnmangled);
00105 }
00106 #endif // __GNUC__ > 2
00107 return typeName;
00108 }
00109
00111 #ifdef HAVE_PTHREADS
00112 #else
00113 # ifdef _WIN32
00114 }
00115 extern "C" unsigned long int GetCurrentThreadId(void);
00116 namespace gnash {
00117 # else
00118
00119 #include <sys/types.h>
00120 #include <unistd.h>
00121 # endif
00122 #endif
00123
00124 inline unsigned long int get_thread_id(void)
00125 {
00126 #ifdef HAVE_PTHREADS
00127 # ifdef __APPLE_CC__
00128 return reinterpret_cast<unsigned long int>(pthread_self());
00129 # else
00130
00131
00132
00133
00134 # ifdef _WIN32
00135 return GetCurrentThreadId();
00136 #else
00137 return (unsigned long int)pthread_self();
00138 #endif
00139 # endif
00140 #else
00141 # ifdef _WIN32
00142 return GetCurrentThreadId();
00143 # else
00144 return static_cast<unsigned long int>(getpid());
00145 # endif
00146 #endif
00147 }
00148
00149 }
00150
00151
00152 #define UNUSED(x) (x) = (x)
00153
00154 #endif // _GNASH_UTILITY_H
00155
00156
00157
00158
00159
00160
00161
00162