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 INSTANCE_HOLDER_DWA2002517_HPP
|
Chris@16
|
6 # define INSTANCE_HOLDER_DWA2002517_HPP
|
Chris@16
|
7
|
Chris@16
|
8 # include <boost/python/detail/prefix.hpp>
|
Chris@16
|
9
|
Chris@16
|
10 # include <boost/noncopyable.hpp>
|
Chris@16
|
11 # include <boost/python/type_id.hpp>
|
Chris@16
|
12 # include <cstddef>
|
Chris@16
|
13
|
Chris@16
|
14 namespace boost { namespace python {
|
Chris@16
|
15
|
Chris@16
|
16 // Base class for all holders
|
Chris@16
|
17 struct BOOST_PYTHON_DECL instance_holder : private noncopyable
|
Chris@16
|
18 {
|
Chris@16
|
19 public:
|
Chris@16
|
20 instance_holder();
|
Chris@16
|
21 virtual ~instance_holder();
|
Chris@16
|
22
|
Chris@16
|
23 // return the next holder in a chain
|
Chris@16
|
24 instance_holder* next() const;
|
Chris@16
|
25
|
Chris@16
|
26 // When the derived holder actually holds by [smart] pointer and
|
Chris@16
|
27 // null_ptr_only is set, only report that the type is held when
|
Chris@16
|
28 // the pointer is null. This is needed for proper shared_ptr
|
Chris@16
|
29 // support, to prevent holding shared_ptrs from being found when
|
Chris@16
|
30 // converting from python so that we can use the conversion method
|
Chris@16
|
31 // that always holds the Python object.
|
Chris@16
|
32 virtual void* holds(type_info, bool null_ptr_only) = 0;
|
Chris@16
|
33
|
Chris@16
|
34 void install(PyObject* inst) throw();
|
Chris@16
|
35
|
Chris@16
|
36 // These functions should probably be located elsewhere.
|
Chris@16
|
37
|
Chris@16
|
38 // Allocate storage for an object of the given size at the given
|
Chris@16
|
39 // offset in the Python instance<> object if bytes are available
|
Chris@16
|
40 // there. Otherwise allocate size bytes of heap memory.
|
Chris@16
|
41 static void* allocate(PyObject*, std::size_t offset, std::size_t size);
|
Chris@16
|
42
|
Chris@16
|
43 // Deallocate storage from the heap if it was not carved out of
|
Chris@16
|
44 // the given Python object by allocate(), above.
|
Chris@16
|
45 static void deallocate(PyObject*, void* storage) throw();
|
Chris@16
|
46 private:
|
Chris@16
|
47 instance_holder* m_next;
|
Chris@16
|
48 };
|
Chris@16
|
49
|
Chris@16
|
50 // This macro is needed for implementation of derived holders
|
Chris@16
|
51 # define BOOST_PYTHON_UNFORWARD(N,ignored) (typename unforward<A##N>::type)(a##N)
|
Chris@16
|
52
|
Chris@16
|
53 //
|
Chris@16
|
54 // implementation
|
Chris@16
|
55 //
|
Chris@16
|
56 inline instance_holder* instance_holder::next() const
|
Chris@16
|
57 {
|
Chris@16
|
58 return m_next;
|
Chris@16
|
59 }
|
Chris@16
|
60
|
Chris@16
|
61 }} // namespace boost::python
|
Chris@16
|
62
|
Chris@16
|
63 #endif // INSTANCE_HOLDER_DWA2002517_HPP
|