~ubuntu-branches/debian/experimental/kopete/experimental

« back to all changes in this revision

Viewing changes to protocols/jabber/googletalk/libjingle/talk/base/common.h

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2015-02-24 11:32:57 UTC
  • mfrom: (1.1.41 vivid)
  • Revision ID: package-import@ubuntu.com-20150224113257-gnupg4v7lzz18ij0
Tags: 4:14.12.2-1
* New upstream release (14.12.2).
* Bump Standards-Version to 3.9.6, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * libjingle
3
 
 * Copyright 2004 Google Inc.
4
 
 *
5
 
 * Redistribution and use in source and binary forms, with or without
6
 
 * modification, are permitted provided that the following conditions are met:
7
 
 *
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.
15
 
 *
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.
26
 
 */
27
 
 
28
 
#ifndef TALK_BASE_COMMON_H_
29
 
#define TALK_BASE_COMMON_H_
30
 
 
31
 
#include "talk/base/basictypes.h"
32
 
#include "talk/base/constructormagic.h"
33
 
 
34
 
#if defined(_MSC_VER)
35
 
// warning C4355: 'this' : used in base member initializer list
36
 
#pragma warning(disable:4355)
37
 
#endif
38
 
 
39
 
//////////////////////////////////////////////////////////////////////
40
 
// General Utilities
41
 
//////////////////////////////////////////////////////////////////////
42
 
 
43
 
#ifndef UNUSED
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 *) { }
50
 
#endif // UNUSED
51
 
 
52
 
#ifndef WIN32
53
 
#define strnicmp(x,y,n) strncasecmp(x,y,n)
54
 
#define stricmp(x,y) strcasecmp(x,y)
55
 
 
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)
59
 
#else
60
 
#define stdmax(x,y) talk_base::_max(x,y)
61
 
#endif
62
 
 
63
 
 
64
 
#define ARRAY_SIZE(x) (static_cast<int>((sizeof(x)/sizeof(x[0]))))
65
 
 
66
 
/////////////////////////////////////////////////////////////////////////////
67
 
// Assertions
68
 
/////////////////////////////////////////////////////////////////////////////
69
 
 
70
 
#ifndef ENABLE_DEBUG
71
 
#define ENABLE_DEBUG _DEBUG
72
 
#endif  // !defined(ENABLE_DEBUG)
73
 
 
74
 
#if ENABLE_DEBUG
75
 
 
76
 
namespace talk_base {
77
 
 
78
 
// Break causes the debugger to stop executing, or the program to abort
79
 
void Break();
80
 
 
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);
84
 
 
85
 
inline bool Assert(bool result, const char * function, const char * file,
86
 
                   int line, const char * expression) {
87
 
  if (!result) {
88
 
    LogAssert(function, file, line, expression);
89
 
    Break();
90
 
    return false;
91
 
  }
92
 
  return true;
93
 
}
94
 
 
95
 
}  // namespace talk_base
96
 
 
97
 
#if defined(_MSC_VER) && _MSC_VER < 1300
98
 
#define __FUNCTION__ ""
99
 
#endif
100
 
 
101
 
#ifndef ASSERT
102
 
#define ASSERT(x) (void)talk_base::Assert((x),__FUNCTION__,__FILE__,__LINE__,#x)
103
 
#endif
104
 
 
105
 
#ifndef VERIFY
106
 
#define VERIFY(x) talk_base::Assert((x),__FUNCTION__,__FILE__,__LINE__,#x)
107
 
#endif
108
 
 
109
 
#else // !ENABLE_DEBUG
110
 
 
111
 
namespace talk_base {
112
 
 
113
 
inline bool ImplicitCastToBool(bool result) { return result; }
114
 
 
115
 
}  // namespace talk_base
116
 
 
117
 
#ifndef ASSERT
118
 
#define ASSERT(x) (void)0
119
 
#endif
120
 
 
121
 
#ifndef VERIFY
122
 
#define VERIFY(x) talk_base::ImplicitCastToBool(x)
123
 
#endif
124
 
 
125
 
#endif // !ENABLE_DEBUG
126
 
 
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
131
 
 
132
 
// Forces compiler to inline, even against its better judgement. Use wisely.
133
 
#if defined(__GNUC__)
134
 
#define FORCE_INLINE __attribute__((always_inline))
135
 
#elif defined(WIN32)
136
 
#define FORCE_INLINE __forceinline
137
 
#else
138
 
#define FORCE_INLINE
139
 
#endif
140
 
 
141
 
#endif // TALK_BASE_COMMON_H_