lean cpp library
A lean C++ library providing efficient utility classes for high-performance C++ applications.
|
00001 /*****************************************************/ 00002 /* lean (c) Tobias Zirr 2011 */ 00003 /*****************************************************/ 00004 00005 #ifndef LEAN 00006 #define LEAN 00007 00012 00013 #ifdef DOXYGEN_READ_THIS 00014 00015 #define LEAN_BUILD_LIB 00016 #undef LEAN_BUILD_LIB 00017 00019 #define LEAN_HEADER_ONLY 00020 #undef LEAN_HEADER_ONLY 00021 00023 #define LEAN_MIN_DEPENDENCY 00024 #undef LEAN_MIN_DEPENDENCY 00025 00027 #define LEAN_MAYBE_EXPORT 00028 #undef LEAN_MAYBE_EXPORT 00029 00031 #define LEAN_INTEGRATE_ONCE 00032 #undef LEAN_INTEGRATE_ONCE 00033 #endif 00034 00036 00039 00044 00045 #ifdef DOXYGEN_READ_THIS 00046 00047 #define LEAN_DEBUG_BUILD 00048 #undef LEAN_DEBUG_BUILD 00049 00050 #define LEAN_RELEASE_BUILD 00051 #undef LEAN_RELEASE_BUILD 00052 #else 00053 00054 #ifdef _DEBUG 00055 00056 #define LEAN_DEBUG_BUILD 00057 #else 00058 00059 #define LEAN_RELEASE_BUILD 00060 #endif 00061 00062 #endif 00063 00064 #ifndef LEAN_MAYBE_EXPORT 00065 00066 #define LEAN_MAYBE_EXPORT 00067 #endif 00068 00069 #ifdef _MSC_VER 00070 00071 #pragma warning(push) 00072 // Decorated name length exceeded all the time by various STL containers 00073 #pragma warning(disable : 4503) 00074 // Can't do anything about methods not being inlined 00075 #pragma warning(disable : 4714) 00076 // Formal parameters named for documentation purposes 00077 #pragma warning(disable : 4100) 00078 // Constant conditional expressions occur quite often in template code 00079 #pragma warning(disable : 4127) 00080 // Sometimes, using 'this' in initializier lists is unavoidable 00081 #pragma warning(disable : 4355) 00082 // We actually want arrays & PODs to be default-initialized 00083 #pragma warning(disable : 4351) 00084 #pragma warning(disable : 4345) 00085 // Assignment operators suppressed intentionally 00086 #pragma warning(disable : 4512) 00087 // Extern template now standard 00088 #pragma warning(disable : 4231) 00089 00090 #endif 00091 00092 #ifdef LEAN_DEBUG_BUILD 00093 #include <cassert> 00094 #ifdef _MSC_VER 00095 00096 #define LEAN_ASSERT(expr) ( assert(expr), __assume(expr) ) 00097 #else 00098 00099 #define LEAN_ASSERT(expr) assert(expr) 00100 #endif 00101 00102 #define LEAN_ASSERT_DEBUG(expr) assert(expr) 00103 #else 00104 #ifdef _MSC_VER 00105 00106 #define LEAN_ASSERT(expr) __assume(expr) 00107 #else 00108 00109 #define LEAN_ASSERT(expr) 00110 #endif 00111 00112 #define LEAN_ASSERT_DEBUG(expr) 00113 #endif 00114 00116 #define LEAN_ASSERT_NOT_NULL(expr) ( LEAN_ASSERT(expr != nullptr), expr ) 00117 00118 #define LEAN_ASSERT_NOT_NULL_DEBUG(expr) ( LEAN_ASSERT_DEBUG(expr != nullptr), expr ) 00119 00120 #ifdef _MSC_VER 00121 00122 #define LEAN_INLINE __forceinline 00123 00124 #define LEAN_NOINLINE __declspec(noinline) inline 00125 00126 #define LEAN_NOLTINLINE __declspec(noinline) 00127 00128 #ifndef LEAN_DEBUG_BUILD 00129 00130 #define LEAN_OPTIMIZE_DEFAULT_DESTRUCTOR 00131 #endif 00132 #else 00133 00134 #define LEAN_INLINE inline 00135 00136 #define LEAN_NOINLINE inline 00137 00138 #define LEAN_NOLTINLINE 00139 #endif 00140 00142 #define LEAN_NOTINLINE LEAN_NOLTINLINE 00143 00144 #ifdef _MSC_VER 00145 00146 #define LEAN_INTERFACE __declspec(novtable) 00147 #else 00148 00149 #define LEAN_INTERFACE 00150 #endif 00151 00152 #if !defined(LEAN_INTEGRATE_ONCE) && defined(LEAN_HEADER_ONLY) && !defined(LEAN_BUILD_LIB) 00153 00154 #define LEAN_LINK_SELECT(linklib, headeronly) headeronly 00155 #else 00156 00157 #define LEAN_LINK_SELECT(linklib, headeronly) linklib 00158 00159 #define LEAN_LINKING 1 00160 #endif 00161 00162 #if !defined(LEAN_LINKING) || defined(LEAN_INTEGRATE_ONCE) 00163 00164 #define LEAN_INCLUDE_LINKED 1 00165 #endif 00166 00168 #define LEAN_MAYBE_LINK LEAN_LINK_SELECT(, LEAN_NOINLINE) 00169 00170 #define LEAN_ALWAYS_LINK LEAN_LINK_SELECT(LEAN_NOLTINLINE, LEAN_NOINLINE) 00171 00172 #if !defined(LEAN_INTEGRATE_ONCE) && (defined(LEAN_HEADER_ONLY) || !defined(LEAN_MIN_DEPENDENCY)) && !defined(LEAN_BUILD_LIB) 00173 00174 #define LEAN_INLINE_SELECT(maxdep, mindep) maxdep 00175 00176 #define LEAN_INLINING 1 00177 #else 00178 00179 #define LEAN_INLINE_SELECT(maxdep, mindep) mindep 00180 #endif 00181 00182 #if defined(LEAN_INLINING) || defined(LEAN_INTEGRATE_ONCE) 00183 00184 #define LEAN_INCLUDE_INLINED 1 00185 #endif 00186 00188 #define LEAN_MAYBE_INLINE LEAN_INLINE_SELECT(inline, ) 00189 00190 #define LEAN_NEVER_INLINE LEAN_INLINE_SELECT(LEAN_NOINLINE, LEAN_NOLTINLINE) 00191 00193 00198 00200 namespace lean 00201 { 00202 00204 LEAN_INLINE void check(bool value) 00205 { 00206 LEAN_ASSERT_DEBUG(value); 00207 } 00208 00210 template <class Type> 00211 LEAN_INLINE const Type& min(const Type &a,const Type &b) 00212 { 00213 return (a < b) ? a : b; 00214 } 00215 00217 template <class Type> 00218 LEAN_INLINE const Type& max(const Type &a, const Type &b) 00219 { 00220 return (a < b) ? b : a; 00221 } 00222 00224 template <class Type> 00225 LEAN_INLINE Type* addressof(Type& value) 00226 { 00227 // Use C-style cast as const_casting would only make it worse 00228 return reinterpret_cast<Type*>( &(char&)value ); 00229 } 00230 00232 template <class Type, size_t Size> 00233 LEAN_INLINE size_t arraylen(Type (&)[Size]) 00234 { 00235 return Size; 00236 } 00237 00238 } // namespace 00239 00241 00242 #ifdef DOXYGEN_READ_THIS 00243 00244 00245 #define LEAN_NO_CHECK 00246 #undef LEAN_NO_CHECK 00247 00248 00249 #define LEAN_NO_MINMAX 00250 #undef LEAN_NO_MINMAX 00251 #endif 00252 00253 #ifndef LEAN_NO_CHECK 00254 using lean::check; 00255 #endif 00256 00257 #ifndef LEAN_NO_MINMAX 00258 using lean::min; 00259 using lean::max; 00260 #endif 00261 00262 #include "macros.h" 00263 #include "cpp0x.h" 00264 #include "types.h" 00265 00266 #endif