Open Lighting Architecture  0.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
24 #ifndef INCLUDE_OLA_BASE_MACRO_H_
25 #define INCLUDE_OLA_BASE_MACRO_H_
26 
44 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
45  TypeName(const TypeName&); \
46  void operator=(const TypeName&)
47 
59 #ifdef __GNUC__
60 #define OLA_UNUSED __attribute__ ((unused))
61 #else
62 #define OLA_UNUSED
63 #endif // __GNUC__
64 
81 #ifdef __GNUC__
82 #if __GNUC__ >= 7
83 #define OLA_FALLTHROUGH __attribute__ ((fallthrough));
84 #else
85 #define OLA_FALLTHROUGH
86 #endif // __GNUC__ >= 7
87 #else
88 #define OLA_FALLTHROUGH
89 #endif // __GNUC__
90 
105 /*
106  * This code was adapted from:
107  * http://blogs.msdn.com/b/abhinaba/archive/
108  * 2008/10/27/c-c-compile-time-asserts.aspx
109  */
110 
111 #ifdef __cplusplus
112 
113 #define JOIN(X, Y) JOIN2(X, Y)
114 #define JOIN2(X, Y) X##Y
115 
116 namespace internal {
117  template <bool> struct STATIC_ASSERT_FAILURE;
118  template <> struct STATIC_ASSERT_FAILURE<true> { enum { value = 1 }; };
119 
120  template<int x> struct static_assert_test{};
121 }
122 
123 #define STATIC_ASSERT(x) \
124  OLA_UNUSED typedef ::internal::static_assert_test<\
125  sizeof(::internal::STATIC_ASSERT_FAILURE< static_cast<bool>( x ) >)>\
126  JOIN(_static_assert_typedef, __LINE__)
127 
128 #else // __cplusplus
129 
130 #define STATIC_ASSERT(x) extern int __dummy[static_cast<int>x]
131 
132 #endif // __cplusplus
133 
134 /*
135  * End of adapted code.
136  */
137 
157 #ifdef _WIN32
158 #ifdef _MSC_VER
159 #define PACK(__Declaration__) \
160  __pragma(pack(push, 1)) \
161  __Declaration__; \
162  __pragma(pack(pop))
163 #else
164 #define PACK(__Declaration__) \
165  _Pragma("pack(push, 1)") \
166  __Declaration__; \
167  _Pragma("pack(pop)")
168 #endif // _MSC_VER
169 #else
170 #define PACK(__Declaration__) __Declaration__ __attribute__((__packed__))
171 #endif // _WIN32
172 
173 #endif // INCLUDE_OLA_BASE_MACRO_H_