00001
00063 #ifndef SLOTS_HPP
00064 #define SLOTS_HPP
00065
00066
00067
00068
00069
00070
00071
00072 class NullT { };
00073
00074
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
00086 template<typename PolicyT, typename ArgT>
00087 inline void run(const ArgT& args)
00088 {
00089 PolicyT::runPlugin(plugin,args);
00090 Base::template run<PolicyT,ArgT>(args);
00091 }
00092
00093
00094 template<typename PolicyT, typename ArgT>
00095 inline void run(const PolicyT& policy, const ArgT& args)
00096 {
00097 policy(plugin,args);
00098 Base::template run<PolicyT,ArgT>(policy, args);
00099 }
00100 };
00101
00102
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
00114 template<typename PolicyT, typename ArgT>
00115 inline void run(const ArgT& args) { PolicyT::runPlugin(plugin,args); }
00116
00117
00118 template<typename PolicyT, typename ArgT>
00119 inline void run(const PolicyT& policy, const ArgT& args) { policy(plugin,args); }
00120 };
00121
00122
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
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
00159 template<typename PolicyT, typename ArgT>
00160 inline void run(const ArgT& args)
00161 {
00162 BaseT::template run<PolicyT,ArgT>(args);
00163 }
00164
00165
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
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
00201
00202
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
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