Scarab  v2.11.1
Project 8 C++ Utility Library
Classes | Namespaces | Macros | Typedefs | Functions | Variables
cast.h File Reference
#include "pytypes.h"
#include "detail/typeid.h"
#include "detail/descr.h"
#include "detail/internals.h"
#include <array>
#include <limits>
#include <tuple>
#include <type_traits>
Include dependency graph for cast.h:

Go to the source code of this file.

Classes

class  loader_life_support
 
struct  value_and_holder
 
struct  values_and_holders
 
struct  values_and_holders::iterator
 
class  type_caster_generic
 
struct  is_copy_constructible< T, SFINAE >
 
struct  is_copy_constructible< Container, enable_if_t< all_of< std::is_copy_constructible< Container >, std::is_same< typename Container::value_type &, typename Container::reference > >::value > >
 
struct  is_copy_constructible< std::pair< T1, T2 > >
 
struct  polymorphic_type_hook< itype, SFINAE >
 
struct  polymorphic_type_hook< itype, detail::enable_if_t< std::is_polymorphic< itype >::value > >
 
class  type_caster_base< type >
 Generic type caster for objects stored on the heap. More...
 
class  type_caster< type, SFINAE >
 
class  type_caster< std::reference_wrapper< type > >
 
struct  type_caster< T, enable_if_t< std::is_arithmetic< T >::value &&!is_std_char_type< T >::value > >
 
struct  void_caster< T >
 
class  type_caster< void_type >
 
class  type_caster< void >
 
class  type_caster< std::nullptr_t >
 
class  type_caster< bool >
 
struct  string_caster< StringType, IsView >
 
struct  type_caster< std::basic_string< CharT, Traits, Allocator >, enable_if_t< is_std_char_type< CharT >::value > >
 
struct  type_caster< CharT, enable_if_t< is_std_char_type< CharT >::value > >
 
class  tuple_caster< Tuple, Ts >
 
class  type_caster< std::pair< T1, T2 > >
 
class  type_caster< std::tuple< Ts... > >
 
struct  holder_helper< T >
 
struct  copyable_holder_caster< type, holder_type >
 Type caster for holder types like std::shared_ptr, etc. More...
 
class  type_caster< std::shared_ptr< T > >
 Specialize for the common std::shared_ptr, so users don't need to. More...
 
struct  move_only_holder_caster< type, holder_type >
 
class  type_caster< std::unique_ptr< type, deleter > >
 
struct  always_construct_holder< T, Value >
 
struct  is_holder_type< base, holder >
 
struct  is_holder_type< base, std::unique_ptr< base, deleter > >
 
struct  handle_type_name< T >
 
struct  handle_type_name< bytes >
 
struct  handle_type_name< args >
 
struct  handle_type_name< kwargs >
 
struct  pyobject_caster< type >
 
class  type_caster< T, enable_if_t< is_pyobject< T >::value > >
 
struct  move_always< T, SFINAE >
 
struct  move_always< T, enable_if_t< all_of< move_is_plain_type< T >, negation< is_copy_constructible< T > >, std::is_move_constructible< T >, std::is_same< decltype(std::declval< make_caster< T >>().operator T &()), T & >>::value > >
 
struct  move_if_unreferenced< T, SFINAE >
 
struct  move_if_unreferenced< T, enable_if_t< all_of< move_is_plain_type< T >, negation< move_always< T > >, std::is_move_constructible< T >, std::is_same< decltype(std::declval< make_caster< T >>().operator T &()), T & >>::value > >
 
struct  return_value_policy_override< Return, SFINAE >
 
struct  return_value_policy_override< Return, detail::enable_if_t< std::is_base_of< type_caster_generic, make_caster< Return > >::value, void > >
 
struct  overload_unused
 
struct  arg
 
struct  arg_v
 
struct  function_call
 Internal data associated with a single function call. More...
 
class  argument_loader< Args >
 Helper class which loads arguments for C++ functions called from Python. More...
 
class  simple_collector< policy >
 
class  unpacking_collector< policy >
 Helper class which collects positional, keyword, * and ** arguments for a Python function call. More...
 

Namespaces

 pybind11
 glibc defines I as a macro which breaks things, e.g., boost template names
 
 pybind11::detail
 
 pybind11::literals
 

Macros

#define PYBIND11_TYPE_CASTER(type, py_name)
 
#define PYBIND11_DECLARE_HOLDER_TYPE(type, holder_type, ...)
 Create a specialization for custom holder types (silently ignores std::shared_ptr) More...
 
#define PYBIND11_MAKE_OPAQUE(...)
 
#define PYBIND11_TYPE(...)   __VA_ARGS__
 

Typedefs

template<typename T >
using cast_op_type = conditional_t< std::is_pointer< remove_reference_t< T > >::value, typename std::add_pointer< intrinsic_t< T > >::type, typename std::add_lvalue_reference< intrinsic_t< T > >::type >
 
template<typename T >
using movable_cast_op_type = conditional_t< std::is_pointer< typename std::remove_reference< T >::type >::value, typename std::add_pointer< intrinsic_t< T > >::type, conditional_t< std::is_rvalue_reference< T >::value, typename std::add_rvalue_reference< intrinsic_t< T > >::type, typename std::add_lvalue_reference< intrinsic_t< T > >::type > >
 
template<typename type >
using make_caster = type_caster< intrinsic_t< type > >
 
template<typename CharT >
using is_std_char_type = any_of< std::is_same< CharT, char >, std::is_same< CharT, char16_t >, std::is_same< CharT, char32_t >, std::is_same< CharT, wchar_t > >
 
template<typename type , typename holder_type >
using type_caster_holder = conditional_t< is_copy_constructible< holder_type >::value, copyable_holder_caster< type, holder_type >, move_only_holder_caster< type, holder_type > >
 
template<typename T >
using move_is_plain_type = satisfies_none_of< T, std::is_void, std::is_pointer, std::is_reference, std::is_const >
 
template<typename T >
using move_never = none_of< move_always< T >, move_if_unreferenced< T > >
 
template<typename type >
using cast_is_temporary_value_reference = bool_constant<(std::is_reference< type >::value||std::is_pointer< type >::value) &&!std::is_base_of< type_caster_generic, make_caster< type > >::value &&!std::is_same< intrinsic_t< type >, void >::value >
 
template<typename ret_type >
using overload_caster_t = conditional_t< cast_is_temporary_value_reference< ret_type >::value, make_caster< ret_type >, overload_unused >
 
template<typename >
using arg_t = arg_v
 Alias for backward compatibility – to be removed in version 2.0. More...
 

Functions

std::pair< decltype(internals::registered_types_py)::iterator, bool > all_type_info_get_cache (PyTypeObject *type)
 
 __attribute__ ((noinline)) inline detail
 Return the type info for a given C++ type; on lookup failure can either throw or return nullptr. More...
 
 for (handle parent :reinterpret_borrow< tuple >(t->tp_bases)) check.push_back((PyTypeObject *) parent.ptr())
 
 for (size_t i=0;i< check.size();i++)
 
const std::vector< detail::type_info * > & all_type_info (PyTypeObject *type)
 
detail::type_info * get_local_type_info (const std::type_index &tp)
 
detail::type_info * get_global_type_info (const std::type_index &tp)
 
 if (!type) return false
 
return isinstance (obj, type)
 
 for (auto it=range.first;it !=range.second;++it)
 
return handle ()
 
PyThreadState * get_thread_state_unchecked ()
 
void keep_alive_impl (handle nurse, handle patient)
 
PyObject * make_new_instance (PyTypeObject *type)
 
template<typename T >
make_caster< T >::template cast_op_type< T > cast_op (make_caster< T > &caster)
 
template<typename T >
make_caster< T >::template cast_op_type< typename std::add_rvalue_reference< T >::type > cast_op (make_caster< T > &&caster)
 
template<typename T , typename SFINAE >
type_caster< T, SFINAE > & load_type (type_caster< T, SFINAE > &conv, const handle &handle)
 
template<typename T >
make_caster< T > load_type (const handle &handle)
 
template<typename T , detail::enable_if_t<!detail::is_pyobject< T >::value, int > = 0>
cast (const handle &handle)
 
template<typename T , detail::enable_if_t<!detail::is_pyobject< T >::value, int > = 0>
object cast (const T &value, return_value_policy policy=return_value_policy::automatic_reference, handle parent=handle())
 
template<typename T >
detail::enable_if_t<!detail::move_never< T >::value, T > move (object &&obj)
 
template<typename T >
detail::enable_if_t< detail::move_always< T >::value, T > cast (object &&object)
 
template<typename T >
detail::enable_if_t< detail::move_if_unreferenced< T >::value, T > cast (object &&object)
 
template<typename T >
detail::enable_if_t< detail::move_never< T >::value, T > cast (object &&object)
 
template<typename T , enable_if_t<!is_pyobject< T >::value, int > >
object object_or_cast (T &&o)
 
template<typename T >
enable_if_t< cast_is_temporary_value_reference< T >::value, T > cast_ref (object &&o, make_caster< T > &caster)
 
template<typename T >
enable_if_t<!cast_is_temporary_value_reference< T >::value, T > cast_ref (object &&, overload_unused &)
 
template<typename T >
enable_if_t<!cast_is_temporary_value_reference< T >::value, T > cast_safe (object &&o)
 
template<typename T >
enable_if_t< cast_is_temporary_value_reference< T >::value, T > cast_safe (object &&)
 
template<>
void cast_safe< void > (object &&)
 
template<return_value_policy policy = return_value_policy::automatic_reference>
tuple make_tuple ()
 
template<return_value_policy policy = return_value_policy::automatic_reference, typename... Args>
tuple make_tuple (Args &&... args_)
 
constexpr arg operator"" _a (const char *name, size_t)
 
template<return_value_policy policy, typename... Args, typename = enable_if_t<all_of<is_positional<Args>...>::value>>
simple_collector< policy > collect_arguments (Args &&...args)
 Collect only positional arguments for a Python function call. More...
 
template<return_value_policy policy, typename... Args, typename = enable_if_t<!all_of<is_positional<Args>...>::value>>
unpacking_collector< policy > collect_arguments (Args &&...args)
 Collect all arguments, including keywords and unpacking (only instantiated when needed) More...
 

Variables

std::vector< type_info * > & bases
 
auto const & type_dict = get_internals().registered_types_py
 
const std::type_info & tp
 
const detail::type_info * type
 
auto range = instances.equal_range(ptr)
 

Macro Definition Documentation

◆ PYBIND11_DECLARE_HOLDER_TYPE

#define PYBIND11_DECLARE_HOLDER_TYPE (   type,
  holder_type,
  ... 
)
Value:
namespace pybind11 { namespace detail { \
template <typename type> \
struct always_construct_holder<holder_type> : always_construct_holder<void, ##__VA_ARGS__> { }; \
template <typename type> \
: public type_caster_holder<type, holder_type> { }; \
}}
glibc defines I as a macro which breaks things, e.g., boost template names
Definition: attr.h:15

Create a specialization for custom holder types (silently ignores std::shared_ptr)

Definition at line 1539 of file cast.h.

◆ PYBIND11_MAKE_OPAQUE

#define PYBIND11_MAKE_OPAQUE (   ...)
Value:
namespace pybind11 { namespace detail { \
template<> class type_caster<__VA_ARGS__> : public type_caster_base<__VA_ARGS__> { }; \
}}
glibc defines I as a macro which breaks things, e.g., boost template names
Definition: attr.h:15

Definition at line 2121 of file cast.h.

◆ PYBIND11_TYPE

#define PYBIND11_TYPE (   ...)    __VA_ARGS__

Lets you pass a type containing a , through a macro parameter without needing a separate typedef, e.g.: PYBIND11_OVERLOAD(PYBIND11_TYPE(ReturnType<A, B>), PYBIND11_TYPE(Parent<C, D>), f, arg)

Definition at line 2128 of file cast.h.

◆ PYBIND11_TYPE_CASTER

#define PYBIND11_TYPE_CASTER (   type,
  py_name 
)
Value:
protected: \
type value; \
public: \
static constexpr auto name = py_name; \
template <typename T_, enable_if_t<std::is_same<type, remove_cv_t<T_>>::value, int> = 0> \
static handle cast(T_ *src, return_value_policy policy, handle parent) { \
if (!src) return none().release(); \
if (policy == return_value_policy::take_ownership) { \
auto h = cast(std::move(*src), policy, parent); delete src; return h; \
} else { \
return cast(*src, policy, parent); \
} \
} \
operator type*() { return &value; } \
operator type&() { return value; } \
operator type&&() && { return std::move(value); } \
detail::enable_if_t< detail::move_never< T >::value, T > cast(object &&object)
Definition: cast.h:1714
conditional_t< std::is_pointer< remove_reference_t< T > >::value, typename std::add_pointer< intrinsic_t< T > >::type, typename std::add_lvalue_reference< intrinsic_t< T > >::type > cast_op_type
Definition: cast.h:752
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
conditional_t< std::is_pointer< typename std::remove_reference< T >::type >::value, typename std::add_pointer< intrinsic_t< T > >::type, conditional_t< std::is_rvalue_reference< T >::value, typename std::add_rvalue_reference< intrinsic_t< T > >::type, typename std::add_lvalue_reference< intrinsic_t< T > >::type > > movable_cast_op_type
Definition: cast.h:767
const detail::type_info * type
Definition: cast.h:453
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
Definition: cast.h:1685

Definition at line 942 of file cast.h.