1 // Copyright David Abrahams 2002. 2 // Distributed under the Boost Software License, Version 1.0. (See 3 // accompanying file LICENSE_1_0.txt or copy at 4 // http://www.boost.org/LICENSE_1_0.txt) 5 #ifndef BACK_REFERENCE_DWA2002510_HPP 6 # define BACK_REFERENCE_DWA2002510_HPP 7 8 # include <boost/python/detail/prefix.hpp> 9 10 # include <boost/python/object_fwd.hpp> 11 # include <boost/python/detail/dependent.hpp> 12 # include <boost/python/detail/raw_pyobject.hpp> 13 14 namespace boost { namespace python { 15 16 template <class T> 17 struct back_reference 18 { 19 private: // types 20 typedef typename detail::dependent<object,T>::type source_t; 21 public: 22 typedef T type; 23 24 back_reference(PyObject*, T); 25 source_t const& source() const; 26 T get() const; 27 private: 28 source_t m_source; 29 T m_value; 30 }; 31 32 template<typename T> 33 class is_back_reference 34 { 35 public: 36 BOOST_STATIC_CONSTANT(bool, value = false); 37 }; 38 39 template<typename T> 40 class is_back_reference<back_reference<T> > 41 { 42 public: 43 BOOST_STATIC_CONSTANT(bool, value = true); 44 }; 45 46 47 // 48 // implementations 49 // 50 template <class T> back_reference(PyObject * p,T x)51back_reference<T>::back_reference(PyObject* p, T x) 52 : m_source(detail::borrowed_reference(p)) 53 , m_value(x) 54 { 55 } 56 57 template <class T> source() const58typename back_reference<T>::source_t const& back_reference<T>::source() const 59 { 60 return m_source; 61 } 62 63 template <class T> get() const64T back_reference<T>::get() const 65 { 66 return m_value; 67 } 68 69 }} // namespace boost::python 70 71 #endif // BACK_REFERENCE_DWA2002510_HPP 72