poly_controller.hppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ADOBE_POLY_CONTROLLER_HPP
00010 #define ADOBE_POLY_CONTROLLER_HPP
00011
00012
00013
00014 #include <adobe/config.hpp>
00015
00016 #include <adobe/functional.hpp>
00017 #include <adobe/poly.hpp>
00018 #include <adobe/any_regular.hpp>
00019 #include <adobe/controller_concept.hpp>
00020
00021
00022
00023 namespace adobe {
00024
00025
00026
00027 namespace implementation {
00028
00029
00030
00031 template <class T>
00032 inline boost::function<void (const T&)>
00033 make_setter(const boost::function<void (const any_regular_t&)>& f) {
00034 return boost::bind(f, boost::bind(constructor<any_regular_t>(), _1));
00035 }
00036
00037
00038
00039 }
00040
00041
00042
00043 struct poly_controller_interface : public poly_copyable_interface
00044 {
00045 virtual void monitor(boost::function<void (const any_regular_t&)> setter) = 0;
00046 virtual void enable(bool enable_state) = 0;
00047 };
00048
00049
00050
00051 template <typename T>
00052 struct poly_controller_instance : optimized_storage_type<T, poly_controller_interface>::type
00053 {
00054 typedef typename optimized_storage_type<T, poly_controller_interface>::type base_t;
00055
00056 BOOST_CLASS_REQUIRE(T, adobe, ControllerConcept);
00057
00058 poly_controller_instance(const T& x) : base_t(x) {}
00059 poly_controller_instance(move_from<poly_controller_instance> x)
00060 : base_t(move_from<base_t>(x.source)) {}
00061
00062 void monitor(boost::function<void (const any_regular_t&)> f)
00063 {
00064 ControllerConcept<T>::monitor(this->get(),
00065 implementation::make_setter<typename ControllerConcept<T>::model_type>(f));
00066 }
00067
00068 void enable(bool enable_state)
00069 {
00070 ControllerConcept<T>::enable(this->get(), enable_state);
00071 }
00072 };
00073
00074
00075
00076
00077
00078 struct controller : poly_base<poly_controller_interface, poly_controller_instance>
00079 {
00080 typedef poly_base<poly_controller_interface, poly_controller_instance> base_t;
00081
00082 template <typename T>
00083 explicit controller(const T& s) : base_t(s) { }
00084
00085 controller(move_from<controller> x) : base_t(move_from<base_t>(x.source)) {}
00086
00087 void monitor(const boost::function<void (const any_regular_t&)>& f)
00088 { interface_ref().monitor(f); }
00089
00090 void enable(bool enable_state)
00091 { interface_ref().enable(enable_state); }
00092
00093 };
00094
00095
00096
00097 typedef poly<controller> poly_controller_t;
00098
00099
00100
00101 template <>
00102 struct controller_model_type<poly_controller_t>
00103 {
00104 typedef any_regular_t type;
00105 };
00106
00107
00108 }
00109
00110
00111
00112 #endif
|