Open Lighting Architecture: include/ola/base/Macro.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
Macro.h
Go to the documentation of this file.
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * Macro.h
17 */
18
23
24#ifndef INCLUDE_OLA_BASE_MACRO_H_
25#define INCLUDE_OLA_BASE_MACRO_H_
26
45#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
46 TypeName(const TypeName&); \
47 void operator=(const TypeName&)
48
60#ifdef __GNUC__
61#define OLA_UNUSED __attribute__ ((unused))
62#else
63#define OLA_UNUSED
64#endif // __GNUC__
65
82#ifdef __GNUC__
83#if __GNUC__ >= 7
84#define OLA_FALLTHROUGH __attribute__ ((fallthrough));
85#else
86#define OLA_FALLTHROUGH
87#endif // __GNUC__ >= 7
88#else
89#define OLA_FALLTHROUGH
90#endif // __GNUC__
91
105
106/*
107 * This code was adapted from:
108 * http://blogs.msdn.com/b/abhinaba/archive/
109 * 2008/10/27/c-c-compile-time-asserts.aspx
110 */
111
112#ifdef __cplusplus
113
114#define JOIN(X, Y) JOIN2(X, Y)
115#define JOIN2(X, Y) X##Y
116
117namespace internal {
118 template <bool> struct STATIC_ASSERT_FAILURE;
119 template <> struct STATIC_ASSERT_FAILURE<true> { enum { value = 1 }; };
120
121 template<int x> struct static_assert_test{};
122}
123
124#define STATIC_ASSERT(x) \
125 OLA_UNUSED typedef ::internal::static_assert_test<\
126 sizeof(::internal::STATIC_ASSERT_FAILURE< static_cast<bool>( x ) >)>\
127 JOIN(_static_assert_typedef, __LINE__)
128
129#else // __cplusplus
130
131#define STATIC_ASSERT(x) extern int __dummy[static_cast<int>x]
132
133#endif // __cplusplus
134
135/*
136 * End of adapted code.
137 */
138
158#ifdef _WIN32
159#ifdef _MSC_VER
160#define PACK(__Declaration__) \
161 __pragma(pack(push, 1)) \
162 __Declaration__; \
163 __pragma(pack(pop))
164#else
165#define PACK(__Declaration__) \
166 _Pragma("pack(push, 1)") \
167 __Declaration__; \
168 _Pragma("pack(pop)")
169#endif // _MSC_VER
170#else
171#define PACK(__Declaration__) __Declaration__ __attribute__((__packed__))
172#endif // _WIN32
173
174#endif // INCLUDE_OLA_BASE_MACRO_H_