slots.hpp
Go to the documentation of this file.
00001 
00063 #ifndef SLOTS_HPP
00064 #define SLOTS_HPP
00065 
00066 /*
00067  * some design classes and functions for templated property handling
00068  * "Slots" is a wrapper class tieing together a variable list of properties
00069  * advantage: no v-table lookups for base-function calls
00070  */
00071 
00072 class NullT { };
00073 
00074 //_________________________________ Extensions ________________________________
00075 template<typename PluginT, typename Base>
00076 class Extension : public Base
00077 {
00078 private:
00079   PluginT plugin;
00080 
00081 public:
00082   Extension(const PluginT& p, const Base& b)
00083     : Base(b), plugin(p) { }
00084 
00085   // for static policy
00086   template<typename PolicyT, typename ArgT>
00087   inline void run(const ArgT& args)
00088   {
00089     PolicyT::runPlugin(plugin,args); // call static function
00090     Base::template run<PolicyT,ArgT>(args); // recursive
00091   }
00092 
00093   // for non-static policy
00094   template<typename PolicyT, typename ArgT>
00095   inline void run(const PolicyT& policy, const ArgT& args)
00096   {
00097     policy(plugin,args); // call operator()
00098     Base::template run<PolicyT,ArgT>(policy, args);  // recursive
00099   }
00100 };
00101 
00102 //_____ specialization (end of recursive inheritance) _____
00103 template<typename PluginT>
00104 class Extension<PluginT, NullT>
00105 {
00106 private:
00107   PluginT plugin;
00108 
00109 public:
00110   Extension(const PluginT& p, const NullT& b = NullT())
00111     : plugin(p) { }
00112 
00113   // for static policy
00114   template<typename PolicyT, typename ArgT>
00115   inline void run(const ArgT& args) { PolicyT::runPlugin(plugin,args); }
00116 
00117   // for non-static policy
00118   template<typename PolicyT, typename ArgT>
00119   inline void run(const PolicyT& policy, const ArgT& args) { policy(plugin,args); }
00120 };
00121 
00122 //_____ specialization (null type) _____
00123 template<>
00124 class Extension<NullT, NullT>
00125 {
00126 public:
00127   Extension(const NullT& p = NullT(), const NullT& b = NullT())
00128   { }
00129 
00130   template<typename PolicyT, typename ArgT>
00131   inline void run(const ArgT& args) { return; }
00132 
00133   template<typename PolicyT, typename ArgT>
00134   inline void run(const PolicyT& obj, const ArgT& args) { return; }
00135 };
00136 
00137 
00138 //_________________________________ Slots _____________________________________
00139 template<typename P1 = NullT,
00140          typename P2 = NullT,
00141          typename P3 = NullT,
00142          typename P4 = NullT,
00143          typename P5 = NullT>
00144 class Slots : public Extension<P1, typename Slots<P2,P3,P4,P5,NullT>::BaseT>
00145 {
00146 public:
00147   typedef Slots<P2,P3,P4,P5,NullT> BaseSlots;
00148   typedef Extension<P1, typename BaseSlots::BaseT> BaseT;
00149 
00150   Slots(const P1& plugin1 = P1(),
00151         const P2& plugin2 = P2(),
00152         const P3& plugin3 = P3(),
00153         const P4& plugin4 = P4(),
00154         const P5& plugin5 = P5())
00155     : BaseT( plugin1, BaseSlots(plugin2, plugin3, plugin4, plugin5, NullT()) )
00156   { }
00157 
00158   // for static policy
00159   template<typename PolicyT, typename ArgT>
00160   inline void run(const ArgT& args)
00161   {
00162     BaseT::template run<PolicyT,ArgT>(args);
00163   }
00164 
00165   // for non-static policy
00166   template<typename PolicyT, typename ArgT>
00167   inline void run(const PolicyT& policy, const ArgT& args)
00168   {
00169     BaseT::template run<PolicyT,ArgT>(policy, args);
00170   }
00171 };
00172 
00173 //_____ specialization _____
00174 template<typename P1>
00175 class Slots<P1, NullT, NullT, NullT, NullT> : public Extension<P1, NullT>
00176 {
00177 public:
00178   typedef Extension<P1, NullT> BaseT;
00179 
00180   Slots(const P1&    plugin1 = P1(),
00181         const NullT& plugin2 = NullT(),
00182         const NullT& plugin3 = NullT(),
00183         const NullT& plugin4 = NullT(),
00184         const NullT& plugin5 = NullT())
00185     : BaseT(plugin1) { }
00186 
00187   template<typename PolicyT, typename ArgT>
00188   inline void run(const ArgT& args)
00189   {
00190     BaseT::template run<PolicyT,ArgT>(args);
00191   }
00192 
00193   template<typename PolicyT, typename ArgT>
00194   inline void run(const PolicyT& policy, const ArgT& args)
00195   {
00196     BaseT::template run<PolicyT,ArgT>(policy, args);
00197   }
00198 };
00199 
00200 //_________________ convenience functions _____________________________________
00201 
00202 // run specific policy on slots with arguemnts for static policy class
00203 template<typename Policy, typename Args, typename Slots>
00204 inline void runPolicy(Slots& slots, const Args& args)
00205 {
00206   slots.template run<Policy>(args);
00207 }
00208 
00209 // run specific policy on slots with arguemnts for non-static policy class
00210 template<typename Policy, typename Args, typename Slots>
00211 inline void runSlots(Slots& slots, const Policy& policy, const Args& args)
00212 {
00213   slots.template run(policy, args);
00214 }
00215 
00216 
00217 template<typename T1>
00218 inline Slots<T1> tiePlugins(const T1& a1)
00219 {
00220   return Slots<T1>(a1);
00221 }
00222 
00223 template<typename T1, typename T2>
00224 inline Slots<T1,T2> tiePlugins(const T1& a1, const T2& a2)
00225 {
00226   return Slots<T1,T2>(a1,a2);
00227 }
00228 
00229 template<typename T1, typename T2, typename T3>
00230 inline Slots<T1,T2,T3> tiePlugins(const T1& a1, const T2& a2, const T3& a3)
00231 {
00232   return Slots<T1,T2,T3>(a1,a2,a3);
00233 }
00234 
00235 template<typename T1, typename T2, typename T3, typename T4>
00236 inline Slots<T1,T2,T3,T4> tiePlugins(const T1& a1, const T2& a2,
00237                                      const T3& a3, const T4& a4)
00238 {
00239   return Slots<T1,T2,T3,T4>(a1,a2,a3,a4);
00240 }
00241 
00242 template<typename T1, typename T2, typename T3, typename T4, typename T5>
00243 inline Slots<T1,T2,T3,T4,T5> tiePlugins(const T1& a1, const T2& a2, const T3& a3,
00244                                      const T4& a4, const T5& a5)
00245 {
00246   return Slots<T1,T2,T3,T4,T5>(a1,a2,a3,a4,a5);
00247 }
00248 
00249 #endif


cob_3d_meshing
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:04:03