knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::py::python_optional< T > Struct Template Reference

#include <optional.h>

Inheritance diagram for knowrob::py::python_optional< T >:
Collaboration diagram for knowrob::py::python_optional< T >:

Classes

struct  conversion
 

Public Member Functions

 python_optional ()
 
 python_optional ()
 

Static Public Member Functions

static void * convertible (PyObject *obj)
 
static void constructor (PyObject *obj, boost::python::converter::rvalue_from_python_stage1_data *data)
 
static void * convertible (PyObject *obj)
 
static void constructor (PyObject *obj, boost::python::converter::rvalue_from_python_stage1_data *data)
 

Detailed Description

template<typename T>
struct knowrob::py::python_optional< T >

handling of std::optional, map no-value to None in Python.

Definition at line 15 of file optional.h.

Constructor & Destructor Documentation

◆ python_optional() [1/2]

template<typename T >
knowrob::py::python_optional< T >::python_optional ( )
inlineexplicit

Definition at line 45 of file optional.h.

45  {
46  using namespace boost::python;
47  if (!extract<std::optional<T> >(object()).check()) {
48  to_python_converter<std::optional<T>, conversion, true>();
49  converter::registry::push_back(
50  &convertible,
51  &constructor,
52  type_id<std::optional<T> >(),
53  &conversion::get_pytype
54  );
55  }
56  }
static void * convertible(PyObject *obj)
Definition: optional.h:23
static void constructor(PyObject *obj, boost::python::converter::rvalue_from_python_stage1_data *data)
Definition: optional.h:28

◆ python_optional() [2/2]

template<typename T >
knowrob::py::python_optional< T >::python_optional ( )
inlineexplicit

Definition at line 45 of file optional.h.

45  {
46  using namespace boost::python;
47  if (!extract<std::optional<T> >(object()).check()) {
48  to_python_converter<std::optional<T>, conversion, true>();
49  converter::registry::push_back(
50  &convertible,
51  &constructor,
52  type_id<std::optional<T> >(),
53  &conversion::get_pytype
54  );
55  }
56  }

Member Function Documentation

◆ constructor() [1/2]

template<typename T >
static void knowrob::py::python_optional< T >::constructor ( PyObject *  obj,
boost::python::converter::rvalue_from_python_stage1_data *  data 
)
inlinestatic

Definition at line 28 of file optional.h.

31  {
32  using namespace boost::python;
33  void *const storage =
34  reinterpret_cast<
35  converter::rvalue_from_python_storage<std::optional<T> > *
36  >(data)->storage.bytes;
37  if (obj == Py_None) {
38  new(storage) std::optional<T>();
39  } else {
40  new(storage) std::optional<T>(extract<T>(obj));
41  }
42  data->convertible = storage;
43  }

◆ constructor() [2/2]

template<typename T >
static void knowrob::py::python_optional< T >::constructor ( PyObject *  obj,
boost::python::converter::rvalue_from_python_stage1_data *  data 
)
inlinestatic

Definition at line 28 of file optional.h.

31  {
32  using namespace boost::python;
33  void *const storage =
34  reinterpret_cast<
35  converter::rvalue_from_python_storage<std::optional<T> > *
36  >(data)->storage.bytes;
37  if (obj == Py_None) {
38  new(storage) std::optional<T>();
39  } else {
40  new(storage) std::optional<T>(extract<T>(obj));
41  }
42  data->convertible = storage;
43  }

◆ convertible() [1/2]

template<typename T >
static void* knowrob::py::python_optional< T >::convertible ( PyObject *  obj)
inlinestatic

Definition at line 23 of file optional.h.

23  {
24  using namespace boost::python;
25  return obj == Py_None || extract<T>(obj).check() ? obj : NULL;
26  }

◆ convertible() [2/2]

template<typename T >
static void* knowrob::py::python_optional< T >::convertible ( PyObject *  obj)
inlinestatic

Definition at line 23 of file optional.h.

23  {
24  using namespace boost::python;
25  return obj == Py_None || extract<T>(obj).check() ? obj : NULL;
26  }

The documentation for this struct was generated from the following file: