os/ossrv/ossrv_pub/boost_apis/boost/python/instance_holder.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright David Abrahams 2002.
sl@0
     2
// Distributed under the Boost Software License, Version 1.0. (See
sl@0
     3
// accompanying file LICENSE_1_0.txt or copy at
sl@0
     4
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
     5
#ifndef INSTANCE_HOLDER_DWA2002517_HPP
sl@0
     6
# define INSTANCE_HOLDER_DWA2002517_HPP
sl@0
     7
sl@0
     8
# include <boost/python/detail/prefix.hpp>
sl@0
     9
sl@0
    10
# include <boost/utility.hpp>
sl@0
    11
# include <boost/python/type_id.hpp>
sl@0
    12
# include <cstddef>
sl@0
    13
sl@0
    14
namespace boost { namespace python { 
sl@0
    15
sl@0
    16
// Base class for all holders
sl@0
    17
struct BOOST_PYTHON_DECL instance_holder : private noncopyable
sl@0
    18
{
sl@0
    19
 public:
sl@0
    20
    instance_holder();
sl@0
    21
    virtual ~instance_holder();
sl@0
    22
    
sl@0
    23
    // return the next holder in a chain
sl@0
    24
    instance_holder* next() const;
sl@0
    25
sl@0
    26
    // When the derived holder actually holds by [smart] pointer and
sl@0
    27
    // null_ptr_only is set, only report that the type is held when
sl@0
    28
    // the pointer is null.  This is needed for proper shared_ptr
sl@0
    29
    // support, to prevent holding shared_ptrs from being found when
sl@0
    30
    // converting from python so that we can use the conversion method
sl@0
    31
    // that always holds the Python object.
sl@0
    32
    virtual void* holds(type_info, bool null_ptr_only) = 0;
sl@0
    33
sl@0
    34
    void install(PyObject* inst) throw();
sl@0
    35
sl@0
    36
    // These functions should probably be located elsewhere.
sl@0
    37
    
sl@0
    38
    // Allocate storage for an object of the given size at the given
sl@0
    39
    // offset in the Python instance<> object if bytes are available
sl@0
    40
    // there. Otherwise allocate size bytes of heap memory.
sl@0
    41
    static void* allocate(PyObject*, std::size_t offset, std::size_t size);
sl@0
    42
sl@0
    43
    // Deallocate storage from the heap if it was not carved out of
sl@0
    44
    // the given Python object by allocate(), above.
sl@0
    45
    static void deallocate(PyObject*, void* storage) throw();
sl@0
    46
 private:
sl@0
    47
    instance_holder* m_next;
sl@0
    48
};
sl@0
    49
sl@0
    50
// This macro is needed for implementation of derived holders
sl@0
    51
# define BOOST_PYTHON_UNFORWARD(N,ignored) (typename unforward<A##N>::type)(a##N)
sl@0
    52
sl@0
    53
//
sl@0
    54
// implementation
sl@0
    55
//
sl@0
    56
inline instance_holder* instance_holder::next() const
sl@0
    57
{
sl@0
    58
    return m_next;
sl@0
    59
}
sl@0
    60
sl@0
    61
}} // namespace boost::python
sl@0
    62
sl@0
    63
#endif // INSTANCE_HOLDER_DWA2002517_HPP