本文整理汇总了C++中Load::setProperty方法的典型用法代码示例。如果您正苦于以下问题:C++ Load::setProperty方法的具体用法?C++ Load::setProperty怎么用?C++ Load::setProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Load
的用法示例。
在下文中一共展示了Load::setProperty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: create
PyObject* Load::create(PyTypeObject* pytype, PyObject* args, PyObject* kwds)
{
try
{
// Pick up the operation
PyObject* oper = PyDict_GetItemString(kwds,"operation");
if (!oper)
throw DataException("missing operation on Load");
if (!PyObject_TypeCheck(oper, Operation::metadata->pythonClass))
throw DataException("load operation must be of type operation");
// Pick up the resource
PyObject* res = PyDict_GetItemString(kwds,"resource");
if (!res)
throw DataException("missing resource on Load");
if (!PyObject_TypeCheck(res, Resource::metadata->pythonClass))
throw DataException("load resource must be of type resource");
// Pick up the quantity
PyObject* q1 = PyDict_GetItemString(kwds,"quantity");
double q2 = q1 ? PythonData(q1).getDouble() : 1.0;
// Pick up the effective dates
DateRange eff;
PyObject* eff_start = PyDict_GetItemString(kwds,"effective_start");
if (eff_start)
{
PythonData d(eff_start);
eff.setStart(d.getDate());
}
PyObject* eff_end = PyDict_GetItemString(kwds,"effective_end");
if (eff_end)
{
PythonData d(eff_end);
eff.setEnd(d.getDate());
}
// Create the load
Load *l = new LoadDefault(
static_cast<Operation*>(oper),
static_cast<Resource*>(res),
q2, eff
);
// Iterate over extra keywords, and set attributes. @todo move this responsibility to the readers...
if (l)
{
PyObject *key, *value;
Py_ssize_t pos = 0;
while (PyDict_Next(kwds, &pos, &key, &value))
{
PythonData field(value);
PyObject* key_utf8 = PyUnicode_AsUTF8String(key);
DataKeyword attr(PyBytes_AsString(key_utf8));
Py_DECREF(key_utf8);
if (!attr.isA(Tags::effective_end) && !attr.isA(Tags::effective_start)
&& !attr.isA(Tags::operation) && !attr.isA(Tags::resource)
&& !attr.isA(Tags::quantity) && !attr.isA(Tags::type)
&& !attr.isA(Tags::action))
{
const MetaFieldBase* fmeta = l->getType().findField(attr.getHash());
if (!fmeta && l->getType().category)
fmeta = l->getType().category->findField(attr.getHash());
if (fmeta)
// Update the attribute
fmeta->setField(l, field);
else
l->setProperty(attr.getName(), value);;
}
};
}
// Return the object
Py_INCREF(l);
return static_cast<PyObject*>(l);
}
catch (...)
{
PythonType::evalException();
return NULL;
}
}