sl@0: // Copyright David Abrahams 2002. sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: #ifndef INSTANCE_HOLDER_DWA2002517_HPP sl@0: # define INSTANCE_HOLDER_DWA2002517_HPP sl@0: sl@0: # include sl@0: sl@0: # include sl@0: # include sl@0: # include sl@0: sl@0: namespace boost { namespace python { sl@0: sl@0: // Base class for all holders sl@0: struct BOOST_PYTHON_DECL instance_holder : private noncopyable sl@0: { sl@0: public: sl@0: instance_holder(); sl@0: virtual ~instance_holder(); sl@0: sl@0: // return the next holder in a chain sl@0: instance_holder* next() const; sl@0: sl@0: // When the derived holder actually holds by [smart] pointer and sl@0: // null_ptr_only is set, only report that the type is held when sl@0: // the pointer is null. This is needed for proper shared_ptr sl@0: // support, to prevent holding shared_ptrs from being found when sl@0: // converting from python so that we can use the conversion method sl@0: // that always holds the Python object. sl@0: virtual void* holds(type_info, bool null_ptr_only) = 0; sl@0: sl@0: void install(PyObject* inst) throw(); sl@0: sl@0: // These functions should probably be located elsewhere. sl@0: sl@0: // Allocate storage for an object of the given size at the given sl@0: // offset in the Python instance<> object if bytes are available sl@0: // there. Otherwise allocate size bytes of heap memory. sl@0: static void* allocate(PyObject*, std::size_t offset, std::size_t size); sl@0: sl@0: // Deallocate storage from the heap if it was not carved out of sl@0: // the given Python object by allocate(), above. sl@0: static void deallocate(PyObject*, void* storage) throw(); sl@0: private: sl@0: instance_holder* m_next; sl@0: }; sl@0: sl@0: // This macro is needed for implementation of derived holders sl@0: # define BOOST_PYTHON_UNFORWARD(N,ignored) (typename unforward::type)(a##N) sl@0: sl@0: // sl@0: // implementation sl@0: // sl@0: inline instance_holder* instance_holder::next() const sl@0: { sl@0: return m_next; sl@0: } sl@0: sl@0: }} // namespace boost::python sl@0: sl@0: #endif // INSTANCE_HOLDER_DWA2002517_HPP