TemplateMeta.h

Go to the documentation of this file.
00001 #ifndef __LDK_TEMPLATEMETA_H__
00002 #define __LDK_TEMPLATEMETA_H__
00003 
00005 //   Copyright (C) 2003-2006 Lorien Dunn.
00006 //
00007 //   Contact: loriendunn AT users DOT sourceforge DOT net
00008 //
00009 //   This software is provided 'as-is', without any express or implied warranty.
00010 //   In no event will the authors be held liable for any damages arising from
00011 //   the use of this software.
00012 //
00013 //   Permission is granted to anyone to use this software for any purpose,
00014 //   including commercial applications, and to alter it and redistribute it
00015 //   freely, subject to the following restrictions:
00016 //
00017 //   1. The origin of this software must not be misrepresented; you must not
00018 //   claim that you wrote the original software. If you use this software in a
00019 //   product, an acknowledgment in the product documentation would be
00020 //   appreciated but is not required.
00021 //
00022 //   2. Altered source versions must be plainly marked as such, and must not be
00023 //   misrepresented as being the original software.
00024 //
00025 //   3. This notice may not be removed or altered from any source distribution.
00026 //
00028 
00033 
00034 namespace LDK
00035 {
00038 namespace Meta
00039 {
00040 
00045 
00053 template<bool test, class TCase, class FCase> struct If;
00054 
00057 template<class TCase, class FCase>
00058 struct If<true, TCase, FCase>
00059 {
00061     typedef TCase result;
00062 };
00063 
00066 template<class TCase, class FCase>
00067 struct If<false, TCase, FCase>
00068 {
00070     typedef FCase result;
00071 };
00072 
00077 struct LDK_API True
00078 {
00079     enum { value = 1 };
00080 };
00081 
00086 struct LDK_API False
00087 {
00088     enum { value = 0 };
00089 };
00090 
00091 
00092 template <bool x> struct CTAssert;
00093 template <> struct LDK_API CTAssert<true> {};
00099 #define CTASSERT(expr,msg)  LDK::Meta::CTAssert<((expr) != false)> ERROR_##msg;
00100 
00109 template <int N>
00110 struct PowerOf2
00111 {
00112     enum
00113     {
00114         value = !(N%2) ? PowerOf2<(int)((N/2.0)+0.5)>::value : false
00115     };
00116 };
00117 //it is a power of two
00118 template <>
00119 struct LDK_API PowerOf2<2>
00120 {
00121     enum { value = true };
00122 };
00123 //it is not a power of two
00124 template <>
00125 struct LDK_API PowerOf2<0>
00126 {
00127     enum { value = false };
00128 };
00129 
00139 template <int Size>
00140 struct HalfwayPowerOf2
00141 {
00142     enum
00143     {
00144         value = PowerOf2<Size>::value ? false :\
00145             PowerOf2<(int)(Size+((Size/3.0)+0.5))>::value
00146     };
00147 };
00149 }//namespace Meta
00150 
00151 }//namespace LDK
00152 
00153 #endif //__LDK_TEMPLATEMETA_H__

Generated on Fri Aug 17 18:32:26 2007 for LDK by  doxygen 1.5.1