Open Lighting Architecture  0.9.1
 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 
48 /*
49  * This code was adapted from:
50  * http://blogs.msdn.com/b/abhinaba/archive/
51  * 2008/10/27/c-c-compile-time-asserts.aspx
52  */
53 
54 #ifdef __cplusplus
55 
56 #define JOIN(X, Y) JOIN2(X, Y)
57 #define JOIN2(X, Y) X##Y
58 
59 namespace internal {
60  template <bool> struct STATIC_ASSERT_FAILURE;
61  template <> struct STATIC_ASSERT_FAILURE<true> { enum { value = 1 }; };
62 
63  template<int x> struct static_assert_test{};
64 }
65 
66 #define STATIC_ASSERT(x) \
67  typedef ::internal::static_assert_test<\
68  sizeof(::internal::STATIC_ASSERT_FAILURE< static_cast<bool>( x ) >)>\
69  JOIN(_static_assert_typedef, __LINE__)
70 
71 #else // __cplusplus
72 
73 #define STATIC_ASSERT(x) extern int __dummy[static_cast<int>x]
74 
75 #endif // __cplusplus
76 
77 /*
78  * End of adapted code.
79  */
80 
81 #endif // INCLUDE_OLA_BASE_MACRO_H_