mirror of
https://github.com/boostorg/python.git
synced 2026-01-27 19:12:16 +00:00
Lots of documentation updates, plus the associated code shuffling needed to expose the right things to users
[SVN r13975]
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
# include <boost/python/args.hpp>
|
||||
# include <boost/python/reference.hpp>
|
||||
# include <boost/python/object/class.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/detail/wrap_function.hpp>
|
||||
# include <boost/python/detail/member_function_cast.hpp>
|
||||
# include <boost/python/object/class_converters.hpp>
|
||||
@@ -194,7 +194,7 @@ class class_ : public objects::class_base
|
||||
id_vector()
|
||||
{
|
||||
// Stick the derived class id into the first element of the array
|
||||
ids[0] = converter::undecorated_type_id<T>();
|
||||
ids[0] = type_id<T>();
|
||||
|
||||
// Write the rest of the elements into succeeding positions.
|
||||
class_id* p = ids + 1;
|
||||
@@ -276,9 +276,9 @@ namespace detail
|
||||
typedef void type;
|
||||
|
||||
// Here's the runtime behavior
|
||||
static void execute(converter::undecorated_type_id_t** p)
|
||||
static void execute(type_info** p)
|
||||
{
|
||||
*(*p)++ = converter::undecorated_type_id<T>();
|
||||
*(*p)++ = type_id<T>();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#ifndef CALLBACK_DWA2002228_HPP
|
||||
# define CALLBACK_DWA2002228_HPP
|
||||
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/converter/to_python_function.hpp>
|
||||
# include <boost/python/converter/pointee_to_python_function.hpp>
|
||||
# include <boost/python/converter/from_python.hpp>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
# include <boost/python/converter/find_from_python.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/python/converter/from_python_data.hpp>
|
||||
|
||||
@@ -6,9 +6,11 @@
|
||||
#ifndef LVALUE_FROM_PYTHON_CHAIN_DWA200237_HPP
|
||||
# define LVALUE_FROM_PYTHON_CHAIN_DWA200237_HPP
|
||||
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/converter/pointer_type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
@@ -39,7 +41,7 @@ namespace detail
|
||||
template <class T>
|
||||
lvalue_from_python_registration*const&
|
||||
ref_lvalue_from_python_chain<T>::value
|
||||
= registry::lvalue_converters(undecorated_type_id<T>());
|
||||
= registry::lvalue_converters(type_id<T>());
|
||||
|
||||
template <class T, bool callback>
|
||||
struct select_lvalue_from_python_chain
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/converter/to_python_function_type.hpp>
|
||||
# include <boost/python/converter/pointer_type_id.hpp>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#ifndef POINTER_TYPE_ID_DWA2002222_HPP
|
||||
# define POINTER_TYPE_ID_DWA2002222_HPP
|
||||
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
@@ -17,9 +17,9 @@ namespace detail
|
||||
struct pointer_typeid_select
|
||||
{
|
||||
template <class T>
|
||||
static inline undecorated_type_id_t execute(T*(*)() = 0)
|
||||
static inline type_info execute(T*(*)() = 0)
|
||||
{
|
||||
return undecorated_type_id<T>();
|
||||
return type_id<T>();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -27,37 +27,37 @@ namespace detail
|
||||
struct pointer_typeid_select<true>
|
||||
{
|
||||
template <class T>
|
||||
static inline undecorated_type_id_t execute(T* const volatile&(*)() = 0)
|
||||
static inline type_info execute(T* const volatile&(*)() = 0)
|
||||
{
|
||||
return undecorated_type_id<T>();
|
||||
return type_id<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline undecorated_type_id_t execute(T*volatile&(*)() = 0)
|
||||
static inline type_info execute(T*volatile&(*)() = 0)
|
||||
{
|
||||
return undecorated_type_id<T>();
|
||||
return type_id<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline undecorated_type_id_t execute(T*const&(*)() = 0)
|
||||
static inline type_info execute(T*const&(*)() = 0)
|
||||
{
|
||||
return undecorated_type_id<T>();
|
||||
return type_id<T>();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static inline undecorated_type_id_t execute(T*&(*)() = 0)
|
||||
static inline type_info execute(T*&(*)() = 0)
|
||||
{
|
||||
return undecorated_type_id<T>();
|
||||
return type_id<T>();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Usage: pointer_type_id<T>()
|
||||
//
|
||||
// Returns an undecorated_type_id_t associated with the type pointed
|
||||
// Returns a type_info associated with the type pointed
|
||||
// to by T, which may be a pointer or a reference to a pointer.
|
||||
template <class T>
|
||||
undecorated_type_id_t pointer_type_id(T(*)() = 0)
|
||||
type_info pointer_type_id(T(*)() = 0)
|
||||
{
|
||||
return detail::pointer_typeid_select<
|
||||
is_reference<T>::value
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// to its suitability for any purpose.
|
||||
#ifndef REGISTRY_DWA20011127_HPP
|
||||
# define REGISTRY_DWA20011127_HPP
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/converter/to_python_function_type.hpp>
|
||||
@@ -19,22 +19,22 @@ struct rvalue_from_python_registration;
|
||||
// This namespace acts as a sort of singleton
|
||||
namespace registry
|
||||
{
|
||||
BOOST_PYTHON_DECL lvalue_from_python_registration*& lvalue_converters(undecorated_type_id_t);
|
||||
BOOST_PYTHON_DECL rvalue_from_python_registration*& rvalue_converters(undecorated_type_id_t);
|
||||
BOOST_PYTHON_DECL lvalue_from_python_registration*& lvalue_converters(type_info);
|
||||
BOOST_PYTHON_DECL rvalue_from_python_registration*& rvalue_converters(type_info);
|
||||
|
||||
BOOST_PYTHON_DECL to_python_function_t const&
|
||||
get_to_python_function(undecorated_type_id_t);
|
||||
get_to_python_function(type_info);
|
||||
|
||||
BOOST_PYTHON_DECL void insert(to_python_function_t, undecorated_type_id_t);
|
||||
BOOST_PYTHON_DECL void insert(to_python_function_t, type_info);
|
||||
|
||||
// Insert an lvalue from_python converter
|
||||
BOOST_PYTHON_DECL void insert(void* (*convert)(PyObject*), undecorated_type_id_t);
|
||||
BOOST_PYTHON_DECL void insert(void* (*convert)(PyObject*), type_info);
|
||||
|
||||
// Insert an rvalue from_python converter
|
||||
BOOST_PYTHON_DECL void insert(
|
||||
void* (*convertible)(PyObject*)
|
||||
, constructor_function
|
||||
, undecorated_type_id_t
|
||||
, type_info
|
||||
);
|
||||
|
||||
// Insert an rvalue from_python converter at the tail of the
|
||||
@@ -42,10 +42,10 @@ namespace registry
|
||||
BOOST_PYTHON_DECL void push_back(
|
||||
void* (*convertible)(PyObject*)
|
||||
, constructor_function
|
||||
, undecorated_type_id_t
|
||||
, type_info
|
||||
);
|
||||
|
||||
BOOST_PYTHON_DECL PyTypeObject*& class_object(undecorated_type_id_t key);
|
||||
BOOST_PYTHON_DECL PyTypeObject*& class_object(type_info key);
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// to its suitability for any purpose.
|
||||
#ifndef RVALUE_FROM_PYTHON_CHAIN_DWA200237_HPP
|
||||
# define RVALUE_FROM_PYTHON_CHAIN_DWA200237_HPP
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
@@ -21,7 +22,7 @@ namespace detail
|
||||
|
||||
template <class T>
|
||||
rvalue_from_python_registration*const& rvalue_from_python_chain_impl<T>::value
|
||||
= registry::rvalue_converters(undecorated_type_id<T>());
|
||||
= registry::rvalue_converters(type_id<T>());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/converter/to_python_function_type.hpp>
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace detail
|
||||
template <class T>
|
||||
to_python_function_t const&
|
||||
to_python_function_base<T>::value
|
||||
= converter::registry::get_to_python_function(undecorated_type_id<T>());
|
||||
= converter::registry::get_to_python_function(type_id<T>());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
// Copyright David Abrahams 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef TYPE_ID_DWA20011127_HPP
|
||||
# define TYPE_ID_DWA20011127_HPP
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/python/detail/msvc_typeinfo.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
# include <boost/type_traits/composite_traits.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/operators.hpp>
|
||||
# include <boost/type.hpp>
|
||||
# include <typeinfo>
|
||||
# include <iosfwd>
|
||||
# include <cstring>
|
||||
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// for this compiler at least, cross-shared-library type_info
|
||||
// comparisons don't work, so use typeid(x).name() instead. It's not
|
||||
// yet clear what the best default strategy is.
|
||||
# if defined(__GNUC__) && __GNUC__ >= 3
|
||||
# define BOOST_PYTHON_TYPE_ID_NAME
|
||||
# endif
|
||||
|
||||
// type ids which represent the same information as std::type_info
|
||||
// (i.e. the top-level reference and cv-qualifiers are stripped), but
|
||||
// which works across shared libraries.
|
||||
struct undecorated_type_id_t : totally_ordered<undecorated_type_id_t>
|
||||
{
|
||||
undecorated_type_id_t(std::type_info const&);
|
||||
|
||||
// default constructor needed to build arrays, etc.
|
||||
undecorated_type_id_t();
|
||||
|
||||
bool operator<(undecorated_type_id_t const& rhs) const;
|
||||
bool operator==(undecorated_type_id_t const& rhs) const;
|
||||
|
||||
char const* name() const;
|
||||
friend BOOST_PYTHON_DECL std::ostream& operator<<(
|
||||
std::ostream&, undecorated_type_id_t const&);
|
||||
|
||||
private: // data members
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
typedef char const* base_id_t;
|
||||
# else
|
||||
typedef std::type_info const* base_id_t;
|
||||
# endif
|
||||
|
||||
base_id_t m_base_type;
|
||||
};
|
||||
|
||||
struct type_id_t : totally_ordered<type_id_t>
|
||||
{
|
||||
enum decoration { const_ = 0x1, volatile_ = 0x2, reference = 0x4 };
|
||||
|
||||
type_id_t(undecorated_type_id_t, decoration = decoration());
|
||||
|
||||
bool operator<(type_id_t const& rhs) const;
|
||||
bool operator==(type_id_t const& rhs) const;
|
||||
|
||||
friend BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, type_id_t const&);
|
||||
|
||||
operator undecorated_type_id_t const&() const;
|
||||
private: // type
|
||||
typedef undecorated_type_id_t base_id_t;
|
||||
|
||||
private: // data members
|
||||
decoration m_decoration;
|
||||
base_id_t m_base_type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline undecorated_type_id_t undecorated_type_id(boost::type<T>* = 0)
|
||||
{
|
||||
return undecorated_type_id_t(
|
||||
# if (!defined(BOOST_MSVC) || BOOST_MSVC > 1300) && (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 600)
|
||||
typeid(T)
|
||||
# else // strip the decoration which msvc and Intel mistakenly leave in
|
||||
python::detail::msvc_typeid<T>()
|
||||
# endif
|
||||
);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline type_id_t type_id(boost::type<T>* = 0)
|
||||
{
|
||||
return type_id_t(
|
||||
undecorated_type_id<T>()
|
||||
, type_id_t::decoration(
|
||||
(is_const<T>::value || python::detail::is_reference_to_const<T>::value
|
||||
? type_id_t::const_ : 0)
|
||||
| (is_volatile<T>::value || python::detail::is_reference_to_volatile<T>::value
|
||||
? type_id_t::volatile_ : 0)
|
||||
| (is_reference<T>::value ? type_id_t::reference : 0)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
inline undecorated_type_id_t::undecorated_type_id_t(std::type_info const& id)
|
||||
: m_base_type(
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
id.name()
|
||||
# else
|
||||
&id
|
||||
# endif
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
inline undecorated_type_id_t::undecorated_type_id_t()
|
||||
: m_base_type()
|
||||
{
|
||||
}
|
||||
|
||||
inline type_id_t::type_id_t(undecorated_type_id_t base_t, decoration decoration)
|
||||
: m_decoration(decoration)
|
||||
, m_base_type(base_t)
|
||||
{
|
||||
}
|
||||
|
||||
inline bool undecorated_type_id_t::operator<(undecorated_type_id_t const& rhs) const
|
||||
{
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
return std::strcmp(m_base_type, rhs.m_base_type) < 0;
|
||||
# else
|
||||
return m_base_type->before(*rhs.m_base_type);
|
||||
# endif
|
||||
}
|
||||
|
||||
inline bool type_id_t::operator<(type_id_t const& rhs) const
|
||||
{
|
||||
return m_decoration < rhs.m_decoration
|
||||
|| m_decoration == rhs.m_decoration
|
||||
&& m_base_type < rhs.m_base_type;
|
||||
}
|
||||
|
||||
inline bool undecorated_type_id_t::operator==(undecorated_type_id_t const& rhs) const
|
||||
{
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
return !std::strcmp(m_base_type, rhs.m_base_type);
|
||||
# else
|
||||
return *m_base_type == *rhs.m_base_type;
|
||||
# endif
|
||||
}
|
||||
|
||||
inline bool type_id_t::operator==(type_id_t const& rhs) const
|
||||
{
|
||||
return m_decoration == rhs.m_decoration && m_base_type == rhs.m_base_type;
|
||||
}
|
||||
|
||||
inline type_id_t::operator undecorated_type_id_t const&() const
|
||||
{
|
||||
return m_base_type;
|
||||
}
|
||||
|
||||
inline char const* undecorated_type_id_t::name() const
|
||||
{
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
return m_base_type;
|
||||
# else
|
||||
return m_base_type->name();
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, undecorated_type_id_t const&);
|
||||
BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, type_id_t const&);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // TYPE_ID_DWA20011127_HPP
|
||||
77
include/boost/python/detail/decorated_type_id.hpp
Executable file
77
include/boost/python/detail/decorated_type_id.hpp
Executable file
@@ -0,0 +1,77 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef DECORATED_TYPE_ID_DWA2002517_HPP
|
||||
# define DECORATED_TYPE_ID_DWA2002517_HPP
|
||||
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# include <boost/type_traits/cv_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
struct decorated_type_info : totally_ordered<decorated_type_info>
|
||||
{
|
||||
enum decoration { const_ = 0x1, volatile_ = 0x2, reference = 0x4 };
|
||||
|
||||
decorated_type_info(type_info, decoration = decoration());
|
||||
|
||||
bool operator<(decorated_type_info const& rhs) const;
|
||||
bool operator==(decorated_type_info const& rhs) const;
|
||||
|
||||
friend BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, decorated_type_info const&);
|
||||
|
||||
operator type_info const&() const;
|
||||
private: // type
|
||||
typedef type_info base_id_t;
|
||||
|
||||
private: // data members
|
||||
decoration m_decoration;
|
||||
base_id_t m_base_type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline decorated_type_info decorated_type_id(boost::type<T>* = 0)
|
||||
{
|
||||
return decorated_type_info(
|
||||
type_id<T>()
|
||||
, decorated_type_info::decoration(
|
||||
(is_const<T>::value || python::detail::is_reference_to_const<T>::value
|
||||
? decorated_type_info::const_ : 0)
|
||||
| (is_volatile<T>::value || python::detail::is_reference_to_volatile<T>::value
|
||||
? decorated_type_info::volatile_ : 0)
|
||||
| (is_reference<T>::value ? decorated_type_info::reference : 0)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
inline decorated_type_info::decorated_type_info(type_info base_t, decoration decoration)
|
||||
: m_decoration(decoration)
|
||||
, m_base_type(base_t)
|
||||
{
|
||||
}
|
||||
|
||||
inline bool decorated_type_info::operator<(decorated_type_info const& rhs) const
|
||||
{
|
||||
return m_decoration < rhs.m_decoration
|
||||
|| m_decoration == rhs.m_decoration
|
||||
&& m_base_type < rhs.m_base_type;
|
||||
}
|
||||
|
||||
inline bool decorated_type_info::operator==(decorated_type_info const& rhs) const
|
||||
{
|
||||
return m_decoration == rhs.m_decoration && m_base_type == rhs.m_base_type;
|
||||
}
|
||||
|
||||
inline decorated_type_info::operator type_info const&() const
|
||||
{
|
||||
return m_base_type;
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, decorated_type_info const&);
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // DECORATED_TYPE_ID_DWA2002517_HPP
|
||||
@@ -8,7 +8,7 @@
|
||||
# include <boost/type.hpp>
|
||||
# include <boost/python/converter/implicit.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
@@ -20,7 +20,7 @@ void implicitly_convertible(boost::type<Source>* = 0, boost::type<Target>* = 0)
|
||||
converter::registry::push_back(
|
||||
&functions::convertible
|
||||
, &functions::construct
|
||||
, converter::undecorated_type_id<Target>());
|
||||
, type_id<Target>());
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
43
include/boost/python/instance_holder.hpp
Executable file
43
include/boost/python/instance_holder.hpp
Executable file
@@ -0,0 +1,43 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef INSTANCE_HOLDER_DWA2002517_HPP
|
||||
# define INSTANCE_HOLDER_DWA2002517_HPP
|
||||
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/utility.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
// Base class for all holders
|
||||
struct BOOST_PYTHON_DECL instance_holder : private noncopyable
|
||||
{
|
||||
public:
|
||||
instance_holder();
|
||||
virtual ~instance_holder();
|
||||
|
||||
// return the next holder in a chain
|
||||
instance_holder* next() const;
|
||||
|
||||
virtual void* holds(type_info) = 0;
|
||||
|
||||
void install(PyObject* inst) throw();
|
||||
private:
|
||||
instance_holder* m_next;
|
||||
};
|
||||
// This macro is needed for implementation of derived holders
|
||||
# define BOOST_PYTHON_UNFORWARD(N,ignored) (typename unforward<A##N>::type)(a##N)
|
||||
|
||||
//
|
||||
// implementation
|
||||
//
|
||||
inline instance_holder* instance_holder::next() const
|
||||
{
|
||||
return m_next;
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // INSTANCE_HOLDER_DWA2002517_HPP
|
||||
@@ -35,8 +35,8 @@ objects::function* make_function(F f, Policies const& policies)
|
||||
, detail::arg_tuple_size<F>::value);
|
||||
}
|
||||
|
||||
template <class ArgList, class Holder>
|
||||
objects::function* make_constructor(Holder* = 0, ArgList* = 0)
|
||||
template <class ArgList, class HolderGenerator>
|
||||
objects::function* make_constructor(HolderGenerator* = 0, ArgList* = 0)
|
||||
{
|
||||
enum { nargs = mpl::size<ArgList>::value };
|
||||
|
||||
@@ -44,13 +44,13 @@ objects::function* make_constructor(Holder* = 0, ArgList* = 0)
|
||||
objects::py_function(
|
||||
::boost::bind<PyObject*>(detail::caller(),
|
||||
objects::make_holder<nargs>
|
||||
::template apply<Holder,ArgList>::execute
|
||||
::template apply<HolderGenerator,ArgList>::execute
|
||||
, _1, _2, default_call_policies()))
|
||||
, nargs + 1);
|
||||
}
|
||||
|
||||
template <class ArgList, class Holder, class Policies>
|
||||
objects::function* make_constructor(Policies const& policies, Holder* = 0, ArgList* = 0)
|
||||
template <class ArgList, class HolderGenerator, class Policies>
|
||||
objects::function* make_constructor(Policies const& policies, HolderGenerator* = 0, ArgList* = 0)
|
||||
{
|
||||
enum { nargs = mpl::size<ArgList>::value };
|
||||
|
||||
@@ -58,7 +58,7 @@ objects::function* make_constructor(Policies const& policies, Holder* = 0, ArgLi
|
||||
objects::py_function(
|
||||
::boost::bind<PyObject*>(detail::caller(),
|
||||
objects::make_holder<nargs>
|
||||
::template apply<Holder,ArgList>::execute
|
||||
::template apply<HolderGenerator,ArgList>::execute
|
||||
, _1, _2, policies))
|
||||
, nargs + 1);
|
||||
}
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
# include <boost/python/detail/wrap_python.hpp>
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/utility.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/reference.hpp>
|
||||
# include <boost/python/instance_holder.hpp>
|
||||
# include <cstddef>
|
||||
|
||||
namespace boost { namespace python {
|
||||
@@ -19,10 +20,8 @@ class module;
|
||||
|
||||
namespace objects {
|
||||
|
||||
template <class T> struct holder;
|
||||
|
||||
// To identify a class, we don't need cv/reference decorations
|
||||
typedef converter::undecorated_type_id_t class_id;
|
||||
typedef type_info class_id;
|
||||
|
||||
struct BOOST_PYTHON_DECL class_base : private noncopyable
|
||||
{
|
||||
@@ -46,25 +45,6 @@ struct BOOST_PYTHON_DECL class_base : private noncopyable
|
||||
|
||||
BOOST_PYTHON_DECL ref registered_class_object(class_id id);
|
||||
|
||||
// Base class for all holders
|
||||
struct BOOST_PYTHON_DECL instance_holder : private noncopyable
|
||||
{
|
||||
public:
|
||||
instance_holder();
|
||||
virtual ~instance_holder();
|
||||
|
||||
// return the next holder in a chain
|
||||
instance_holder* next() const;
|
||||
|
||||
virtual void* holds(converter::undecorated_type_id_t) = 0;
|
||||
|
||||
void install(PyObject* inst) throw();
|
||||
private:
|
||||
instance_holder* m_next;
|
||||
};
|
||||
// This macro is needed for implementation of derived holders
|
||||
# define BOOST_PYTHON_UNFORWARD(N,ignored) (typename unforward<A##N>::type)(a##N)
|
||||
|
||||
// Each extension instance will be one of these
|
||||
struct instance
|
||||
{
|
||||
@@ -75,14 +55,6 @@ struct instance
|
||||
BOOST_PYTHON_DECL ref class_metatype();
|
||||
BOOST_PYTHON_DECL ref class_type();
|
||||
|
||||
//
|
||||
// implementation
|
||||
//
|
||||
inline instance_holder* instance_holder::next() const
|
||||
{
|
||||
return m_next;
|
||||
}
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // CLASS_DWA20011214_HPP
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#ifndef CLASS_OBJECT_DWA200222_HPP
|
||||
# define CLASS_OBJECT_DWA200222_HPP
|
||||
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
@@ -18,8 +18,8 @@ struct class_object
|
||||
};
|
||||
|
||||
template <class T>
|
||||
PyTypeObject*& class_object<T>::reference = converter::registry::class_object(
|
||||
converter::undecorated_type_id<T>());
|
||||
PyTypeObject*& class_object<T>::reference
|
||||
= converter::registry::class_object(python::type_id<T>());
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
#ifndef FIND_INSTANCE_DWA2002312_HPP
|
||||
# define FIND_INSTANCE_DWA2002312_HPP
|
||||
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
// Given an undecorated type_id, find the instance data which
|
||||
// corresponds to it, or return 0 in case no such type is held.
|
||||
BOOST_PYTHON_DECL void* find_instance_impl(PyObject*, converter::undecorated_type_id_t);
|
||||
// Given a type_id, find the instance data which corresponds to it, or
|
||||
// return 0 in case no such type is held.
|
||||
BOOST_PYTHON_DECL void* find_instance_impl(PyObject*, type_info);
|
||||
|
||||
// This produces a function with the right signature for use in from_python conversions
|
||||
template <class T>
|
||||
@@ -21,14 +21,14 @@ struct instance_finder
|
||||
{
|
||||
instance_finder()
|
||||
{
|
||||
converter::registry::insert(&execute, converter::undecorated_type_id<T>());
|
||||
converter::registry::insert(&execute, python::type_id<T>());
|
||||
}
|
||||
|
||||
static instance_finder const registration;
|
||||
private:
|
||||
static inline void* execute(PyObject* p)
|
||||
{
|
||||
return find_instance_impl(p, converter::undecorated_type_id<T>());
|
||||
return find_instance_impl(p, python::type_id<T>());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -6,13 +6,15 @@
|
||||
#ifndef INHERITANCE_DWA200216_HPP
|
||||
# define INHERITANCE_DWA200216_HPP
|
||||
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/shared_ptr.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/type_traits/object_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
|
||||
typedef converter::undecorated_type_id_t class_id;
|
||||
using converter::undecorated_type_id;
|
||||
typedef type_info class_id;
|
||||
using python::type_id;
|
||||
|
||||
// Types used to get address and id of most derived type
|
||||
typedef std::pair<void*,class_id> dynamic_id_t;
|
||||
@@ -70,7 +72,7 @@ struct non_polymorphic_id_generator
|
||||
{
|
||||
static dynamic_id_t execute(void* p_)
|
||||
{
|
||||
return std::make_pair(p_, converter::undecorated_type_id<T>());
|
||||
return std::make_pair(p_, python::type_id<T>());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -91,7 +93,7 @@ void register_dynamic_id(T* = 0)
|
||||
{
|
||||
typedef typename dynamic_id_generator<T>::type generator;
|
||||
register_dynamic_id_aux(
|
||||
converter::undecorated_type_id<T>(), &generator::execute);
|
||||
python::type_id<T>(), &generator::execute);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -154,8 +156,8 @@ inline void register_conversion(
|
||||
{
|
||||
typedef typename cast_generator<Source,Target>::type generator;
|
||||
|
||||
add_cast(converter::undecorated_type_id<Source>()
|
||||
, converter::undecorated_type_id<Target>()
|
||||
add_cast(python::type_id<Source>()
|
||||
, python::type_id<Target>()
|
||||
, &generator::execute
|
||||
, is_downcast);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
# define POINTER_HOLDER_DWA20011215_HPP
|
||||
|
||||
# include <boost/python/object/class.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/object/inheritance.hpp>
|
||||
# include <boost/python/object/find_instance.hpp>
|
||||
# include <boost/python/object/forward.hpp>
|
||||
@@ -46,7 +46,7 @@ struct pointer_holder : instance_holder
|
||||
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_CONSTRUCT_POINTER_HOLDER,nil)
|
||||
|
||||
private: // required holder implementation
|
||||
void* holds(converter::undecorated_type_id_t);
|
||||
void* holds(type_info);
|
||||
|
||||
private: // data members
|
||||
Pointer m_p;
|
||||
@@ -84,45 +84,45 @@ struct pointer_holder_back_reference : instance_holder
|
||||
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_CONSTRUCT_POINTER_HOLDER_BACK_REFERENCE,nil)
|
||||
|
||||
private: // required holder implementation
|
||||
void* holds(converter::undecorated_type_id_t);
|
||||
void* holds(type_info);
|
||||
|
||||
private: // data members
|
||||
Pointer m_p;
|
||||
};
|
||||
|
||||
template <class Pointer, class Value>
|
||||
pointer_holder<Pointer,Value>::pointer_holder(Pointer p)
|
||||
inline pointer_holder<Pointer,Value>::pointer_holder(Pointer p)
|
||||
: m_p(p)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Pointer, class Value>
|
||||
pointer_holder_back_reference<Pointer,Value>::pointer_holder_back_reference(Pointer p)
|
||||
inline pointer_holder_back_reference<Pointer,Value>::pointer_holder_back_reference(Pointer p)
|
||||
: m_p(p)
|
||||
{
|
||||
}
|
||||
|
||||
template <class Pointer, class Value>
|
||||
void* pointer_holder<Pointer, Value>::holds(converter::undecorated_type_id_t dst_t)
|
||||
void* pointer_holder<Pointer, Value>::holds(type_info dst_t)
|
||||
{
|
||||
if (dst_t == converter::undecorated_type_id<Pointer>())
|
||||
if (dst_t == python::type_id<Pointer>())
|
||||
return &this->m_p;
|
||||
|
||||
converter::type_id_t src_t = converter::undecorated_type_id<Value>();
|
||||
type_info src_t = python::type_id<Value>();
|
||||
return src_t == dst_t ? &*this->m_p
|
||||
: find_dynamic_type(&*this->m_p, src_t, dst_t);
|
||||
}
|
||||
|
||||
template <class Pointer, class Value>
|
||||
void* pointer_holder_back_reference<Pointer, Value>::holds(converter::undecorated_type_id_t dst_t)
|
||||
void* pointer_holder_back_reference<Pointer, Value>::holds(type_info dst_t)
|
||||
{
|
||||
if (dst_t == converter::undecorated_type_id<Pointer>())
|
||||
if (dst_t == python::type_id<Pointer>())
|
||||
return &this->m_p;
|
||||
|
||||
if (dst_t == converter::undecorated_type_id<held_type>())
|
||||
if (dst_t == python::type_id<held_type>())
|
||||
return &*this->m_p;
|
||||
|
||||
converter::type_id_t src_t = converter::undecorated_type_id<Value>();
|
||||
type_info src_t = python::type_id<Value>();
|
||||
Value* p = &*this->m_p;
|
||||
return src_t == dst_t ? p : find_dynamic_type(p, src_t, dst_t);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
# include <boost/python/object/value_holder_fwd.hpp>
|
||||
# include <boost/python/object/class.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/object/inheritance.hpp>
|
||||
# include <boost/python/object/find_instance.hpp>
|
||||
# include <boost/python/object/forward.hpp>
|
||||
@@ -40,7 +40,7 @@ struct value_holder : instance_holder
|
||||
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_CONSTRUCT_VALUE_HOLDER,nil)
|
||||
|
||||
private: // required holder implementation
|
||||
void* holds(converter::undecorated_type_id_t);
|
||||
void* holds(type_info);
|
||||
|
||||
private: // data members
|
||||
Held m_held;
|
||||
@@ -72,32 +72,32 @@ struct value_holder_back_reference : instance_holder
|
||||
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_CONSTRUCT_VALUE_HOLDER_BACK_REFERENCE,nil)
|
||||
|
||||
private: // required holder implementation
|
||||
void* holds(converter::undecorated_type_id_t);
|
||||
void* holds(type_info);
|
||||
|
||||
private: // data members
|
||||
BackReferenceType m_held;
|
||||
};
|
||||
|
||||
template <class Held>
|
||||
void* value_holder<Held>::holds(converter::undecorated_type_id_t dst_t)
|
||||
void* value_holder<Held>::holds(type_info dst_t)
|
||||
{
|
||||
converter::undecorated_type_id_t src_t = converter::undecorated_type_id<Held>();
|
||||
type_info src_t = python::type_id<Held>();
|
||||
return src_t == dst_t ? &m_held
|
||||
: find_static_type(&m_held, src_t, dst_t);
|
||||
}
|
||||
|
||||
template <class Held, class BackReferenceType>
|
||||
void* value_holder_back_reference<Held,BackReferenceType>::holds(
|
||||
converter::undecorated_type_id_t dst_t)
|
||||
type_info dst_t)
|
||||
{
|
||||
converter::undecorated_type_id_t src_t = converter::undecorated_type_id<Held>();
|
||||
type_info src_t = python::type_id<Held>();
|
||||
if (src_t == dst_t)
|
||||
{
|
||||
Held* x = &m_held;
|
||||
return x;
|
||||
}
|
||||
|
||||
src_t = converter::undecorated_type_id<BackReferenceType>();
|
||||
src_t = python::type_id<BackReferenceType>();
|
||||
return src_t == dst_t
|
||||
? &m_held
|
||||
: find_static_type(&m_held, src_t, dst_t);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/converter/to_python_function.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/type_id.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
@@ -31,7 +31,7 @@ to_python_converter<T,Conversion>::to_python_converter()
|
||||
|
||||
converter::registry::insert(
|
||||
&normalized::convert
|
||||
, converter::undecorated_type_id<T>());
|
||||
, type_id<T>());
|
||||
}
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
# define TO_PYTHON_VALUE_DWA200221_HPP
|
||||
|
||||
# include <boost/type_traits/transform_traits.hpp>
|
||||
# include <boost/python/converter/type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/converter/to_python_function.hpp>
|
||||
# include <boost/python/converter/builtin_converters.hpp>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#ifndef TYPE_FROM_PYTHON_DWA2002130_HPP
|
||||
# define TYPE_FROM_PYTHON_DWA2002130_HPP
|
||||
|
||||
# include <boost/python/type_id.hpp>
|
||||
# include <boost/python/converter/registry.hpp>
|
||||
# include <boost/python/detail/void_ptr.hpp>
|
||||
|
||||
@@ -16,9 +17,9 @@ namespace detail
|
||||
// Given a pointer-to-function of 1 parameter returning a reference
|
||||
// type, return the type_id of the function's return type.
|
||||
template <class T, class U>
|
||||
inline converter::undecorated_type_id_t extractor_type_id(T&(*)(U))
|
||||
inline type_info extractor_type_id(T&(*)(U))
|
||||
{
|
||||
return converter::undecorated_type_id<T>();
|
||||
return type_id<T>();
|
||||
}
|
||||
|
||||
// A function generator whose static execute() function is an lvalue
|
||||
|
||||
102
include/boost/python/type_id.hpp
Executable file
102
include/boost/python/type_id.hpp
Executable file
@@ -0,0 +1,102 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#ifndef TYPE_ID_DWA2002517_HPP
|
||||
# define TYPE_ID_DWA2002517_HPP
|
||||
|
||||
# include <boost/python/detail/config.hpp>
|
||||
# include <boost/python/detail/msvc_typeinfo.hpp>
|
||||
# include <boost/operators.hpp>
|
||||
# include <typeinfo>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
// for this compiler at least, cross-shared-library type_info
|
||||
// comparisons don't work, so use typeid(x).name() instead. It's not
|
||||
// yet clear what the best default strategy is.
|
||||
# if defined(__GNUC__) && __GNUC__ >= 3
|
||||
# define BOOST_PYTHON_TYPE_ID_NAME
|
||||
# endif
|
||||
|
||||
// type ids which represent the same information as std::type_info
|
||||
// (i.e. the top-level reference and cv-qualifiers are stripped), but
|
||||
// which works across shared libraries.
|
||||
struct type_info : private totally_ordered<type_info>
|
||||
{
|
||||
type_info(std::type_info const& = typeid(void));
|
||||
|
||||
bool operator<(type_info const& rhs) const;
|
||||
bool operator==(type_info const& rhs) const;
|
||||
|
||||
char const* name() const;
|
||||
friend BOOST_PYTHON_DECL std::ostream& operator<<(
|
||||
std::ostream&, type_info const&);
|
||||
|
||||
private: // data members
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
typedef char const* base_id_t;
|
||||
# else
|
||||
typedef std::type_info const* base_id_t;
|
||||
# endif
|
||||
|
||||
base_id_t m_base_type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline type_info type_id(boost::type<T>* = 0)
|
||||
{
|
||||
return type_info(
|
||||
# if (!defined(BOOST_MSVC) || BOOST_MSVC > 1300) && (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 600)
|
||||
typeid(T)
|
||||
# else // strip the decoration which msvc and Intel mistakenly leave in
|
||||
python::detail::msvc_typeid<T>()
|
||||
# endif
|
||||
);
|
||||
}
|
||||
|
||||
inline type_info::type_info(std::type_info const& id)
|
||||
: m_base_type(
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
id.name()
|
||||
# else
|
||||
&id
|
||||
# endif
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
inline bool type_info::operator<(type_info const& rhs) const
|
||||
{
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
return std::strcmp(m_base_type, rhs.m_base_type) < 0;
|
||||
# else
|
||||
return m_base_type->before(*rhs.m_base_type);
|
||||
# endif
|
||||
}
|
||||
|
||||
inline bool type_info::operator==(type_info const& rhs) const
|
||||
{
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
return !std::strcmp(m_base_type, rhs.m_base_type);
|
||||
# else
|
||||
return *m_base_type == *rhs.m_base_type;
|
||||
# endif
|
||||
}
|
||||
|
||||
inline char const* type_info::name() const
|
||||
{
|
||||
# ifdef BOOST_PYTHON_TYPE_ID_NAME
|
||||
return m_base_type;
|
||||
# else
|
||||
return m_base_type->name();
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream&, type_info const&);
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // TYPE_ID_DWA2002517_HPP
|
||||
Reference in New Issue
Block a user