fix doc example typo
[boost.git] / boost / python / instance_holder.hpp
blob0916348ef64fda12591d41ce6709b0d338e68b72
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
8 # include <boost/python/detail/prefix.hpp>
10 # include <boost/utility.hpp>
11 # include <boost/python/type_id.hpp>
12 # include <cstddef>
14 namespace boost { namespace python {
16 // Base class for all holders
17 struct BOOST_PYTHON_DECL instance_holder : private noncopyable
19 public:
20 instance_holder();
21 virtual ~instance_holder();
23 // return the next holder in a chain
24 instance_holder* next() const;
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;
34 void install(PyObject* inst) throw();
36 // These functions should probably be located elsewhere.
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);
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;
50 // This macro is needed for implementation of derived holders
51 # define BOOST_PYTHON_UNFORWARD(N,ignored) (typename unforward<A##N>::type)(a##N)
54 // implementation
56 inline instance_holder* instance_holder::next() const
58 return m_next;
61 }} // namespace boost::python
63 #endif // INSTANCE_HOLDER_DWA2002517_HPP