Gnash  0.8.11dev
utility.h
Go to the documentation of this file.
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
19 
20 #ifndef GNASH_UTILITY_H
21 #define GNASH_UTILITY_H
22 
23 // HAVE_FINITE, HAVE_PTHREADS, WIN32, NDEBUG etc.
24 #ifdef HAVE_CONFIG_H
25 #include "gnashconfig.h"
26 #endif
27 
28 #include <cstdlib>
29 #include <cassert>
30 #include <cstring>
31 #include <string>
32 #include <typeinfo>
33 
34 #if defined(__GNUC__) && __GNUC__ > 2
35 # include <cxxabi.h>
36 #endif
37 
38 #if defined(_WIN32) || defined(WIN32)
39 #ifndef NDEBUG
40 
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
49 
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
57 
58 namespace std
59 {
60  typedef std::basic_string<wchar_t> wstring;
61 };
62 #endif
63 
64 #if defined(__HAIKU__)
65 namespace std {
66  class wstring : public std::basic_string<char>
67  {
68  public:
69  wstring(const char *t)
70  : std::basic_string<char>(t)
71  {
72  }
73  wstring()
74  {
75  }
76  wstring(const wstring &that)
77  : std::basic_string<char>(that.c_str())
78  {
79  }
80  wstring(const std::basic_string<char> &that)
81  : std::basic_string<char>(that)
82  {
83  }
84  };
85 };
86 #endif
87 
88 namespace gnash {
89 
92 template <class T>
93 std::string typeName(const T& inst)
94 {
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)
102  {
103  typeName = typeNameUnmangled;
104  std::free(typeNameUnmangled);
105  }
106 #endif // __GNUC__ > 2
107  return typeName;
108 }
109 
110 } // namespace gnash
111 
112 // Handy macro to quiet compiler warnings about unused parameters/variables.
113 #define UNUSED(x) static_cast<void>((x))
114 
115 #endif
116 
117 
118 // Local Variables:
119 // mode: C++
120 // c-basic-offset: 8
121 // tab-width: 8
122 // indent-tabs-mode: t
123 // End:
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
Definition: GnashKey.h:166
Definition: GnashKey.h:132
std::string name
Definition: LocalConnection_as.cpp:149
std::string typeName(const T &inst)
Definition: utility.h:93