author | sl |
Tue, 10 Jun 2014 14:32:02 +0200 | |
changeset 1 | 260cb5ec6c19 |
permissions | -rw-r--r-- |
sl@0 | 1 |
// Copyright David Abrahams 2002. |
sl@0 | 2 |
// Distributed under the Boost Software License, Version 1.0. (See |
sl@0 | 3 |
// accompanying file LICENSE_1_0.txt or copy at |
sl@0 | 4 |
// http://www.boost.org/LICENSE_1_0.txt) |
sl@0 | 5 |
#ifndef BACK_REFERENCE_DWA2002510_HPP |
sl@0 | 6 |
# define BACK_REFERENCE_DWA2002510_HPP |
sl@0 | 7 |
|
sl@0 | 8 |
# include <boost/python/detail/prefix.hpp> |
sl@0 | 9 |
|
sl@0 | 10 |
# include <boost/python/object_fwd.hpp> |
sl@0 | 11 |
# include <boost/python/detail/dependent.hpp> |
sl@0 | 12 |
# include <boost/python/detail/raw_pyobject.hpp> |
sl@0 | 13 |
|
sl@0 | 14 |
namespace boost { namespace python { |
sl@0 | 15 |
|
sl@0 | 16 |
template <class T> |
sl@0 | 17 |
struct back_reference |
sl@0 | 18 |
{ |
sl@0 | 19 |
private: // types |
sl@0 | 20 |
typedef typename detail::dependent<object,T>::type source_t; |
sl@0 | 21 |
public: |
sl@0 | 22 |
typedef T type; |
sl@0 | 23 |
|
sl@0 | 24 |
back_reference(PyObject*, T); |
sl@0 | 25 |
source_t const& source() const; |
sl@0 | 26 |
T get() const; |
sl@0 | 27 |
private: |
sl@0 | 28 |
source_t m_source; |
sl@0 | 29 |
T m_value; |
sl@0 | 30 |
}; |
sl@0 | 31 |
|
sl@0 | 32 |
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
sl@0 | 33 |
template<typename T> |
sl@0 | 34 |
class is_back_reference |
sl@0 | 35 |
{ |
sl@0 | 36 |
public: |
sl@0 | 37 |
BOOST_STATIC_CONSTANT(bool, value = false); |
sl@0 | 38 |
}; |
sl@0 | 39 |
|
sl@0 | 40 |
template<typename T> |
sl@0 | 41 |
class is_back_reference<back_reference<T> > |
sl@0 | 42 |
{ |
sl@0 | 43 |
public: |
sl@0 | 44 |
BOOST_STATIC_CONSTANT(bool, value = true); |
sl@0 | 45 |
}; |
sl@0 | 46 |
|
sl@0 | 47 |
# else // no partial specialization |
sl@0 | 48 |
|
sl@0 | 49 |
}} // namespace boost::python |
sl@0 | 50 |
|
sl@0 | 51 |
#include <boost/type.hpp> |
sl@0 | 52 |
|
sl@0 | 53 |
namespace boost { namespace python { |
sl@0 | 54 |
|
sl@0 | 55 |
namespace detail |
sl@0 | 56 |
{ |
sl@0 | 57 |
typedef char (&yes_back_reference_t)[1]; |
sl@0 | 58 |
typedef char (&no_back_reference_t)[2]; |
sl@0 | 59 |
|
sl@0 | 60 |
no_back_reference_t is_back_reference_test(...); |
sl@0 | 61 |
|
sl@0 | 62 |
template<typename T> |
sl@0 | 63 |
yes_back_reference_t is_back_reference_test(boost::type< back_reference<T> >); |
sl@0 | 64 |
} |
sl@0 | 65 |
|
sl@0 | 66 |
template<typename T> |
sl@0 | 67 |
class is_back_reference |
sl@0 | 68 |
{ |
sl@0 | 69 |
public: |
sl@0 | 70 |
BOOST_STATIC_CONSTANT( |
sl@0 | 71 |
bool, value = ( |
sl@0 | 72 |
sizeof(detail::is_back_reference_test(boost::type<T>())) |
sl@0 | 73 |
== sizeof(detail::yes_back_reference_t))); |
sl@0 | 74 |
}; |
sl@0 | 75 |
|
sl@0 | 76 |
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
sl@0 | 77 |
|
sl@0 | 78 |
// |
sl@0 | 79 |
// implementations |
sl@0 | 80 |
// |
sl@0 | 81 |
template <class T> |
sl@0 | 82 |
back_reference<T>::back_reference(PyObject* p, T x) |
sl@0 | 83 |
: m_source(detail::borrowed_reference(p)) |
sl@0 | 84 |
, m_value(x) |
sl@0 | 85 |
{ |
sl@0 | 86 |
} |
sl@0 | 87 |
|
sl@0 | 88 |
template <class T> |
sl@0 | 89 |
typename back_reference<T>::source_t const& back_reference<T>::source() const |
sl@0 | 90 |
{ |
sl@0 | 91 |
return m_source; |
sl@0 | 92 |
} |
sl@0 | 93 |
|
sl@0 | 94 |
template <class T> |
sl@0 | 95 |
T back_reference<T>::get() const |
sl@0 | 96 |
{ |
sl@0 | 97 |
return m_value; |
sl@0 | 98 |
} |
sl@0 | 99 |
|
sl@0 | 100 |
}} // namespace boost::python |
sl@0 | 101 |
|
sl@0 | 102 |
#endif // BACK_REFERENCE_DWA2002510_HPP |