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