本文整理汇总了C++中PythonObject::IsValid方法的典型用法代码示例。如果您正苦于以下问题:C++ PythonObject::IsValid方法的具体用法?C++ PythonObject::IsValid怎么用?C++ PythonObject::IsValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PythonObject
的用法示例。
在下文中一共展示了PythonObject::IsValid方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AppendItem
void PythonList::AppendItem(const PythonObject &object) {
if (IsAllocated() && object.IsValid()) {
// `PyList_Append` does *not* steal a reference, so do not call `Py_INCREF`
// here like we do with `PyList_SetItem`.
PyList_Append(m_py_obj, object.get());
}
}
示例2: PythonObject
PythonObject
PythonDictionary::GetItemForKey(const PythonObject &key) const
{
if (IsAllocated() && key.IsValid())
return PythonObject(PyRefType::Borrowed, PyDict_GetItem(m_py_obj, key.get()));
return PythonObject();
}
示例3: SetItemAtIndex
void PythonTuple::SetItemAtIndex(uint32_t index, const PythonObject &object) {
if (IsAllocated() && object.IsValid()) {
// PyTuple_SetItem is documented to "steal" a reference, so we need to
// convert it to an owned reference by incrementing it.
Py_INCREF(object.get());
PyTuple_SetItem(m_py_obj, index, object.get());
}
}
示例4: SetItemForKey
void PythonDictionary::SetItemForKey(const PythonObject &key,
const PythonObject &value) {
if (IsAllocated() && key.IsValid() && value.IsValid())
PyDict_SetItem(m_py_obj, key.get(), value.get());
}