本文整理汇总了C++中Datum::getType方法的典型用法代码示例。如果您正苦于以下问题:C++ Datum::getType方法的具体用法?C++ Datum::getType怎么用?C++ Datum::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Datum
的用法示例。
在下文中一共展示了Datum::getType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setAttr
void NodeProxy::setAttr(std::string name, object obj)
{
if (!settable)
throw proxy::ProxyException("Cannot set datum value.");
Datum* datum = node->getDatum(QString::fromStdString(name));
if (!datum)
throw proxy::ProxyException("Nonexistent datum lookup.");
if (obj.ptr()->ob_type != datum->getType())
throw proxy::ProxyException("Invalid type.");
auto e = dynamic_cast<EvalDatum*>(datum);
if (!e)
throw proxy::ProxyException("Datum must be an EvalDatum");
// Make sure that the existing expression can be directly coerced into
// a value of the desired type. This is so that assigning x when
// x equals "12.0" works, but assigning x when x = "po.y" fails.
auto o = PyObject_CallFunction((PyObject*)datum->getType(), "s",
e->getExpr().toStdString().c_str());
if (!o)
{
PyErr_Clear();
return;
}
Py_DECREF(o);
auto txt = QString::fromStdString(extract<std::string>(str(obj))());
// Special case: use QString::number to sanely trim the number of decimal
// places that are printed for float values.
if (datum->getType() == &PyFloat_Type)
txt = QString::number(txt.toFloat());
e->setExpr(txt);
}