本文整理汇总了C++中Datum::getDict方法的典型用法代码示例。如果您正苦于以下问题:C++ Datum::getDict方法的具体用法?C++ Datum::getDict怎么用?C++ Datum::getDict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Datum
的用法示例。
在下文中一共展示了Datum::getDict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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
}
}
示例2: checkCodec
void VariableRegistryTestFixture::checkCodec(const Datum &generated_codec, int number_of_entries) const {
CPPUNIT_ASSERT( generated_codec.isDictionary() );
auto &dict = generated_codec.getDict();
CPPUNIT_ASSERT( dict.size() == number_of_entries );
for (auto &item : dict) {
auto &key = item.first;
auto &value = item.second;
CPPUNIT_ASSERT( key.isInteger() );
CPPUNIT_ASSERT( value.isDictionary() );
}
}
示例3:
BEGIN_NAMESPACE_MW
map<int, string> extract_simple_codec_map(Datum datum){
map<int, string> result;
for (auto &item : datum.getDict()) {
int key = item.first.getInteger();
Datum value_datum = item.second;
if (value_datum.isDictionary()) {
value_datum = value_datum.getElement("tagname");
}
result[key] = value_datum.getString();
}
return result;
}