Classes | Namespaces | Macros | Typedefs | Functions
cast.h File Reference
#include "detail/common.h"
#include "detail/descr.h"
#include "detail/type_caster_base.h"
#include "detail/typeid.h"
#include "pytypes.h"
#include <array>
#include <cstring>
#include <functional>
#include <iosfwd>
#include <iterator>
#include <memory>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
Include dependency graph for cast.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  always_construct_holder< T, Value >
 
struct  arg
 
struct  arg_v
 
class  argument_loader< Args >
 Helper class which loads arguments for C++ functions called from Python. More...
 
struct  copyable_holder_caster< type, holder_type, SFINAE >
 
struct  function_call
 Internal data associated with a single function call. More...
 
struct  handle_type_name< T >
 
struct  handle_type_name< anyset >
 
struct  handle_type_name< args >
 
struct  handle_type_name< bool_ >
 
struct  handle_type_name< buffer >
 
struct  handle_type_name< bytearray >
 
struct  handle_type_name< bytes >
 
struct  handle_type_name< capsule >
 
struct  handle_type_name< dict >
 
struct  handle_type_name< ellipsis >
 
struct  handle_type_name< float_ >
 
struct  handle_type_name< frozenset >
 
struct  handle_type_name< function >
 
struct  handle_type_name< handle >
 
struct  handle_type_name< int_ >
 
struct  handle_type_name< item_accessor >
 
struct  handle_type_name< iterable >
 
struct  handle_type_name< iterator >
 
struct  handle_type_name< kwargs >
 
struct  handle_type_name< list >
 
struct  handle_type_name< list_accessor >
 
struct  handle_type_name< memoryview >
 
struct  handle_type_name< none >
 
struct  handle_type_name< obj_attr_accessor >
 
struct  handle_type_name< object >
 
struct  handle_type_name< sequence >
 
struct  handle_type_name< sequence_accessor >
 
struct  handle_type_name< set >
 
struct  handle_type_name< slice >
 
struct  handle_type_name< str >
 
struct  handle_type_name< str_attr_accessor >
 
struct  handle_type_name< tuple >
 
struct  handle_type_name< tuple_accessor >
 
struct  handle_type_name< type >
 
struct  handle_type_name< weakref >
 
struct  holder_helper< T >
 
struct  is_holder_type< base, holder >
 
struct  is_holder_type< base, std::unique_ptr< base, deleter > >
 
struct  kw_only
 
struct  move_always< T, SFINAE >
 
struct  move_always< T, enable_if_t< all_of< move_is_plain_type< T >, negation< is_copy_constructible< T > >, 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 > >, is_move_constructible< T >, std::is_same< decltype(std::declval< make_caster< T >>().operator T&()), T & > >::value > >
 
struct  move_only_holder_caster< type, holder_type, SFINAE >
 
struct  override_unused
 
struct  pos_only
 
struct  pyobject_caster< type >
 
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 > >
 
class  simple_collector< policy >
 
struct  string_caster< StringType, IsView >
 
class  tuple_caster< Tuple, Ts >
 
class  type_caster< type, SFINAE >
 
class  type_caster< bool >
 
struct  type_caster< CharT, enable_if_t< is_std_char_type< CharT >::value > >
 
struct  type_caster< std::basic_string< CharT, Traits, Allocator >, enable_if_t< is_std_char_type< CharT >::value > >
 
class  type_caster< std::nullptr_t >
 
class  type_caster< std::pair< T1, T2 > >
 
class  type_caster< std::reference_wrapper< type > >
 
class  type_caster< std::shared_ptr< T > >
 Specialize for the common std::shared_ptr, so users don't need to. More...
 
class  type_caster< std::tuple< Ts... > >
 
class  type_caster< std::unique_ptr< type, deleter > >
 
class  type_caster< T, enable_if_t< is_pyobject< T >::value > >
 
struct  type_caster< T, enable_if_t< std::is_arithmetic< T >::value &&!is_std_char_type< T >::value > >
 
class  type_caster< void >
 
class  type_caster< void_type >
 
class  unpacking_collector< policy >
 Helper class which collects positional, keyword, * and ** arguments for a Python function call. More...
 
struct  void_caster< T >
 

Namespaces

 literals
 

Macros

#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__
 
#define PYBIND11_TYPE_CASTER(type, py_name)
 

Typedefs

template<typename >
using arg_t = arg_v
 Alias for backward compatibility – to be removed in version 2.0. More...
 
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 T >
using is_kw_only = std::is_same< intrinsic_t< T >, kw_only >
 
template<typename T >
using is_pos_only = std::is_same< intrinsic_t< T >, pos_only >
 
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 >
using make_caster = type_caster< intrinsic_t< 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 ret_type >
using override_caster_t = conditional_t< cast_is_temporary_value_reference< ret_type >::value, make_caster< ret_type >, override_unused >
 
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 > >
 

Functions

template<typename... Args>
constexpr bool args_are_all_positional ()
 
template<typename T , detail::enable_if_t<!detail::is_pyobject< T >::value &&!detail::is_same_ignoring_cvref< T, PyObject * >::value, int > = 0>
T cast (const handle &handle)
 
template<typename T , typename Handle , detail::enable_if_t< detail::is_same_ignoring_cvref< T, PyObject * >::value &&detail::is_same_ignoring_cvref< Handle, handle >::value, int > = 0>
T cast (Handle &&handle)
 
template<typename T , typename Object , detail::enable_if_t< detail::is_same_ignoring_cvref< T, PyObject * >::value &&detail::is_same_ignoring_cvref< Object, object >::value, int > = 0>
T cast (Object &&obj)
 
template<typename T >
detail::enable_if_t<!detail::is_pyobject< T >::value &&detail::move_always< T >::value, Tcast (object &&object)
 
template<typename T >
detail::enable_if_t<!detail::is_pyobject< T >::value &&detail::move_if_unreferenced< T >::value, Tcast (object &&object)
 
template<typename T >
detail::enable_if_t<!detail::is_pyobject< T >::value &&detail::move_never< T >::value, Tcast (object &&object)
 
template<typename T >
detail::enable_if_t< detail::is_pyobject< T >::value, Tcast (object &&object)
 
template<typename T , detail::enable_if_t<!detail::is_pyobject< T >::value, int > = 0>
object cast (T &&value, return_value_policy policy=return_value_policy::automatic_reference, handle parent=handle())
 
cast_error cast_error_unable_to_convert_call_arg (const std::string &name, const std::string &type)
 
template<typename T >
make_caster< T >::template cast_op_type< typename std::add_rvalue_reference< T >::typecast_op (make_caster< T > &&caster)
 
template<typename T >
make_caster< T >::template cast_op_type< Tcast_op (make_caster< T > &caster)
 
template<typename T >
enable_if_t<!cast_is_temporary_value_reference< T >::value, Tcast_ref (object &&, override_unused &)
 
template<typename T >
enable_if_t< cast_is_temporary_value_reference< T >::value, Tcast_ref (object &&o, make_caster< T > &caster)
 
template<typename T >
enable_if_t< cast_is_temporary_value_reference< T >::value &&!detail::is_same_ignoring_cvref< T, PyObject * >::value, Tcast_safe (object &&)
 
template<typename T >
enable_if_t< std::is_void< T >::value, void > cast_safe (object &&)
 
template<typename T >
enable_if_t< detail::is_same_ignoring_cvref< T, PyObject * >::value, PyObject * > cast_safe (object &&o)
 
template<typename T >
enable_if_t< detail::none_of< cast_is_temporary_value_reference< T >, detail::is_same_ignoring_cvref< T, PyObject * >, std::is_void< T > >::value, Tcast_safe (object &&o)
 
template<return_value_policy policy, typename... Args, typename = enable_if_t<args_are_all_positional<Args...>()>>
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<!args_are_all_positional<Args...>()>>
unpacking_collector< policy > collect_arguments (Args &&...args)
 Collect all arguments, including keywords and unpacking (only instantiated when needed) More...
 
template<typename T >
make_caster< Tload_type (const handle &handle)
 
template<typename T , typename SFINAE >
type_caster< T, SFINAE > & load_type (type_caster< T, SFINAE > &conv, const handle &handle)
 
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_)
 
template<typename T >
detail::enable_if_t<!detail::move_never< T >::value, Tmove (object &&obj)
 
template<typename T , enable_if_t<!is_pyobject< T >::value, int > >
object object_or_cast (T &&o)
 
constexpr arg literals::operator""_a (const char *name, size_t)
 

Macro Definition Documentation

◆ PYBIND11_DECLARE_HOLDER_TYPE

#define PYBIND11_DECLARE_HOLDER_TYPE (   type,
  holder_type,
  ... 
)
Value:

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

Definition at line 865 of file cast.h.

◆ PYBIND11_MAKE_OPAQUE

#define PYBIND11_MAKE_OPAQUE (   ...)
Value:
namespace detail { \
template <> \
} \
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

Definition at line 1835 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_OVERRIDE(PYBIND11_TYPE(ReturnType<A, B>), PYBIND11_TYPE(Parent<C, D>), f, arg)

Definition at line 1846 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_, \
std::is_same<type, ::pybind11::detail::remove_cv_t<T_>>::value, \
int> \
= 0> \
static ::pybind11::handle cast( \
T_ *src, ::pybind11::return_value_policy policy, ::pybind11::handle parent) { \
if (!src) \
return ::pybind11::none().release(); \
if (policy == ::pybind11::return_value_policy::take_ownership) { \
auto h = cast(std::move(*src), policy, parent); \
delete src; \
return h; \
} \
return cast(*src, policy, parent); \
} \
operator type *() { return &value; } /* NOLINT(bugprone-macro-parentheses) */ \
operator type &() { return value; } /* NOLINT(bugprone-macro-parentheses) */ \
operator type &&() && { return std::move(value); } /* NOLINT(bugprone-macro-parentheses) */ \
template <typename T_> \
using cast_op_type = ::pybind11::detail::movable_cast_op_type<T_>

Definition at line 87 of file cast.h.

Typedef Documentation

◆ arg_t

template<typename >
using arg_t = arg_v

Alias for backward compatibility – to be removed in version 2.0.

Definition at line 1509 of file cast.h.

◆ cast_is_temporary_value_reference

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>

Definition at line 1116 of file cast.h.

◆ is_kw_only

template<typename T >
using is_kw_only = std::is_same<intrinsic_t<T>, kw_only>

Definition at line 1529 of file cast.h.

◆ is_pos_only

template<typename T >
using is_pos_only = std::is_same<intrinsic_t<T>, pos_only>

Definition at line 1531 of file cast.h.

◆ is_std_char_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> >

Definition at line 123 of file cast.h.

◆ make_caster

template<typename type >
using make_caster = type_caster<intrinsic_t<type> >

Definition at line 40 of file cast.h.

◆ move_is_plain_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>

Definition at line 1082 of file cast.h.

◆ move_never

template<typename T >
using move_never = none_of<move_always<T>, move_if_unreferenced<T> >

Definition at line 1106 of file cast.h.

◆ override_caster_t

template<typename ret_type >
using override_caster_t = conditional_t<cast_is_temporary_value_reference<ret_type>::value, make_caster<ret_type>, override_unused>

Definition at line 1323 of file cast.h.

◆ type_caster_holder

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> >

Definition at line 857 of file cast.h.

Function Documentation

◆ args_are_all_positional()

template<typename... Args>
constexpr bool args_are_all_positional ( )
constexpr

Definition at line 1781 of file cast.h.

◆ cast() [1/8]

template<typename T , detail::enable_if_t<!detail::is_pyobject< T >::value &&!detail::is_same_ignoring_cvref< T, PyObject * >::value, int > = 0>
T cast ( const handle handle)

Definition at line 1173 of file cast.h.

◆ cast() [2/8]

template<typename T , typename Handle , detail::enable_if_t< detail::is_same_ignoring_cvref< T, PyObject * >::value &&detail::is_same_ignoring_cvref< Handle, handle >::value, int > = 0>
T cast ( Handle &&  handle)

Definition at line 1200 of file cast.h.

◆ cast() [3/8]

template<typename T , typename Object , detail::enable_if_t< detail::is_same_ignoring_cvref< T, PyObject * >::value &&detail::is_same_ignoring_cvref< Object, object >::value, int > = 0>
T cast ( Object &&  obj)

Definition at line 1210 of file cast.h.

◆ cast() [4/8]

template<typename T >
detail::enable_if_t<!detail::is_pyobject<T>::value && detail::move_always<T>::value, T> cast ( object &&  object)

Definition at line 1269 of file cast.h.

◆ cast() [5/8]

template<typename T >
detail::enable_if_t<!detail::is_pyobject<T>::value && detail::move_if_unreferenced<T>::value, T> cast ( object &&  object)

Definition at line 1274 of file cast.h.

◆ cast() [6/8]

template<typename T >
detail::enable_if_t<!detail::is_pyobject<T>::value && detail::move_never<T>::value, T> cast ( object &&  object)

Definition at line 1282 of file cast.h.

◆ cast() [7/8]

template<typename T >
detail::enable_if_t<detail::is_pyobject<T>::value, T> cast ( object &&  object)

Definition at line 1288 of file cast.h.

◆ cast() [8/8]

template<typename T , detail::enable_if_t<!detail::is_pyobject< T >::value, int > = 0>
object cast ( T &&  value,
return_value_policy  policy = return_value_policy::automatic_reference,
handle  parent = handle() 
)

Definition at line 1216 of file cast.h.

◆ cast_error_unable_to_convert_call_arg()

cast_error cast_error_unable_to_convert_call_arg ( const std::string &  name,
const std::string &  type 
)
inline

Definition at line 1375 of file cast.h.

◆ cast_op() [1/2]

template<typename T >
make_caster<T>::template cast_op_type<typename std::add_rvalue_reference<T>::type> cast_op ( make_caster< T > &&  caster)

Definition at line 50 of file cast.h.

◆ cast_op() [2/2]

template<typename T >
make_caster<T>::template cast_op_type<T> cast_op ( make_caster< T > &  caster)

Definition at line 44 of file cast.h.

◆ cast_ref() [1/2]

template<typename T >
enable_if_t<!cast_is_temporary_value_reference<T>::value, T> cast_ref ( object &&  ,
override_unused  
)

Definition at line 1333 of file cast.h.

◆ cast_ref() [2/2]

template<typename T >
enable_if_t<cast_is_temporary_value_reference<T>::value, T> cast_ref ( object &&  o,
make_caster< T > &  caster 
)

Definition at line 1328 of file cast.h.

◆ cast_safe() [1/4]

template<typename T >
enable_if_t<cast_is_temporary_value_reference<T>::value && !detail::is_same_ignoring_cvref<T, PyObject *>::value, T> cast_safe ( object &&  )

Definition at line 1345 of file cast.h.

◆ cast_safe() [2/4]

template<typename T >
enable_if_t<std::is_void<T>::value, void> cast_safe ( object &&  )

Definition at line 1349 of file cast.h.

◆ cast_safe() [3/4]

template<typename T >
enable_if_t<detail::is_same_ignoring_cvref<T, PyObject *>::value, PyObject *> cast_safe ( object &&  o)

Definition at line 1352 of file cast.h.

◆ cast_safe() [4/4]

template<typename T >
enable_if_t<detail::none_of<cast_is_temporary_value_reference<T>, detail::is_same_ignoring_cvref<T, PyObject *>, std::is_void<T> >::value, T> cast_safe ( object &&  o)

Definition at line 1360 of file cast.h.

◆ collect_arguments() [1/2]

template<return_value_policy policy, typename... Args, typename = enable_if_t<args_are_all_positional<Args...>()>>
simple_collector<policy> collect_arguments ( Args &&...  args)

Collect only positional arguments for a Python function call.

Definition at line 1789 of file cast.h.

◆ collect_arguments() [2/2]

template<return_value_policy policy, typename... Args, typename = enable_if_t<!args_are_all_positional<Args...>()>>
unpacking_collector<policy> collect_arguments ( Args &&...  args)

Collect all arguments, including keywords and unpacking (only instantiated when needed)

Definition at line 1797 of file cast.h.

◆ load_type() [1/2]

template<typename T >
make_caster<T> load_type ( const handle handle)

Definition at line 1159 of file cast.h.

◆ load_type() [2/2]

template<typename T , typename SFINAE >
type_caster<T, SFINAE>& load_type ( type_caster< T, SFINAE > &  conv,
const handle handle 
)

Definition at line 1139 of file cast.h.

◆ make_tuple() [1/2]

template<return_value_policy policy = return_value_policy::automatic_reference>
tuple make_tuple ( )

Definition at line 1383 of file cast.h.

◆ make_tuple() [2/2]

template<return_value_policy policy = return_value_policy::automatic_reference, typename... Args>
tuple make_tuple ( Args &&...  args_)

Definition at line 1388 of file cast.h.

◆ move()

template<typename T >
detail::enable_if_t<!detail::move_never<T>::value, T> move ( object &&  obj)

Definition at line 1243 of file cast.h.

◆ object_or_cast()

template<typename T , enable_if_t<!is_pyobject< T >::value, int > >
object object_or_cast ( T &&  o)

Definition at line 1313 of file cast.h.

name
Annotation for function names.
Definition: attr.h:51
cast
T cast(const handle &handle)
Definition: cast.h:1173
gtsam.examples.DogLegOptimizerExample.type
type
Definition: DogLegOptimizerExample.py:111
return_value_policy
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
Definition: wrap/pybind11/include/pybind11/detail/common.h:499
detail
Definition: testSerializationNonlinear.cpp:70
PYBIND11_NAMESPACE_BEGIN
#define PYBIND11_NAMESPACE_BEGIN(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:76
h
const double h
Definition: testSimpleHelicopter.cpp:19
always_construct_holder
Definition: cast.h:860
type_caster
Definition: cast.h:38
PYBIND11_NAMESPACE
Definition: test_custom_type_casters.cpp:24
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 > cast_op_type
Definition: type_caster_base.h:841
type_caster_holder
conditional_t< is_copy_constructible< holder_type >::value, copyable_holder_caster< type, holder_type >, move_only_holder_caster< type, holder_type > > type_caster_holder
Definition: cast.h:857
enable_if_t
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
Definition: wrap/pybind11/include/pybind11/detail/common.h:654
test_callbacks.value
value
Definition: test_callbacks.py:160
type_caster_base
Generic type caster for objects stored on the heap.
Definition: type_caster_base.h:1096


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:18:28