Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

GenProg.hh

00001 //=============================================================================
00002 //                                                                            
00003 //                               OpenMesh                                     
00004 //      Copyright (C) 2001-2005 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 Library General Public License as published  
00013 //   by the Free Software Foundation, version 2.                             
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 //   Library General Public License for more details.                          
00019 //                                                                            
00020 //   You should have received a copy of the GNU Library 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: 1.1.1.1 $
00027 //   $Date: 2004/09/06 12:35:33 $
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.hh>
00045 
00046 
00047 //== NAMESPACES ===============================================================
00048 
00049 namespace OpenMesh {
00050 namespace GenProg  {
00051 #ifndef DOXY_IGNORE_THIS
00052 
00053 //== IMPLEMENTATION ===========================================================
00054 
00055 
00057 template <bool b> class Bool2Type { enum { my_bool = b }; };
00058 
00060 template <int i>  class Int2Type  { enum { my_int = i }; };
00061 
00063 typedef Bool2Type<true> True;
00064 
00066 typedef Bool2Type<false> False;
00067 
00068 
00069 //-----------------------------------------------------------------------------
00070 
00071 
00072 
00073 //--- Template "if" w/ partial specialization ---------------------------------
00074 #if OM_PARTIAL_SPECIALIZATION
00075 
00076 
00077 template <bool condition, class Then, class Else>
00078 struct IF { typedef Then Result; };
00079 
00085 template <class Then, class Else>
00086 struct IF<false, Then, Else> { typedef Else Result; };
00087 
00088 
00089 
00090 
00091 
00092 //--- Template "if" w/o partial specialization --------------------------------
00093 #else
00094 
00095 
00096 struct SelectThen 
00097 {
00098   template <class Then, class Else> struct Select {
00099     typedef Then Result;
00100   };
00101 };
00102 
00103 struct SelectElse
00104 {
00105   template <class Then, class Else> struct Select {
00106     typedef Else Result;
00107   };
00108 };
00109 
00110 template <bool condition> struct ChooseSelector {
00111   typedef SelectThen Result;
00112 };
00113 
00114 template <> struct ChooseSelector<false> {
00115   typedef SelectElse Result;
00116 };
00117 
00118 
00125 template <bool condition, class Then, class Else>
00126 class IF 
00127 { 
00128   typedef typename ChooseSelector<condition>::Result  Selector;
00129 public:
00130   typedef typename Selector::template Select<Then, Else>::Result  Result;
00131 };
00132 
00133 #endif
00134 
00135 //=============================================================================
00136 #endif
00137 } // namespace GenProg
00138 } // namespace OpenMesh
00139 //=============================================================================
00140 #endif // OPENMESH_GENPROG_HH defined
00141 //=============================================================================

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .