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