本文整理汇总了C++中Datum::getFloat方法的典型用法代码示例。如果您正苦于以下问题:C++ Datum::getFloat方法的具体用法?C++ Datum::getFloat怎么用?C++ Datum::getFloat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Datum
的用法示例。
在下文中一共展示了Datum::getFloat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getNumber
Datum ComponentRegistry::getNumber(std::string expression, GenericDataType type){
Datum value;
switch(type){
case M_FLOAT:
case M_INTEGER:
case M_BOOLEAN:
case M_STRING:
value = getValue(expression, type);
if (value.getDataType() == type) {
return value;
}
break;
default:
throw FatalParserException("Attempt to cast a number of invalid type");
}
switch (type){
case M_FLOAT:
return Datum(value.getFloat());
case M_INTEGER:
return Datum(value.getInteger());
case M_STRING:
return Datum(value.getString());
case M_BOOLEAN:
return Datum(value.getBool());
default:
return value;
}
}
示例2: srg
boost::python::object convert_datum_to_python(const Datum &datum) {
ScopedRecursionGuard srg(" while converting MWorks datum to Python object");
if (datum.isUndefined()) {
return boost::python::object();
}
switch (datum.getDataType()) {
case M_INTEGER:
return convert_longlong_to_python(datum.getInteger());
case M_FLOAT:
return manageNewRef( PyFloat_FromDouble(datum.getFloat()) );
case M_BOOLEAN:
return manageNewRef( PyBool_FromLong(datum.getBool()) );
case M_STRING: {
auto &str = datum.getString();
return manageNewRef( PyString_FromStringAndSize(str.c_str(), str.size()) );
}
case M_LIST: {
auto &listValue = datum.getList();
boost::python::object list = manageNewRef( PyList_New(listValue.size()) );
for (Py_ssize_t i = 0; i < listValue.size(); i++) {
boost::python::object item = convert_datum_to_python(listValue.at(i));
// PyList_SetItem "steals" the item reference, so we need to INCREF it
Py_INCREF(item.ptr());
if (PyList_SetItem(list.ptr(), i, item.ptr()))
throw_error_already_set();
}
return list;
}
case M_DICTIONARY: {
boost::python::object dict = manageNewRef( PyDict_New() );
for (auto &item : datum.getDict()) {
if (PyDict_SetItem(dict.ptr(),
convert_datum_to_python(item.first).ptr(),
convert_datum_to_python(item.second).ptr()))
{
throw_error_already_set();
}
}
return dict;
}
default:
PyErr_Format(PyExc_TypeError, "Cannot convert Datum of unknown type (%d)", datum.getDataType());
throw_error_already_set();
return boost::python::object(); // Never reached
}
}