Scarab  v2.9.0
Project 8 C++ Utility Library
Classes | Namespaces | Macros | Typedefs | Functions
pytypes.h File Reference
#include "detail/common.h"
#include "buffer_info.h"
#include <utility>
#include <type_traits>
Include dependency graph for pytypes.h:

Go to the source code of this file.

Classes

class  accessor< Policy >
 
class  pyobject_tag
 Tag and check to identify a class which implements the Python object API. More...
 
class  object_api< Derived >
 
class  handle
 
class  object
 
struct  object::borrowed_t
 
struct  object::stolen_t
 
class  error_already_set
 
class  accessor< Policy >
 
struct  obj_attr
 
struct  str_attr
 
struct  generic_item
 
struct  sequence_item
 
struct  list_item
 
struct  tuple_item
 
class  generic_iterator< Policy >
 STL iterator template used for tuple, list, sequence and dict. More...
 
struct  arrow_proxy< T >
 Quick proxy class needed to implement operator-> for iterators which can't return pointers. More...
 
class  sequence_fast_readonly
 Lightweight iterator policy using just a simple pointer: see PySequence_Fast_ITEMS More...
 
class  sequence_slow_readwrite
 Full read and write access using the sequence protocol: see detail::sequence_accessor More...
 
class  dict_readonly
 Python's dictionary protocol permits this to be a forward iterator. More...
 
class  kwargs_proxy
 
class  args_proxy
 
class  simple_collector< policy >
 
class  unpacking_collector< policy >
 Helper class which collects positional, keyword, * and ** arguments for a Python function call. More...
 
class  iterator
 
class  iterable
 
class  str
 
class  bytes
 
class  none
 
class  bool_
 
class  int_
 
class  float_
 
class  weakref
 
class  slice
 
class  capsule
 
class  tuple
 
class  dict
 
class  sequence
 
class  list
 
class  args
 
class  kwargs
 
class  set
 
class  function
 
class  staticmethod
 
class  buffer
 
class  memoryview
 

Namespaces

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

Macros

#define PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun)
 
#define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, ConvertFun)
 
#define PYBIND11_OBJECT(Name, Parent, CheckFun)
 
#define PYBIND11_OBJECT_DEFAULT(Name, Parent, CheckFun)
 
#define PYBIND11_MATH_OPERATOR_UNARY(op, fn)
 
#define PYBIND11_MATH_OPERATOR_BINARY(op, fn)
 

Typedefs

using obj_attr_accessor = accessor< accessor_policies::obj_attr >
 
using str_attr_accessor = accessor< accessor_policies::str_attr >
 
using item_accessor = accessor< accessor_policies::generic_item >
 
using sequence_accessor = accessor< accessor_policies::sequence_item >
 
using list_accessor = accessor< accessor_policies::list_item >
 
using tuple_accessor = accessor< accessor_policies::tuple_item >
 
template<typename T >
using is_pyobject = std::is_base_of< pyobject_tag, remove_reference_t< T > >
 
using tuple_iterator = generic_iterator< iterator_policies::sequence_fast_readonly >
 
using list_iterator = generic_iterator< iterator_policies::sequence_fast_readonly >
 
using sequence_iterator = generic_iterator< iterator_policies::sequence_slow_readwrite >
 
using dict_iterator = generic_iterator< iterator_policies::dict_readonly >
 
template<typename T >
using is_keyword = std::is_base_of< arg, T >
 Python argument categories (using PEP 448 terms) More...
 
template<typename T >
using is_s_unpacking = std::is_same< args_proxy, T >
 
template<typename T >
using is_ds_unpacking = std::is_same< kwargs_proxy, T >
 
template<typename T >
using is_positional = satisfies_none_of< T, is_keyword, is_s_unpacking, is_ds_unpacking >
 
template<typename T >
using is_keyword_or_ds = satisfies_any_of< T, is_keyword, is_ds_unpacking >
 

Functions

bool isinstance_generic (handle obj, const std::type_info &tp)
 
template<typename T >
reinterpret_borrow (handle h)
 
template<typename T >
reinterpret_steal (handle h)
 
std::string error_string ()
 
template<typename T , detail::enable_if_t< std::is_base_of< object, T >::value, int > = 0>
bool isinstance (handle obj)
 
template<>
bool isinstance< handle > (handle obj)=delete
 
template<>
bool isinstance< object > (handle obj)
 
bool isinstance (handle obj, handle type)
 
bool hasattr (handle obj, handle name)
 
bool hasattr (handle obj, const char *name)
 
void delattr (handle obj, handle name)
 
void delattr (handle obj, const char *name)
 
object getattr (handle obj, handle name)
 
object getattr (handle obj, const char *name)
 
object getattr (handle obj, handle name, handle default_)
 
object getattr (handle obj, const char *name, handle default_)
 
void setattr (handle obj, handle name, handle value)
 
void setattr (handle obj, const char *name, handle value)
 
ssize_t hash (handle obj)
 
handle get_function (handle value)
 
template<typename T , enable_if_t< is_pyobject< T >::value, int > = 0>
auto object_or_cast (T &&o) -> decltype(std::forward< T >(o))
 
template<typename T , enable_if_t<!is_pyobject< T >::value, int > >
object object_or_cast (T &&o)
 
handle object_or_cast (PyObject *ptr)
 
bool PyIterable_Check (PyObject *obj)
 
bool PyNone_Check (PyObject *o)
 
bool PyUnicode_Check_Permissive (PyObject *o)
 
bool PyStaticMethod_Check (PyObject *o)
 
str operator"" _s (const char *s, size_t size)
 
template<typename Unsigned >
Unsigned as_unsigned (PyObject *o)
 
size_t len (handle h)
 
size_t len_hint (handle h)
 
str repr (handle h)
 
iterator iter (handle obj)
 

Macro Definition Documentation

◆ PYBIND11_MATH_OPERATOR_BINARY

#define PYBIND11_MATH_OPERATOR_BINARY (   op,
  fn 
)
Value:
template <typename D> \
object object_api<D>::op(object_api const &other) const { \
object result = reinterpret_steal<object>( \
fn(derived().ptr(), other.derived().ptr())); \
if (!result.ptr()) \
throw error_already_set(); \
return result; \
}

Definition at line 1448 of file pytypes.h.

◆ PYBIND11_MATH_OPERATOR_UNARY

#define PYBIND11_MATH_OPERATOR_UNARY (   op,
  fn 
)
Value:
template <typename D> object object_api<D>::op() const { \
object result = reinterpret_steal<object>(fn(derived().ptr())); \
if (!result.ptr()) \
throw error_already_set(); \
return result; \
}

Definition at line 1440 of file pytypes.h.

◆ PYBIND11_OBJECT

#define PYBIND11_OBJECT (   Name,
  Parent,
  CheckFun 
)
Value:
PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \
/* This is deliberately not 'explicit' to allow implicit conversion from object: */ \
Name(const object &o) : Parent(o) { } \
Name(object &&o) : Parent(std::move(o)) { }
STL namespace.
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
Definition: cast.h:1685
#define PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun)
Definition: pytypes.h:779

Definition at line 801 of file pytypes.h.

◆ PYBIND11_OBJECT_COMMON

#define PYBIND11_OBJECT_COMMON (   Name,
  Parent,
  CheckFun 
)
Value:
public: \
PYBIND11_DEPRECATED("Use reinterpret_borrow<"#Name">() or reinterpret_steal<"#Name">()") \
Name(handle h, bool is_borrowed) : Parent(is_borrowed ? Parent(h, borrowed_t{}) : Parent(h, stolen_t{})) { } \
Name(handle h, borrowed_t) : Parent(h, borrowed_t{}) { } \
Name(handle h, stolen_t) : Parent(h, stolen_t{}) { } \
PYBIND11_DEPRECATED("Use py::isinstance<py::python_type>(obj) instead") \
bool check() const { return m_ptr != nullptr && (bool) CheckFun(m_ptr); } \
static bool check_(handle h) { return h.ptr() != nullptr && CheckFun(h.ptr()); }

Definition at line 779 of file pytypes.h.

◆ PYBIND11_OBJECT_CVT

#define PYBIND11_OBJECT_CVT (   Name,
  Parent,
  CheckFun,
  ConvertFun 
)
Value:
PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun) \
/* This is deliberately not 'explicit' to allow implicit conversion from object: */ \
Name(const object &o) \
: Parent(check_(o) ? o.inc_ref().ptr() : ConvertFun(o.ptr()), stolen_t{}) \
{ if (!m_ptr) throw error_already_set(); } \
Name(object &&o) \
: Parent(check_(o) ? o.release().ptr() : ConvertFun(o.ptr()), stolen_t{}) \
{ if (!m_ptr) throw error_already_set(); } \
template <typename Policy_> \
Name(const ::pybind11::detail::accessor<Policy_> &a) : Name(object(a)) { }
#define PYBIND11_OBJECT_COMMON(Name, Parent, CheckFun)
Definition: pytypes.h:779

Definition at line 789 of file pytypes.h.

◆ PYBIND11_OBJECT_DEFAULT

#define PYBIND11_OBJECT_DEFAULT (   Name,
  Parent,
  CheckFun 
)
Value:
PYBIND11_OBJECT(Name, Parent, CheckFun) \
Name() : Parent() { }
#define PYBIND11_OBJECT(Name, Parent, CheckFun)
Definition: pytypes.h:801

Definition at line 807 of file pytypes.h.