mirror of
https://github.com/RYDE-WORK/pybind11.git
synced 2026-01-30 11:13:30 +08:00
added a pybind11::none class
This commit is contained in:
parent
9b880ba743
commit
18fb3e323a
@ -212,7 +212,7 @@ private:
|
|||||||
ssize_t pos = 0;
|
ssize_t pos = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool iterable_check(PyObject *obj) {
|
inline bool PyIterable_Check(PyObject *obj) {
|
||||||
PyObject *iter = PyObject_GetIter(obj);
|
PyObject *iter = PyObject_GetIter(obj);
|
||||||
if (iter) {
|
if (iter) {
|
||||||
Py_DECREF(iter);
|
Py_DECREF(iter);
|
||||||
@ -222,8 +222,10 @@ inline bool iterable_check(PyObject *obj) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NAMESPACE_END(detail)
|
|
||||||
|
|
||||||
|
inline bool PyNone_Check(PyObject *o) { return o == Py_None; }
|
||||||
|
|
||||||
|
NAMESPACE_END(detail)
|
||||||
|
|
||||||
#define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, CvtStmt) \
|
#define PYBIND11_OBJECT_CVT(Name, Parent, CheckFun, CvtStmt) \
|
||||||
Name(const handle &h, bool borrowed) : Parent(h, borrowed) { CvtStmt; } \
|
Name(const handle &h, bool borrowed) : Parent(h, borrowed) { CvtStmt; } \
|
||||||
@ -261,7 +263,7 @@ private:
|
|||||||
|
|
||||||
class iterable : public object {
|
class iterable : public object {
|
||||||
public:
|
public:
|
||||||
PYBIND11_OBJECT_DEFAULT(iterable, object, detail::iterable_check)
|
PYBIND11_OBJECT_DEFAULT(iterable, object, detail::PyIterable_Check)
|
||||||
};
|
};
|
||||||
|
|
||||||
inline detail::accessor handle::operator[](handle key) const { return detail::accessor(ptr(), key.ptr(), false); }
|
inline detail::accessor handle::operator[](handle key) const { return detail::accessor(ptr(), key.ptr(), false); }
|
||||||
@ -319,6 +321,12 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class none : public object {
|
||||||
|
public:
|
||||||
|
PYBIND11_OBJECT(none, object, detail::PyNone_Check)
|
||||||
|
none() : object(Py_None, true) { }
|
||||||
|
};
|
||||||
|
|
||||||
class bool_ : public object {
|
class bool_ : public object {
|
||||||
public:
|
public:
|
||||||
PYBIND11_OBJECT_DEFAULT(bool_, object, PyBool_Check)
|
PYBIND11_OBJECT_DEFAULT(bool_, object, PyBool_Check)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user