3
* Copyright 2004 Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
13
* 3. The name of the author may not be used to endorse or promote products
14
* derived from this software without specific prior written permission.
16
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
#ifndef TALK_BASE_COMMON_H_
29
#define TALK_BASE_COMMON_H_
31
#include "talk/base/basictypes.h"
32
#include "talk/base/constructormagic.h"
35
// warning C4355: 'this' : used in base member initializer list
36
#pragma warning(disable:4355)
39
//////////////////////////////////////////////////////////////////////
41
//////////////////////////////////////////////////////////////////////
44
#define UNUSED(x) Unused(static_cast<const void *>(&x))
45
#define UNUSED2(x,y) Unused(static_cast<const void *>(&x)); Unused(static_cast<const void *>(&y))
46
#define UNUSED3(x,y,z) Unused(static_cast<const void *>(&x)); Unused(static_cast<const void *>(&y)); Unused(static_cast<const void *>(&z))
47
#define UNUSED4(x,y,z,a) Unused(static_cast<const void *>(&x)); Unused(static_cast<const void *>(&y)); Unused(static_cast<const void *>(&z)); Unused(static_cast<const void *>(&a))
48
#define UNUSED5(x,y,z,a,b) Unused(static_cast<const void *>(&x)); Unused(static_cast<const void *>(&y)); Unused(static_cast<const void *>(&z)); Unused(static_cast<const void *>(&a)); Unused(static_cast<const void *>(&b))
49
inline void Unused(const void *) { }
53
#define strnicmp(x,y,n) strncasecmp(x,y,n)
54
#define stricmp(x,y) strcasecmp(x,y)
56
// TODO: Remove this. std::max should be used everywhere in the code.
57
// NOMINMAX must be defined where we include <windows.h>.
58
#define stdmax(x,y) std::max(x,y)
60
#define stdmax(x,y) talk_base::_max(x,y)
64
#define ARRAY_SIZE(x) (static_cast<int>((sizeof(x)/sizeof(x[0]))))
66
/////////////////////////////////////////////////////////////////////////////
68
/////////////////////////////////////////////////////////////////////////////
71
#define ENABLE_DEBUG _DEBUG
72
#endif // !defined(ENABLE_DEBUG)
78
// Break causes the debugger to stop executing, or the program to abort
81
// LogAssert writes information about an assertion to the log
82
void LogAssert(const char * function, const char * file, int line,
83
const char * expression);
85
inline bool Assert(bool result, const char * function, const char * file,
86
int line, const char * expression) {
88
LogAssert(function, file, line, expression);
95
} // namespace talk_base
97
#if defined(_MSC_VER) && _MSC_VER < 1300
98
#define __FUNCTION__ ""
102
#define ASSERT(x) (void)talk_base::Assert((x),__FUNCTION__,__FILE__,__LINE__,#x)
106
#define VERIFY(x) talk_base::Assert((x),__FUNCTION__,__FILE__,__LINE__,#x)
109
#else // !ENABLE_DEBUG
111
namespace talk_base {
113
inline bool ImplicitCastToBool(bool result) { return result; }
115
} // namespace talk_base
118
#define ASSERT(x) (void)0
122
#define VERIFY(x) talk_base::ImplicitCastToBool(x)
125
#endif // !ENABLE_DEBUG
127
#define COMPILE_TIME_ASSERT(expr) char CTA_UNIQUE_NAME[expr]
128
#define CTA_UNIQUE_NAME CTA_MAKE_NAME(__LINE__)
129
#define CTA_MAKE_NAME(line) CTA_MAKE_NAME2(line)
130
#define CTA_MAKE_NAME2(line) constraint_ ## line
132
// Forces compiler to inline, even against its better judgement. Use wisely.
133
#if defined(__GNUC__)
134
#define FORCE_INLINE __attribute__((always_inline))
136
#define FORCE_INLINE __forceinline
141
#endif // TALK_BASE_COMMON_H_