1 // utility.h -- Various little utility functions, macros & typedefs.
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
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.
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.
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.
25 #include "gnashconfig.h"
38 #if defined(__GNUC__) && __GNUC__ > 2
42 #if defined(_WIN32) || defined(WIN32)
45 // On windows, replace ANSI assert with our own, for a less annoying
46 // debugging experience.
49 #define assert(x) if (!(x)) { __asm { int 3 } }
55 #include <stdio.h> //for FILE * in tu_file.h
56 #include <fcntl.h> //for fcntl in Socket.cpp
57 #include <netdb.h> //for hostent in Socket.cpp
58 #include <netinet/tcp.h> //for TCP_NODELAY in Socket.cpp
59 #undef UNUSED //to avoid "already defined" messages
64 typedef std::basic_string
<wchar_t> wstring
;
68 #if defined(__HAIKU__)
70 class wstring
: public std::basic_string
<char>
73 wstring(const char *t
)
74 : std::basic_string
<char>(t
)
80 wstring(const wstring
&that
)
81 : std::basic_string
<char>(that
.c_str())
84 wstring(const std::basic_string
<char> &that
)
85 : std::basic_string
<char>(that
)
94 /// Return (unmangled) name of this instance type. Used for
95 /// logging in various places.
97 std::string
typeName(const T
& inst
)
99 std::string typeName
= typeid(inst
).name();
100 #if defined(__GNUC__) && __GNUC__ > 2
102 char* typeNameUnmangled
=
103 abi::__cxa_demangle (typeName
.c_str(), NULL
, NULL
,
107 typeName
= typeNameUnmangled
;
108 std::free(typeNameUnmangled
);
110 #endif // __GNUC__ > 2
118 } // end namespace gnash
119 extern "C" unsigned long int /* DWORD WINAPI */ GetCurrentThreadId(void);
123 #include <sys/types.h>
128 inline unsigned long int /* pthread_t */ get_thread_id(void)
132 return reinterpret_cast<unsigned long int>(pthread_self());
134 // This isn't a proper style C++ cast, but FreeBSD has a problem with
135 // static_cast for this as pthread_self() returns a pointer. We can
136 // use that too, this ID is only used for the log file to keep output
137 // from seperare threads clear.
139 return GetCurrentThreadId();
141 return (unsigned long int)pthread_self();
146 return GetCurrentThreadId();
148 return static_cast<unsigned long int>(getpid());
155 // Handy macro to quiet compiler warnings about unused parameters/variables.
156 #define UNUSED(x) static_cast<void>((x))
165 // indent-tabs-mode: t