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