stlab.adobe.com Adobe Systems Incorporated

controller_concept.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /*************************************************************************************************/
00008 
00009 #ifndef ADOBE_CONTROLLER_HPP
00010 #define ADOBE_CONTROLLER_HPP
00011 
00012 /*************************************************************************************************/
00013 
00014 #include <boost/concept_check.hpp>
00015 #include <boost/function.hpp>
00016 
00017 /*************************************************************************************************/
00018 
00019 namespace adobe {
00020 
00021 /*************************************************************************************************/
00022 
00023 template <class C>
00024 struct controller_model_type 
00025 {
00026     typedef typename C::model_type type;
00027 };
00028 
00029 /*************************************************************************************************/
00030 
00031 template <class C, class F> // C Models Controller, F models UnaryFunction
00032 inline void monitor(C& c, const F& setter)
00033 { c.monitor(setter); }
00034 
00035 /*************************************************************************************************/
00036 
00037 template <class C> // C Models Controller
00038 inline void enable(C& c, bool enable_state)
00039 { c.enable(enable_state); }
00040 
00041 /*************************************************************************************************/
00042 
00043 template <class T>
00044 struct ControllerConcept
00045 {
00046     typedef typename controller_model_type<T>::type model_type; 
00047 
00048      
00049     template <class F>
00050     static void monitor(T& controller, F setter)
00051     {
00052         using adobe::monitor; // pick up default version which looks for member functions
00053         monitor(controller, setter); // unqualified to allow user versions
00054     }
00055 
00056     static void enable(T& controller, bool enable_state)
00057     {
00058         using adobe::enable; // pick up default version which looks for member functions
00059         enable(controller, enable_state); // unqualified to allow user versions
00060     }
00061 
00062 // Concept checking:
00063     //use pointers since not required to be default constructible
00064     T* t; 
00065     bool b;
00066     boost::function<void (const typename controller_model_type<T>::type&)> f;
00067 
00068     void constraints() {
00069         // refinement of:
00070         //boost::function_requires<boost::CopyConstructibleConcept<T> >();
00071           // we can enable the CopyConstructible (or Regular) requirement
00072           // once widget types model it
00073 
00074         // associated types:
00075         typedef typename controller_model_type<T>::type associated_type;
00076         
00077         // operations:
00078         using adobe::enable; // pick up default version which looks for member functions
00079         enable(*t, b);
00080 
00081         using adobe::monitor; // pick up default version which looks for member functions
00082         monitor(*t, f);
00083     }
00084 };
00085 
00086 template <class T>
00087 struct ControllerConcept<T*> : ControllerConcept<T> 
00088 {
00089     static void enable(T* c, bool enable_state)
00090     { ControllerConcept<T>::enable(*c, enable_state); }
00091 
00092     static void monitor(T* c,  boost::function<void (const typename ControllerConcept<T>::model_type&)> setter)
00093     { ControllerConcept<T>::monitor(*c, setter); }
00094 
00095     void constraints() {
00096         //boost concept check lib gets confused on VC8 without this
00097         ControllerConcept<T>::constraints();
00098     }
00099 };
00100 
00101 /*************************************************************************************************/
00102 
00103 } //namespace adobe
00104 
00105 /*************************************************************************************************/
00106 
00107 #endif

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google