Gnash  0.8.10
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, 2011, 2012
00004 //   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 #if defined(__GNUC__) && __GNUC__ > 2
00035 #  include <cxxabi.h>
00036 #endif
00037 
00038 #if defined(_WIN32) || defined(WIN32)
00039 #ifndef NDEBUG
00040 
00041 // On windows, replace ANSI assert with our own, for a less annoying
00042 // debugging experience.
00043 #ifndef __MINGW32__
00044 #undef assert
00045 #define assert(x)       if (!(x)) { __asm { int 3 } }
00046 #endif
00047 #endif // not NDEBUG
00048 #endif // _WIN32
00049 
00050 #ifdef __amigaos4__
00051 #include <stdio.h> //for FILE * in tu_file.h
00052 #include <fcntl.h> //for fcntl in Socket.cpp
00053 #include <netdb.h> //for hostent in Socket.cpp
00054 #include <netinet/tcp.h> //for TCP_NODELAY in Socket.cpp
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 
00110 } // namespace gnash
00111 
00112 // Handy macro to quiet compiler warnings about unused parameters/variables.
00113 #define UNUSED(x) static_cast<void>((x))
00114 
00115 #endif 
00116 
00117 
00118 // Local Variables:
00119 // mode: C++
00120 // c-basic-offset: 8 
00121 // tab-width: 8
00122 // indent-tabs-mode: t
00123 // End: