Gnash 0.8.9
|
00001 // utility.h -- Various little utility functions, macros & typedefs. 00002 // 00003 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 00004 // 2011 Free Software Foundation, Inc 00005 // 00006 // This program is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 3 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with this program; if not, write to the Free Software 00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 00020 #ifndef GNASH_UTILITY_H 00021 #define GNASH_UTILITY_H 00022 00023 // HAVE_FINITE, HAVE_PTHREADS, WIN32, NDEBUG etc. 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 // On windows, replace ANSI assert with our own, for a less annoying 00046 // debugging experience. 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 #include <stdio.h> //for FILE * in tu_file.h 00056 #include <fcntl.h> //for fcntl in Socket.cpp 00057 #include <netdb.h> //for hostent in Socket.cpp 00058 #include <netinet/tcp.h> //for TCP_NODELAY in Socket.cpp 00059 #undef UNUSED //to avoid "already defined" messages 00060 #define SHUT_RDWR 0 00061 00062 namespace std 00063 { 00064 typedef std::basic_string<wchar_t> wstring; 00065 }; 00066 #endif 00067 00068 #if defined(__HAIKU__) 00069 namespace std { 00070 class wstring : public std::basic_string<char> 00071 { 00072 public: 00073 wstring(const char *t) 00074 : std::basic_string<char>(t) 00075 { 00076 } 00077 wstring() 00078 { 00079 } 00080 wstring(const wstring &that) 00081 : std::basic_string<char>(that.c_str()) 00082 { 00083 } 00084 wstring(const std::basic_string<char> &that) 00085 : std::basic_string<char>(that) 00086 { 00087 } 00088 }; 00089 }; 00090 #endif 00091 00092 namespace gnash { 00093 00096 template <class T> 00097 std::string typeName(const T& inst) 00098 { 00099 std::string typeName = typeid(inst).name(); 00100 #if defined(__GNUC__) && __GNUC__ > 2 00101 int status; 00102 char* typeNameUnmangled = 00103 abi::__cxa_demangle (typeName.c_str(), NULL, NULL, 00104 &status); 00105 if (status == 0) 00106 { 00107 typeName = typeNameUnmangled; 00108 std::free(typeNameUnmangled); 00109 } 00110 #endif // __GNUC__ > 2 00111 return typeName; 00112 } 00113 00115 #ifdef HAVE_PTHREADS 00116 #else 00117 # ifdef _WIN32 00118 } // end namespace gnash 00119 extern "C" unsigned long int /* DWORD WINAPI */ GetCurrentThreadId(void); 00120 namespace gnash { 00121 # else 00122 /* getpid() */ 00123 #include <sys/types.h> 00124 #include <unistd.h> 00125 # endif 00126 #endif 00127 00128 inline unsigned long int /* pthread_t */ get_thread_id(void) 00129 { 00130 #ifdef HAVE_PTHREADS 00131 # ifdef __APPLE_CC__ 00132 return reinterpret_cast<unsigned long int>(pthread_self()); 00133 # else 00134 // This isn't a proper style C++ cast, but FreeBSD has a problem with 00135 // static_cast for this as pthread_self() returns a pointer. We can 00136 // use that too, this ID is only used for the log file to keep output 00137 // from seperare threads clear. 00138 # ifdef _WIN32 00139 return GetCurrentThreadId(); 00140 #else 00141 return (unsigned long int)pthread_self(); 00142 #endif 00143 # endif 00144 #else 00145 # ifdef _WIN32 00146 return GetCurrentThreadId(); 00147 # else 00148 return static_cast<unsigned long int>(getpid()); 00149 # endif 00150 #endif 00151 } 00152 00153 } // namespace gnash 00154 00155 // Handy macro to quiet compiler warnings about unused parameters/variables. 00156 #define UNUSED(x) static_cast<void>((x)) 00157 00158 #endif 00159 00160 00161 // Local Variables: 00162 // mode: C++ 00163 // c-basic-offset: 8 00164 // tab-width: 8 00165 // indent-tabs-mode: t 00166 // End: