• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

utility.h

Go to the documentation of this file.
00001 // utility.h -- Various little utility functions, macros & typedefs.
00002 // 
00003 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00004 //   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 #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 } // end namespace gnash
00115 extern "C" unsigned long int /* DWORD WINAPI */ GetCurrentThreadId(void);
00116 namespace gnash {
00117 # else
00118 /* getpid() */
00119 #include <sys/types.h>
00120 #include <unistd.h>
00121 # endif
00122 #endif
00123 
00124 inline unsigned long int /* pthread_t */ 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     // This isn't a proper style C++ cast, but FreeBSD has a problem with
00131     // static_cast for this as pthread_self() returns a pointer. We can
00132     // use that too, this ID is only used for the log file to keep output
00133     // from seperare threads clear.
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 } // namespace gnash
00150 
00151 // Handy macro to quiet compiler warnings about unused parameters/variables.
00152 #define UNUSED(x) (x) = (x)
00153 
00154 #endif // _GNASH_UTILITY_H
00155 
00156 
00157 // Local Variables:
00158 // mode: C++
00159 // c-basic-offset: 8 
00160 // tab-width: 8
00161 // indent-tabs-mode: t
00162 // End:

Generated on Fri Mar 16 2012 15:46:13 for Gnash by  doxygen 1.7.1