00001 //============================================================================= 00002 // 00003 // OpenMesh 00004 // Copyright (C) 2003 by Computer Graphics Group, RWTH Aachen 00005 // www.openmesh.org 00006 // 00007 //----------------------------------------------------------------------------- 00008 // 00009 // License 00010 // 00011 // This library is free software; you can redistribute it and/or modify it 00012 // under the terms of the GNU Lesser General Public License as published 00013 // by the Free Software Foundation, version 2.1. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00023 // 00024 //----------------------------------------------------------------------------- 00025 // 00026 // $Revision: 1801 $ 00027 // $Date: 2008-05-19 11:53:56 +0200 (Mon, 19 May 2008) $ 00028 // 00029 //============================================================================= 00030 00031 00032 //============================================================================= 00033 // 00034 // Utils for generic/generative programming 00035 // 00036 //============================================================================= 00037 00038 #ifndef OPENMESH_GENPROG_HH 00039 #define OPENMESH_GENPROG_HH 00040 00041 00042 //== INCLUDES ================================================================= 00043 00044 #include <OpenMesh/Core/System/config.h> 00045 00046 00047 //== NAMESPACES =============================================================== 00048 00049 namespace OpenMesh { 00050 00051 namespace GenProg { 00052 #ifndef DOXY_IGNORE_THIS 00053 00054 //== IMPLEMENTATION =========================================================== 00055 00056 00058 template <bool b> struct Bool2Type { enum { my_bool = b }; }; 00059 00061 template <int i> struct Int2Type { enum { my_int = i }; }; 00062 00064 typedef Bool2Type<true> True; 00065 00067 typedef Bool2Type<false> False; 00068 00069 //----------------------------------------------------------------------------- 00071 template <bool Expr> struct AssertCompile; 00072 template <> struct AssertCompile<true> {}; 00073 00074 00075 00076 //--- Template "if" w/ partial specialization --------------------------------- 00077 #if OM_PARTIAL_SPECIALIZATION 00078 00079 00080 template <bool condition, class Then, class Else> 00081 struct IF { typedef Then Result; }; 00082 00088 template <class Then, class Else> 00089 struct IF<false, Then, Else> { typedef Else Result; }; 00090 00091 00092 00093 00094 00095 //--- Template "if" w/o partial specialization -------------------------------- 00096 #else 00097 00098 00099 struct SelectThen 00100 { 00101 template <class Then, class Else> struct Select { 00102 typedef Then Result; 00103 }; 00104 }; 00105 00106 struct SelectElse 00107 { 00108 template <class Then, class Else> struct Select { 00109 typedef Else Result; 00110 }; 00111 }; 00112 00113 template <bool condition> struct ChooseSelector { 00114 typedef SelectThen Result; 00115 }; 00116 00117 template <> struct ChooseSelector<false> { 00118 typedef SelectElse Result; 00119 }; 00120 00121 00128 template <bool condition, class Then, class Else> 00129 class IF 00130 { 00131 typedef typename ChooseSelector<condition>::Result Selector; 00132 public: 00133 typedef typename Selector::template Select<Then, Else>::Result Result; 00134 }; 00135 00136 #endif 00137 00138 //============================================================================= 00139 #endif 00140 } // namespace GenProg 00141 } // namespace OpenMesh 00142 00143 #define assert_compile(EXPR) GenProg::AssertCompile<(EXPR)>(); 00144 00145 //============================================================================= 00146 #endif // OPENMESH_GENPROG_HH defined 00147 //=============================================================================