stlab.adobe.com Adobe Systems Incorporated

poly_key_handler.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2006-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_POLY_KEY_HANDLER_HPP
00010 #define ADOBE_POLY_KEY_HANDLER_HPP
00011 
00012 /*************************************************************************************************/
00013 
00014 #include <adobe/config.hpp>
00015 
00016 #include <adobe/poly.hpp>
00017 #include <adobe/key_handler_concept.hpp>
00018 #include <adobe/future/platform_primitives.hpp>
00019 #include <adobe/widget_attributes.hpp>
00020 
00021 #include <boost/ref.hpp>
00022 #include <boost/operators.hpp>
00023 
00024 /*************************************************************************************************/
00025 
00026 namespace adobe {
00027 
00028 /*************************************************************************************************/
00029 
00030 namespace implementation {
00031 
00032 /*************************************************************************************************/
00038 template <class T>
00039 inline
00040 typename boost::disable_if<boost::is_reference_wrapper<T>, T& >::type
00041 deref(T& t) 
00042 {
00043     return t;
00044 }
00045 
00046 /*************************************************************************************************/
00051 template <class T>
00052 inline
00053 typename boost::enable_if<boost::is_reference_wrapper<T>, 
00054                           typename boost::unwrap_reference<T>::type& >::type
00055 deref(T& t) 
00056 {
00057     return t.get();
00058 }
00059 /*************************************************************************************************/
00060 
00061 } //namespace implementation
00062 
00063 /*************************************************************************************************/
00064 
00065 struct poly_key_handler_interface : poly_copyable_interface
00066 {
00067     virtual bool handle_key(key_type key, bool pressed, modifiers_t modifiers) = 0;
00068     virtual any_regular_t underlying_handler() = 0;
00069 };
00070 
00071 
00072 template <typename T>
00073 struct poly_key_handler_instance : optimized_storage_type<T, poly_key_handler_interface>::type
00074 {
00075     typedef typename optimized_storage_type<T, poly_key_handler_interface>::type base_t;
00076 
00077     typedef typename boost::unwrap_reference<T>::type deref_type;
00078     
00079     BOOST_CLASS_REQUIRE(deref_type, adobe, KeyHandlerConcept);
00080 
00081     poly_key_handler_instance(const T& x) 
00082         : base_t(x) {}
00083 
00084     poly_key_handler_instance(move_from<poly_key_handler_instance> x) 
00085         : base_t(move_from<base_t>(x.source)) {}
00086 
00087     bool handle_key(key_type key, bool pressed, modifiers_t modifiers)
00088     { 
00089         using adobe::handle_key;
00090         return handle_key(implementation::deref(this->get()), key, pressed, modifiers); 
00091     }
00092 
00093     any_regular_t underlying_handler()
00094     { 
00095         using adobe::underlying_handler;
00096         return underlying_handler(implementation::deref(this->get())); 
00097     }
00098 };
00099 
00100 /*************************************************************************************************/
00101 
00102 struct key_handler : public poly_base<poly_key_handler_interface, poly_key_handler_instance>
00103 {
00104     typedef poly_base<poly_key_handler_interface, poly_key_handler_instance> base_t;
00105 
00106     template <typename T>
00107     explicit key_handler(const T& s) : base_t(s) { }
00108 
00109     key_handler(move_from<key_handler> x) : base_t(move_from<base_t>(x.source)) {}
00110 
00111     bool handle_key(key_type key, bool pressed, modifiers_t modifiers)
00112     { return interface_ref().handle_key(key, pressed, modifiers); }
00113 
00114     any_regular_t underlying_handler()
00115     { return interface_ref().underlying_handler(); }
00116 };
00117 
00118 /*************************************************************************************************/
00119 
00120 typedef poly<key_handler> poly_key_handler_t;
00121 
00122 /*************************************************************************************************/
00123 
00124 } // namespace adobe
00125 
00126 /*************************************************************************************************/
00127 
00128 #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