cppyabm
1.0.17
An agent-based library to integrate C++ and Python
|
|
Go to the documentation of this file.
12 #define PYBIND11_VERSION_MAJOR 2
13 #define PYBIND11_VERSION_MINOR 6
14 #define PYBIND11_VERSION_PATCH 3.dev1
16 #define PYBIND11_NAMESPACE_BEGIN(name) namespace name {
17 #define PYBIND11_NAMESPACE_END(name) }
22 #if !defined(PYBIND11_NAMESPACE)
24 # define PYBIND11_NAMESPACE pybind11 __attribute__((visibility("hidden")))
26 # define PYBIND11_NAMESPACE pybind11
30 #if !(defined(_MSC_VER) && __cplusplus == 199711L)
31 # if __cplusplus >= 201402L
32 # define PYBIND11_CPP14
33 # if __cplusplus >= 201703L
34 # define PYBIND11_CPP17
37 #elif defined(_MSC_VER) && __cplusplus == 199711L
40 # if _MSVC_LANG >= 201402L
41 # define PYBIND11_CPP14
42 # if _MSVC_LANG > 201402L && _MSC_VER >= 1910
43 # define PYBIND11_CPP17
49 #if defined(__INTEL_COMPILER)
50 # if __INTEL_COMPILER < 1800
51 # error pybind11 requires Intel C++ compiler v18 or newer
52 # elif __INTEL_COMPILER < 1900 && defined(PYBIND11_CPP14)
53 # error pybind11 supports only C++11 with Intel C++ compiler v18. Use v19 or newer for C++14.
55 #elif defined(__clang__) && !defined(__apple_build_version__)
56 # if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 3)
57 # error pybind11 requires clang 3.3 or newer
59 #elif defined(__clang__)
62 # if __clang_major__ < 5
63 # error pybind11 requires Xcode/clang 5.0 or newer
65 #elif defined(__GNUG__)
66 # if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
67 # error pybind11 requires gcc 4.8 or newer
69 #elif defined(_MSC_VER)
72 # if _MSC_FULL_VER < 190024210
73 # error pybind11 requires MSVC 2015 update 3 or newer
77 #if !defined(PYBIND11_EXPORT)
78 # if defined(WIN32) || defined(_WIN32)
79 # define PYBIND11_EXPORT __declspec(dllexport)
81 # define PYBIND11_EXPORT __attribute__ ((visibility("default")))
86 # define PYBIND11_NOINLINE __declspec(noinline)
88 # define PYBIND11_NOINLINE __attribute__ ((noinline))
91 #if defined(PYBIND11_CPP14)
92 # define PYBIND11_DEPRECATED(reason) [[deprecated(reason)]]
94 # define PYBIND11_DEPRECATED(reason) __attribute__((deprecated(reason)))
97 #if defined(PYBIND11_CPP17)
98 # define PYBIND11_MAYBE_UNUSED [[maybe_unused]]
99 #elif defined(_MSC_VER) && !defined(__clang__)
100 # define PYBIND11_MAYBE_UNUSED
102 # define PYBIND11_MAYBE_UNUSED __attribute__ ((__unused__))
107 #if defined(_MSC_VER) && _MSC_VER >= 1900
108 # define HAVE_SNPRINTF 1
112 #if defined(_MSC_VER)
113 # if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 4)
114 # define HAVE_ROUND 1
116 # pragma warning(push)
117 # pragma warning(disable: 4510 4610 4512 4005)
118 # if defined(_DEBUG) && !defined(Py_DEBUG)
119 # define PYBIND11_DEBUG_MARKER
125 #include <frameobject.h>
126 #include <pythread.h>
141 #if defined(copysign)
145 #if defined(_MSC_VER)
146 # if defined(PYBIND11_DEBUG_MARKER)
148 # undef PYBIND11_DEBUG_MARKER
150 # pragma warning(pop)
155 #include <forward_list>
160 #include <unordered_set>
161 #include <unordered_map>
164 #include <type_traits>
165 #if defined(__has_include)
166 # if __has_include(<version>)
184 #if PY_MAJOR_VERSION >= 3
185 #define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyInstanceMethod_New(ptr)
186 #define PYBIND11_INSTANCE_METHOD_CHECK PyInstanceMethod_Check
187 #define PYBIND11_INSTANCE_METHOD_GET_FUNCTION PyInstanceMethod_GET_FUNCTION
188 #define PYBIND11_BYTES_CHECK PyBytes_Check
189 #define PYBIND11_BYTES_FROM_STRING PyBytes_FromString
190 #define PYBIND11_BYTES_FROM_STRING_AND_SIZE PyBytes_FromStringAndSize
191 #define PYBIND11_BYTES_AS_STRING_AND_SIZE PyBytes_AsStringAndSize
192 #define PYBIND11_BYTES_AS_STRING PyBytes_AsString
193 #define PYBIND11_BYTES_SIZE PyBytes_Size
194 #define PYBIND11_LONG_CHECK(o) PyLong_Check(o)
195 #define PYBIND11_LONG_AS_LONGLONG(o) PyLong_AsLongLong(o)
196 #define PYBIND11_LONG_FROM_SIGNED(o) PyLong_FromSsize_t((ssize_t) o)
197 #define PYBIND11_LONG_FROM_UNSIGNED(o) PyLong_FromSize_t((size_t) o)
198 #define PYBIND11_BYTES_NAME "bytes"
199 #define PYBIND11_STRING_NAME "str"
200 #define PYBIND11_SLICE_OBJECT PyObject
201 #define PYBIND11_FROM_STRING PyUnicode_FromString
202 #define PYBIND11_STR_TYPE ::pybind11::str
203 #define PYBIND11_BOOL_ATTR "__bool__"
204 #define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_bool)
205 #define PYBIND11_BUILTINS_MODULE "builtins"
208 #define PYBIND11_PLUGIN_IMPL(name) \
209 extern "C" PYBIND11_MAYBE_UNUSED PYBIND11_EXPORT PyObject *PyInit_##name(); \
210 extern "C" PYBIND11_EXPORT PyObject *PyInit_##name()
213 #define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyMethod_New(ptr, nullptr, class_)
214 #define PYBIND11_INSTANCE_METHOD_CHECK PyMethod_Check
215 #define PYBIND11_INSTANCE_METHOD_GET_FUNCTION PyMethod_GET_FUNCTION
216 #define PYBIND11_BYTES_CHECK PyString_Check
217 #define PYBIND11_BYTES_FROM_STRING PyString_FromString
218 #define PYBIND11_BYTES_FROM_STRING_AND_SIZE PyString_FromStringAndSize
219 #define PYBIND11_BYTES_AS_STRING_AND_SIZE PyString_AsStringAndSize
220 #define PYBIND11_BYTES_AS_STRING PyString_AsString
221 #define PYBIND11_BYTES_SIZE PyString_Size
222 #define PYBIND11_LONG_CHECK(o) (PyInt_Check(o) || PyLong_Check(o))
223 #define PYBIND11_LONG_AS_LONGLONG(o) (PyInt_Check(o) ? (long long) PyLong_AsLong(o) : PyLong_AsLongLong(o))
224 #define PYBIND11_LONG_FROM_SIGNED(o) PyInt_FromSsize_t((ssize_t) o) // Returns long if needed.
225 #define PYBIND11_LONG_FROM_UNSIGNED(o) PyInt_FromSize_t((size_t) o) // Returns long if needed.
226 #define PYBIND11_BYTES_NAME "str"
227 #define PYBIND11_STRING_NAME "unicode"
228 #define PYBIND11_SLICE_OBJECT PySliceObject
229 #define PYBIND11_FROM_STRING PyString_FromString
230 #define PYBIND11_STR_TYPE ::pybind11::bytes
231 #define PYBIND11_BOOL_ATTR "__nonzero__"
232 #define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_nonzero)
233 #define PYBIND11_BUILTINS_MODULE "__builtin__"
236 #define PYBIND11_PLUGIN_IMPL(name) \
237 static PyObject *pybind11_init_wrapper(); \
238 extern "C" PYBIND11_MAYBE_UNUSED PYBIND11_EXPORT void init##name(); \
239 extern "C" PYBIND11_EXPORT void init##name() { \
240 (void)pybind11_init_wrapper(); \
242 PyObject *pybind11_init_wrapper()
245 #if PY_VERSION_HEX >= 0x03050000 && PY_VERSION_HEX < 0x03050200
247 struct _Py_atomic_address {
void *
value; };
248 PyAPI_DATA(_Py_atomic_address) _PyThreadState_Current;
252 #define PYBIND11_TRY_NEXT_OVERLOAD ((PyObject *) 1) // special failure return code
253 #define PYBIND11_STRINGIFY(x) #x
254 #define PYBIND11_TOSTRING(x) PYBIND11_STRINGIFY(x)
255 #define PYBIND11_CONCAT(first, second) first##second
256 #define PYBIND11_ENSURE_INTERNALS_READY \
257 pybind11::detail::get_internals();
259 #define PYBIND11_CHECK_PYTHON_VERSION \
261 const char *compiled_ver = PYBIND11_TOSTRING(PY_MAJOR_VERSION) \
262 "." PYBIND11_TOSTRING(PY_MINOR_VERSION); \
263 const char *runtime_ver = Py_GetVersion(); \
264 size_t len = std::strlen(compiled_ver); \
265 if (std::strncmp(runtime_ver, compiled_ver, len) != 0 \
266 || (runtime_ver[len] >= '0' && runtime_ver[len] <= '9')) { \
267 PyErr_Format(PyExc_ImportError, \
268 "Python version mismatch: module was compiled for Python %s, " \
269 "but the interpreter version is incompatible: %s.", \
270 compiled_ver, runtime_ver); \
275 #define PYBIND11_CATCH_INIT_EXCEPTIONS \
276 catch (pybind11::error_already_set &e) { \
277 PyErr_SetString(PyExc_ImportError, e.what()); \
279 } catch (const std::exception &e) { \
280 PyErr_SetString(PyExc_ImportError, e.what()); \
299 #define PYBIND11_PLUGIN(name) \
300 PYBIND11_DEPRECATED("PYBIND11_PLUGIN is deprecated, use PYBIND11_MODULE") \
301 static PyObject *pybind11_init(); \
302 PYBIND11_PLUGIN_IMPL(name) { \
303 PYBIND11_CHECK_PYTHON_VERSION \
304 PYBIND11_ENSURE_INTERNALS_READY \
306 return pybind11_init(); \
307 } PYBIND11_CATCH_INIT_EXCEPTIONS \
309 PyObject *pybind11_init()
332 #define PYBIND11_MODULE(name, variable) \
333 static ::pybind11::module_::module_def \
334 PYBIND11_CONCAT(pybind11_module_def_, name) PYBIND11_MAYBE_UNUSED; \
335 PYBIND11_MAYBE_UNUSED \
336 static void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ &); \
337 PYBIND11_PLUGIN_IMPL(name) { \
338 PYBIND11_CHECK_PYTHON_VERSION \
339 PYBIND11_ENSURE_INTERNALS_READY \
340 auto m = ::pybind11::module_::create_extension_module( \
341 PYBIND11_TOSTRING(name), nullptr, \
342 &PYBIND11_CONCAT(pybind11_module_def_, name)); \
344 PYBIND11_CONCAT(pybind11_init_, name)(m); \
346 } PYBIND11_CATCH_INIT_EXCEPTIONS \
348 void PYBIND11_CONCAT(pybind11_init_, name)(::pybind11::module_ &variable)
354 using
size_t = std::
size_t;
410 inline static constexpr
int log2(
size_t n,
int k = 0) {
return (n <= 1) ? k : log2(n >> 1, k + 1); }
413 inline static constexpr
size_t size_in_ptrs(
size_t s) {
return 1 + ((s - 1) >> log2(
sizeof(
void *))); }
422 static_assert(
sizeof(std::shared_ptr<int>) >=
sizeof(std::unique_ptr<int>),
423 "pybind assumes std::shared_ptrs are at least as big as std::unique_ptrs");
424 return size_in_ptrs(
sizeof(std::shared_ptr<int>));
498 #if defined(PYBIND11_CPP14) && (!defined(_MSC_VER) || _MSC_VER >= 1910)
504 template <
bool B,
typename T =
void>
using enable_if_t =
typename std::enable_if<B, T>::type;
505 template <
bool B,
typename T,
typename F>
using conditional_t =
typename std::conditional<B, T, F>::type;
506 template <
typename T>
using remove_cv_t =
typename std::remove_cv<T>::type;
511 #if defined(PYBIND11_CPP14)
512 using std::index_sequence;
524 :
select_indices_impl<conditional_t<B, index_sequence<IPrev..., I>, index_sequence<IPrev...>>, I + 1, Bs...> {};
534 #if defined(__PGIC__) || defined(__INTEL_COMPILER)
535 template<
typename... >
using void_t = void;
543 #if defined(__cpp_fold_expressions) && !(defined(_MSC_VER) && (_MSC_VER < 1916))
546 #elif !defined(_MSC_VER)
548 template <
class... Ts>
using all_of = std::is_same<
555 template <
class... Ts>
using all_of = std::conjunction<Ts...>;
556 template <
class... Ts>
using any_of = std::disjunction<Ts...>;
566 template <
typename C,
typename R,
typename...
A>
struct remove_class<R (C::*)(A...)> {
using type = R (
A...); };
567 template <
typename C,
typename R,
typename...
A>
struct remove_class<R (C::*)(A...) const> {
using type = R (
A...); };
586 #ifdef __cpp_fold_expressions
587 template <
typename... Ts> constexpr
size_t constexpr_sum(Ts... ns) {
return (0 + ... +
size_t{ns}); }
590 template <
typename T,
typename... Ts>
597 template <
typename T,
typename... Ts>
598 constexpr
int first(
int i, T v, Ts... vs) {
return v ?
i :
first(
i + 1, vs...); }
600 constexpr
int last(
int ,
int result) {
return result; }
601 template <
typename T,
typename... Ts>
602 constexpr
int last(
int i,
int result, T v, Ts... vs) {
return last(
i + 1, v ?
i : result, vs...); }
607 template <
template<
typename>
class Predicate,
typename... Ts>
611 template <
template<
typename>
class Predicate,
typename... Ts>
615 template <
size_t N,
typename T,
typename... Ts>
617 template <
typename T,
typename... Ts>
622 template <
template<
typename>
class Predicate,
typename Default,
typename... Ts>
625 static_assert(
found <= 1,
"Found more than one type matching the predicate");
630 template <
template<
typename>
class P,
typename Default>
633 template <
template<
typename>
class Predicate,
typename Default,
typename... Ts>
651 template <
template<
typename...>
class Base>
659 template <
template<
typename...>
class Base,
typename T>
660 #if !defined(_MSC_VER)
662 #else // MSVC2015 has trouble with decltype in template aliases
663 struct is_template_base_of : decltype(is_template_base_of_impl<Base>::check((intrinsic_t<T>*)nullptr)) { };
668 template <
template<
typename...>
class Class,
typename T>
670 template <
template<
typename...>
class Class,
typename... Us>
678 template <
typename T>
694 template <
typename Function,
typename F = remove_reference_t<Function>>
700 std::remove_pointer<F>,
709 std::is_function, std::is_pointer, std::is_member_pointer>;
716 #if defined(__cpp_fold_expressions) && !defined(__INTEL_COMPILER)
718 #define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) (((PATTERN), void()), ...)
721 #define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) (void)pybind11::detail::expand_side_effects{ ((PATTERN), void(), false)..., false }
729 using std::runtime_error::runtime_error;
734 #define PYBIND11_RUNTIME_EXCEPTION(name, type) \
735 class name : public builtin_exception { public: \
736 using builtin_exception::builtin_exception; \
737 name() : name("") { } \
738 void set_error() const override { PyErr_SetString(type, what()); } \
762 template <typename T, typename SFINAE =
void> struct
is_fmt_numeric {
static constexpr
bool value =
false; };
772 static constexpr
const char c =
"?bBhHiIqQfdg"[detail::is_fmt_numeric<T>::index];
773 static constexpr
const char value[2] = { c,
'\0' };
774 static std::string
format() {
return std::string(1, c); }
777 #if !defined(PYBIND11_CPP17)
795 template <
typename... Args>
799 template <
typename Return>
800 constexpr
auto operator()(Return (*pf)(Args...)) const noexcept
801 -> decltype(pf) {
return pf; }
803 template <
typename Return,
typename Class>
804 constexpr
auto operator()(Return (Class::*pmf)(Args...), std::false_type = {}) const noexcept
805 -> decltype(pmf) {
return pmf; }
807 template <
typename Return,
typename Class>
808 constexpr
auto operator()(Return (Class::*pmf)(Args...)
const, std::true_type)
const noexcept
809 -> decltype(pmf) {
return pmf; }
814 #if defined(PYBIND11_CPP14)
815 #define PYBIND11_OVERLOAD_CAST 1
819 template <
typename... Args>
820 static constexpr detail::overload_cast_impl<Args...>
overload_cast = {};
827 static constexpr
auto const_ = std::true_type{};
829 #if !defined(PYBIND11_CPP14) // no overload_cast: providing something that static_assert-fails:
832 "pybind11::overload_cast<...> requires compiling in C++14 mode");
834 #endif // overload_cast
841 template <
typename T>
852 template <typename Container, typename = enable_if_t<std::is_convertible<decltype(*std::begin(std::declval<const Container &>())), T>
::value>>
864 operator std::vector<T> &&() && {
return std::move(v); }
878 template <
typename T>
879 inline static std::shared_ptr<T> try_get_shared_from_this(std::enable_shared_from_this<T> *holder_value_ptr) {
884 #if defined(__cpp_lib_enable_shared_from_this) && (!defined(_MSC_VER) || _MSC_VER >= 1912)
885 return holder_value_ptr->weak_from_this().lock();
888 return holder_value_ptr->shared_from_this();
890 catch (
const std::bad_weak_ptr &) {
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
#define PYBIND11_RUNTIME_EXCEPTION(name, type)
RAII wrapper that temporarily clears any Python error state.
Return the Nth element from the parameter pack.
#define PYBIND11_NAMESPACE_BEGIN(name)
bool_constant< std::is_pointer< T >::value &&std::is_function< typename std::remove_pointer< T >::type >::value > is_function_pointer
typename remove_class< decltype(&F::operator())>::type type
typename deferred_type< T, Us... >::type deferred_t
#define PYBIND11_NAMESPACE_END(name)
void ignore_unused(const int *)
Ignore that a variable is unused in compiler warnings.
Helper template to strip away type modifiers.
#define PYBIND11_NAMESPACE
nonsimple_values_and_holders nonsimple
static constexpr auto found
const std::vector< T > * operator->() const
value_and_holder get_value_and_holder(const type_info *find_type=nullptr, bool throw_if_missing=true)
static constexpr uint8_t status_instance_registered
any_container(It first, It last)
bool_constant<(std::is_same< Base, Derived >::value||std::is_base_of< Base, Derived >::value) &&std::is_convertible< Derived *, Base * >::value > is_accessible_base_of
all_of< Predicates< T >... > satisfies_all_of
Strip the class from a method type.
typename void_t_impl< Ts... >::type void_t
#define PYBIND11_NOINLINE
std::integral_constant< bool, B > bool_constant
Backports of std::bool_constant and std::negation to accommodate older compilers.
std::is_same< bools< Ts::value..., true >, bools< true, Ts::value... > > all_of
Compile-time all/any/none of that check the boolean value of all template types.
constexpr size_t constexpr_sum()
Compile-time integer sum.
void ** values_and_holders
void * simple_value_holder[1+instance_simple_holder_in_ptrs()]
constexpr overload_cast_impl()
std::vector< T > * operator->()
typename std::conditional< B, T, F >::type conditional_t
void allocate_layout()
Initializes all of the above type/values/holders data (but not the instance values themselves)
typename std::remove_reference< T >::type remove_reference_t
Helper template which holds a list of types.
virtual void set_error() const =0
Set the error using the Python C API.
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
static std::false_type check(...)
conditional_t< found, typename pack_element< index, Ts... >::type, Default > type
std::string get_fully_qualified_tp_name(PyTypeObject *)
static constexpr bool value
any_container(const Container &c)
bool_constant< std::is_base_of< Base, Derived >::value &&!std::is_same< Base, Derived >::value > is_strict_base_of
typename pack_element< N - 1, Ts... >::type type
bool simple_instance_registered
For simple layout, tracks whether the instance is registered in registered_instances
void deallocate_layout()
Destroys/deallocates all of the above.
typename intrinsic_type< T >::type intrinsic_t
typename select_indices_impl< index_sequence<>, 0, Bs... >::type select_indices
std::vector< T > & operator*()
constexpr int constexpr_first()
bool has_patients
If true, get_internals().patients has an entry for this object.
const std::vector< T > & operator*() const
static constexpr auto index
bool owned
If true, the pointer is owned which means we're free to manage it with a holder.
constexpr int first(int i)
Implementation details for constexpr functions.
static constexpr uint8_t status_holder_constructed
Bit values for the non-simple status flags.
PyExc_RuntimeError PYBIND11_NOINLINE void pybind11_fail(const char *reason)
Used internally.
Defer the evaluation of type T until types Us are instantiated.
typename exactly_one< Predicate, Default, Ts... >::type exactly_one_t
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
constexpr size_t instance_simple_holder_in_ptrs()
constexpr auto operator()(Return(*pf)(Args...)) const noexcept -> decltype(pf)
bool simple_holder_constructed
For simple layout, tracks whether the holder has been constructed.
typename make_index_sequence_impl< N >::type make_index_sequence
Helper type to replace 'void' in some expressions.
any_container(const std::initializer_list< TIn > &c)
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
PyObject * weakrefs
Weak references.
constexpr int constexpr_last()
Return the index of the last type in Ts which satisfies Predicate<T>, or -1 if none match.
constexpr auto operator()(Return(Class::*pmf)(Args...), std::false_type={}) const noexcept -> decltype(pmf)
Dummy destructor wrapper that can be used to expose classes with a private destructor.
Make an index sequence of the indices of true arguments.
bool[] expand_side_effects
Apply a function over each element of a parameter pack.
constexpr int last(int, int result)
C++ bindings of builtin Python exceptions.
any_container(std::vector< T > &&v)
static std::true_type check(Base< Us... > *)
typename std::remove_cv< T >::type remove_cv_t
conditional_t< std::is_function< F >::value, F, typename conditional_t< std::is_pointer< F >::value||std::is_member_pointer< F >::value, std::remove_pointer< F >, strip_function_object< F > >::type > function_signature_t
constexpr auto operator()(Return(Class::*pmf)(Args...) const, std::true_type) const noexcept -> decltype(pmf)
decltype(is_template_base_of_impl< Base >::check((intrinsic_t< T > *) nullptr)) is_template_base_of