Update with current status
[gnash.git] / libbase / utility.h
blob10f35aaa59fe6cf86e77e35f3080b6b2dc083660
1 // utility.h -- Various little utility functions, macros & typedefs.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef GNASH_UTILITY_H
21 #define GNASH_UTILITY_H
23 // HAVE_FINITE, HAVE_PTHREADS, WIN32, NDEBUG etc.
24 #ifdef HAVE_CONFIG_H
25 #include "gnashconfig.h"
26 #endif
28 #include <cstdlib>
29 #include <cassert>
30 #include <cstring>
31 #include <string>
32 #include <typeinfo>
34 #if defined(__GNUC__) && __GNUC__ > 2
35 # include <cxxabi.h>
36 #endif
38 #if defined(_WIN32) || defined(WIN32)
39 #ifndef NDEBUG
41 // On windows, replace ANSI assert with our own, for a less annoying
42 // debugging experience.
43 #ifndef __MINGW32__
44 #undef assert
45 #define assert(x) if (!(x)) { __asm { int 3 } }
46 #endif
47 #endif // not NDEBUG
48 #endif // _WIN32
50 #ifdef __amigaos4__
51 #include <stdio.h> //for FILE * in tu_file.h
52 #include <fcntl.h> //for fcntl in Socket.cpp
53 #include <netdb.h> //for hostent in Socket.cpp
54 #include <netinet/tcp.h> //for TCP_NODELAY in Socket.cpp
55 #undef UNUSED //to avoid "already defined" messages
56 #define SHUT_RDWR 0
58 namespace std
60 typedef std::basic_string<wchar_t> wstring;
62 #endif
64 #if defined(__HAIKU__)
65 namespace std {
66 class wstring : public std::basic_string<char>
68 public:
69 wstring(const char *t)
70 : std::basic_string<char>(t)
73 wstring()
76 wstring(const wstring &that)
77 : std::basic_string<char>(that.c_str())
80 wstring(const std::basic_string<char> &that)
81 : std::basic_string<char>(that)
86 #endif
88 namespace gnash {
90 /// Return (unmangled) name of this instance type. Used for
91 /// logging in various places.
92 template <class T>
93 std::string typeName(const T& inst)
95 std::string typeName = typeid(inst).name();
96 #if defined(__GNUC__) && __GNUC__ > 2
97 int status;
98 char* typeNameUnmangled =
99 abi::__cxa_demangle (typeName.c_str(), nullptr, nullptr,
100 &status);
101 if (status == 0)
103 typeName = typeNameUnmangled;
104 std::free(typeNameUnmangled);
106 #endif // __GNUC__ > 2
107 return typeName;
110 } // namespace gnash
112 // Handy macro to quiet compiler warnings about unused parameters/variables.
113 #define UNUSED(x) static_cast<void>((x))
115 #endif
118 // Local Variables:
119 // mode: C++
120 // c-basic-offset: 8
121 // tab-width: 8
122 // indent-tabs-mode: t
123 // End: