source: NonGTP/Boost/boost/python/back_reference.hpp @ 857

Revision 857, 2.3 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[857]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
14namespace boost { namespace python {
15
16template <class T>
17struct 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# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
33template<typename T>
34class is_back_reference
35{
36 public:
37    BOOST_STATIC_CONSTANT(bool, value = false);
38};
39
40template<typename T>
41class is_back_reference<back_reference<T> >
42{
43 public:
44    BOOST_STATIC_CONSTANT(bool, value = true);
45};
46
47# else // no partial specialization
48
49}} // namespace boost::python
50
51#include <boost/type.hpp>
52
53namespace boost { namespace python {
54
55namespace detail
56{
57  typedef char (&yes_back_reference_t)[1];
58  typedef char (&no_back_reference_t)[2];
59     
60  no_back_reference_t is_back_reference_test(...);
61
62  template<typename T>
63  yes_back_reference_t is_back_reference_test(boost::type< back_reference<T> >);
64}
65
66template<typename T>
67class is_back_reference
68{
69 public:
70    BOOST_STATIC_CONSTANT(
71        bool, value = (
72            sizeof(detail::is_back_reference_test(boost::type<T>()))
73            == sizeof(detail::yes_back_reference_t)));
74};
75
76# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
77
78//
79// implementations
80//
81template <class T>
82back_reference<T>::back_reference(PyObject* p, T x)
83    : m_source(detail::borrowed_reference(p))
84      , m_value(x)
85{
86}
87
88template <class T>
89typename back_reference<T>::source_t const& back_reference<T>::source() const
90{
91    return m_source;
92}
93
94template <class T>
95T back_reference<T>::get() const
96{
97    return m_value;
98}
99
100}} // namespace boost::python
101
102#endif // BACK_REFERENCE_DWA2002510_HPP
Note: See TracBrowser for help on using the repository browser.