stlab.adobe.com Adobe Systems Incorporated

view_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_VIEW_HPP
00010 #define ADOBE_VIEW_HPP
00011 
00012 /*************************************************************************************************/
00013 
00014 #include <boost/concept_check.hpp>
00015 #include <boost/ref.hpp>
00016 
00017 #include <adobe/regular_concept.hpp>
00018 
00019 /*************************************************************************************************/
00020 
00021 namespace adobe {
00022 
00023 /*************************************************************************************************/
00024 
00025 #ifdef ADOBE_HAS_CPLUS0X_CONCEPTS
00026 
00027 /*************************************************************************************************/
00028 
00029 auto concept ViewConcept<typename View> 
00030 //: RegularConcept<View> -- Views not yet regular
00031 : std::CopyConstructible<View>
00032 {
00033     typename model_type;
00034     void display(View& v, model_type value); 
00035 };
00036 
00037 /*************************************************************************************************/
00038 
00039 auto concept ViewMFConcept<typename View> 
00040 //: RegularConcept<View> -- Views not yet regular
00041 : std::CopyConstructible<View>
00042 {
00043         
00044     typename model_type = View::model_type;
00045     void View::display(model_type value); 
00046 };
00047 
00048 /*************************************************************************************************/
00049 
00050 template <ViewMFConcept T>
00051 concept_map ViewConcept<T> {
00052     typedef ViewMFConcept<T>::model_type model_type;
00053     inline void display(T& v, model_type value)
00054     { v.display(value); }
00055 };
00056 
00057 /*************************************************************************************************/
00058 
00059 template <ViewConcept T>
00060 concept_map ViewConcept<boost::reference_wrapper<T> > {
00061     typedef ViewConcept<T>::model_type model_type;
00062     void display(boost::reference_wrapper<T>& r, model_type value)
00063     { ViewConcept<T>::display(static_cast<T&>(r),value); }
00064 };
00065 
00066 /*************************************************************************************************/
00067 
00068 #else
00069 
00070 /*************************************************************************************************/
00071     
00072 template <class View>
00073 struct view_model_type 
00074 {
00075     typedef typename boost::unwrap_reference<View>::type::model_type type;
00076 };
00077 
00078 /*************************************************************************************************/
00079 
00080 template <class V> // V models View
00081 inline void display(V& v, const typename view_model_type<V>::type& value)
00082 { v.display(value); }
00083 
00084 /*************************************************************************************************/
00085 
00086 template <class T>
00087 struct ViewConcept
00088 {
00089     typedef typename view_model_type<T>::type model_type; 
00090 
00091     static void display(T& view, const model_type& value)
00092     {
00093         using adobe::display; // pick up default version which looks for member functions
00094         display(view, value); // unqualified to allow user versions
00095     }
00096 
00097 // Concept checking:
00098     //use pointers since not required to be default constructible
00099     T*  t; 
00100     typename view_model_type<T>::type* x;
00101 
00102     void constraints() {    
00103         // refinement of:
00104         // boost::function_requires<RegularConcept<T> >(); // not yet, views not yet regular
00105          //boost::function_requires<boost::CopyConstructibleConcept<T> >();
00106 
00107         // associated types:
00108         typedef typename view_model_type<T>::type associated_type;
00109         
00110         // operations:
00111         using adobe::display; // pick up default version which looks for member functions
00112         display(*t, *x);
00113     }
00114 };
00115 
00116 template <class T>
00117 struct ViewConcept<boost::reference_wrapper<T> > : ViewConcept<T> 
00118 { 
00119     void constraints() {
00120         //boost concept check lib gets confused on VC8 without this
00121         ViewConcept<T>::constraints();
00122     }
00123 };
00124 
00125 #endif
00126 // ADOBE_HAS_CPLUS0X_CONCEPTS
00127 
00128 /*************************************************************************************************/
00129 
00130 } //namespace adobe
00131 
00132 /*************************************************************************************************/
00133 
00134 #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