#include <pybind11/pybind11.h>
#include <dictobject.h>
Go to the source code of this file.
Functions | |
py::object | get (const py::dict &dict, const char *key, py::handle default_=py::none(), bool noneIsEmpty=true) |
template<typename T , typename std::enable_if<!std::is_pointer< T >::value, int >::type = 0> | |
T | get_cast (const py::dict &dict, const char *key, T default_, bool noneIsEmpty=true) |
template<typename T , typename std::enable_if< std::is_pointer< T >::value, int >::type = 0> | |
detail::cast_pointer_proxy< typename std::remove_pointer< T >::type > | get_cast (const py::dict &dict, const char *key, T &&default_=NULL) |
template<typename T > | |
bool | try_get (const py::dict &dict, const char *key, T &var) |
template<typename T > | |
bool | try_get (const py::dict &dict, const std::string &key, T &var) |
|
inline |
Get the string-labeled item from the dict and return it as python object. Returns default_ if item not found.
This is designed to work similar to python's dict.get()
dict | python dictionary |
key | key string |
default_ | default value to return if not found. defaults to None. |
noneIsEmpty | set to false to return None values explicitly. If true, None is replaced with default_. |
Definition at line 55 of file pybind_dict_utils.h.
|
inline |
Get the string-labeled item from the dict and return it as converted c++ value. Returns default_ if item not found.
This is designed to work similar to python's dict.get().
A special overload of this function handles pointer types, which are normally not allowed as cast return type.
dict | python dictionary |
key | key string |
default_ | default value to return if not found. |
noneIsEmpty | set to false to return None values explicitly. If true, None is replaced with default_. |
Definition at line 82 of file pybind_dict_utils.h.
|
inline |
Get the string-labeled item from the dict and return it as converted c++ pointer value value. Returns default_ if item not found.
This is designed to work similar to python's dict.get().
The return value is actually a wrapper to make sure the pointer's target does not go out of scope. It has operator overloads to be usable like a regular pointer.
dict | python dictionary |
key | key string |
default_ | default value to return if not found. defaults to NULL. |
Definition at line 155 of file pybind_dict_utils.h.
|
inline |
Get the string-labeled item from the dict, convert it and set it to the var parameter Returns false if item not found.
This is designed to work similar to python's dict.get().
dict | python dictionary | |
key | key string | |
[out] | var | output var ref. not modified if the parameter is not found. |
Definition at line 179 of file pybind_dict_utils.h.
|
inline |
Get the string-labeled item from the dict, convert it and set it to the var parameter Returns false if item not found.
This is designed to work similar to python's dict.get().
dict | python dictionary | |
key | key string | |
[out] | var | output var ref. not modified if the parameter is not found. |
Definition at line 203 of file pybind_dict_utils.h.