Open Lighting Architecture  0.9.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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
64 
79 /*
80  * This code was adapted from:
81  * http://blogs.msdn.com/b/abhinaba/archive/
82  * 2008/10/27/c-c-compile-time-asserts.aspx
83  */
84 
85 #ifdef __cplusplus
86 
87 #define JOIN(X, Y) JOIN2(X, Y)
88 #define JOIN2(X, Y) X##Y
89 
90 namespace internal {
91  template <bool> struct STATIC_ASSERT_FAILURE;
92  template <> struct STATIC_ASSERT_FAILURE<true> { enum { value = 1 }; };
93 
94  template<int x> struct static_assert_test{};
95 }
96 
97 #define STATIC_ASSERT(x) \
98  OLA_UNUSED typedef ::internal::static_assert_test<\
99  sizeof(::internal::STATIC_ASSERT_FAILURE< static_cast<bool>( x ) >)>\
100  JOIN(_static_assert_typedef, __LINE__)
101 
102 #else // __cplusplus
103 
104 #define STATIC_ASSERT(x) extern int __dummy[static_cast<int>x]
105 
106 #endif // __cplusplus
107 
108 /*
109  * End of adapted code.
110  */
111 
131 #ifdef _WIN32
132 #ifdef _MSC_VER
133 #define PACK(__Declaration__) \
134  __pragma(pack(push, 1)) \
135  __Declaration__; \
136  __pragma(pack(pop))
137 #else
138 #define PACK(__Declaration__) \
139  _Pragma("pack(push, 1)") \
140  __Declaration__; \
141  _Pragma("pack(pop)")
142 #endif
143 #else
144 #define PACK(__Declaration__) __Declaration__ __attribute__((__packed__))
145 #endif
146 
147 #endif // INCLUDE_OLA_BASE_MACRO_H_