stlab.adobe.com Adobe Systems Incorporated

poly_view.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_VIEW_HPP
00010 #define ADOBE_POLY_VIEW_HPP
00011 
00012 #include <adobe/config.hpp>
00013 #include <adobe/view_concept.hpp>
00014 #include <adobe/poly.hpp>
00015 
00016 /*************************************************************************************************/
00017 
00018 namespace adobe {
00019 
00020 
00021 /*************************************************************************************************/
00022 
00028 struct poly_view_interface : poly_copyable_interface
00029 {
00030     virtual void display(const any_regular_t& new_value) = 0;
00031 };
00032 
00033 /*************************************************************************************************/
00034 
00041 template <typename T>
00042 struct poly_view_instance : optimized_storage_type<T, poly_view_interface>::type
00043 {
00044     typedef typename optimized_storage_type<T, poly_view_interface>::type base_t;
00045 
00049     BOOST_CLASS_REQUIRE(T, adobe, ViewConcept);
00050 
00054     poly_view_instance(const T& x) : base_t(x) {}
00055 
00059     poly_view_instance(move_from<poly_view_instance> x) : base_t(move_from<base_t>(x.source)) {}
00060 
00061     void display(const any_regular_t& new_value)
00062     { 
00063         ViewConcept<T>::display(this->get(), new_value.cast<typename ViewConcept<T>::model_type>());
00064     }
00065 
00066 }; 
00067 
00068 /*************************************************************************************************/
00069 
00075 struct view : poly_base<poly_view_interface, poly_view_instance>
00076 {
00077     typedef poly_base<poly_view_interface, poly_view_instance> base_t;
00078 
00082     template <typename T>
00083     explicit view(const T& s) : base_t(s)  { }
00084 
00088     view(move_from<view> x) : base_t(move_from<base_t>(x.source)) {}
00089 
00090     template <typename V>
00091     void display(const V& new_value)
00092     { interface_ref().display(any_regular_t(new_value)); }
00093 };
00094 
00095 
00096 /*************************************************************************************************/
00097 
00098 #if !defined(ADOBE_NO_DOCUMENTATION)
00099 
00100 /*************************************************************************************************/
00101 
00102 typedef poly<view> poly_view_t;
00103 
00104 /*************************************************************************************************/
00105 
00106 template <>
00107 struct view_model_type<poly_view_t> 
00108 {
00109     typedef any_regular_t type;
00110 };
00111 
00112 
00113 /*************************************************************************************************/
00114 
00115 namespace implementation {
00116 
00117     
00118 /*************************************************************************************************/
00119 
00120 template <typename ArgType, typename Function>
00121 struct function_as_view 
00122 { 
00123 //  MM: To do: write Callable1Concept
00124 //  BOOST_CLASS_REQUIRE2(Function, const ModelType&, adobe, Callable1Concept)
00125 
00126     typedef ArgType model_type;
00127 
00128     explicit function_as_view(const Function& f) : f_m(f) {}
00129 
00130     void display(const model_type& x) { f_m(x); }
00131 
00132 // MM: hack so as to work with non-regular F's
00133     friend inline bool operator==(const function_as_view&, const function_as_view&)
00134     { return true; }
00135 
00136     Function f_m;
00137 
00138 };
00139 
00140 /*************************************************************************************************/
00141 
00142 template <typename ArgType, typename Function>
00143 inline function_as_view<ArgType, Function> make_function_as_view(const Function& f)
00144 {
00145     return function_as_view<ArgType, Function>(f);
00146 }
00147 
00148 
00149 } //namespace implementation
00150 
00151 /*************************************************************************************************/
00152 
00153 #endif
00154 
00155 /*************************************************************************************************/
00156 
00180 template <typename ArgType, typename Function>
00181 inline poly<view> make_function_as_poly_view(const Function& f)
00182 {
00183     return poly<view>(implementation::function_as_view<ArgType, Function>(f));
00184 }
00185 
00186 /*************************************************************************************************/
00187 
00188 } // namespace adobe
00189 
00190 /*************************************************************************************************/
00191 
00192 #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