本文整理汇总了C++中poco::json::object::Ptr::getArray方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::getArray方法的具体用法?C++ Ptr::getArray怎么用?C++ Ptr::getArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类poco::json::object::Ptr
的用法示例。
在下文中一共展示了Ptr::getArray方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makeBlock
/***********************************************************************
* block factory - make blocks from JSON object
**********************************************************************/
static Pothos::Proxy makeBlock(
const Pothos::Proxy ®istry,
const Pothos::Proxy &evaluator,
const Poco::JSON::Object::Ptr &blockObj)
{
const auto id = blockObj->getValue<std::string>("id");
if (not blockObj->has("path")) throw Pothos::DataFormatException(
"Pothos::Topology::make()", "blocks["+id+"] missing 'path' field");
const auto path = blockObj->getValue<std::string>("path");
//load up the constructor args
Poco::JSON::Array::Ptr argsArray;
if (blockObj->isArray("args")) argsArray = blockObj->getArray("args");
const auto ctorArgs = evalArgsArray(evaluator, argsArray);
//create the block
auto block = registry.getHandle()->call(path, ctorArgs.data(), ctorArgs.size());
//make the calls
Poco::JSON::Array::Ptr callsArray;
if (blockObj->isArray("calls")) callsArray = blockObj->getArray("calls");
if (callsArray) for (size_t i = 0; i < callsArray->size(); i++)
{
const auto callArray = callsArray->getArray(i);
auto name = callArray->getElement<std::string>(0);
const auto callArgs = evalArgsArray(evaluator, callArray, 1/*offset*/);
block.getHandle()->call(name, callArgs.data(), callArgs.size());
}
return block;
}
示例2: eval
void BlockEval::eval(const std::string &id, const Poco::JSON::Object::Ptr &blockDesc)
{
auto env = Pothos::ProxyEnvironment::make("managed");
auto registry = env->findProxy("Pothos/BlockRegistry");
auto path = blockDesc->getValue<std::string>("path");
//load up the constructor args
std::vector<Pothos::Proxy> ctorArgs;
for (auto arg : *blockDesc->getArray("args"))
{
const auto propKey = arg.extract<std::string>();
const auto obj = _properties[propKey];
ctorArgs.push_back(env->convertObjectToProxy(obj));
}
//create the block
try
{
_proxyBlock = registry.getHandle()->call(path, ctorArgs.data(), ctorArgs.size());
}
catch (const Pothos::Exception &ex)
{
throw Pothos::Exception("BlockEval factory("+path+")", ex);
}
_proxyBlock.callVoid("setName", id);
//inspect before making any calls -- calls may fails
_portDesc = this->inspectPorts();
//make the calls
for (auto call : *blockDesc->getArray("calls"))
{
const auto callObj = call.extract<Poco::JSON::Object::Ptr>();
const auto callName = callObj->get("name").extract<std::string>();
std::vector<Pothos::Proxy> callArgs;
for (auto arg : *callObj->getArray("args"))
{
const auto propKey = arg.extract<std::string>();
const auto obj = _properties[propKey];
callArgs.push_back(env->convertObjectToProxy(obj));
}
try
{
_proxyBlock.getHandle()->call(callName, callArgs.data(), callArgs.size());
}
catch (const Pothos::Exception &ex)
{
throw Pothos::Exception("BlockEval call("+callName+")", ex);
}
}
//inspect after making calls -- ports may have changed
_portDesc = this->inspectPorts();
}
示例3: updateTasksList
void updateTasksList()
{
printf("updateTasksList()\n");
tasksNum = task_manager->getTasksNumber();
if(tasksNum > 0)
{
Poco::JSON::Object::Ptr pObj = new Poco::JSON::Object;
task_manager->getTasks(pObj);
Poco::DynamicStruct ds = *pObj;
printf("ds:%s\n", ds.toString().c_str());
if(pObj->has("tasks"))
printf("pObj has tasks\n");
if(pObj->isArray("tasks"))
printf("pObj is array tasks\n");
Poco::JSON::Array::Ptr pArray = pObj->getArray("tasks");
printf("tasksNum:%d, array size:%d\n", tasksNum, pArray->size());
for(int i = 0; i < tasksNum; i++)
{
memset(pTask[i], 0, sizeof(TaskInfo));
Poco::Dynamic::Var var = pArray->get(i);
Poco::DynamicStruct dss = var.extract<Poco::DynamicStruct>();
pTask[i]->id = (Poco::Int64)dss["id"].extract<Poco::Int64>();
pTask[i]->option = dss["option"].extract<int>();
pTask[i]->hour = dss["hour"].extract<int>();
pTask[i]->minute = dss["minute"].extract<int>();
pTask[i]->weekday = dss["weekday"].extract<int>();
}
}
}
示例4: getParamDocString
QString BlockPropertiesPanel::getParamDocString(const Poco::JSON::Object::Ptr ¶mDesc)
{
assert(paramDesc);
QString output;
output += QString("<h3>%1</h3>").arg(QString::fromStdString(paramDesc->getValue<std::string>("name")));
if (paramDesc->isArray("desc")) for (const auto &lineObj : *paramDesc->getArray("desc"))
{
const auto line = lineObj.extract<std::string>();
if (line.empty()) output += "<p /><p>";
else output += QString::fromStdString(line)+"\n";
}
else output += QString("<p>%1</p>").arg(tr("Undocumented"));
return output;
}
示例5: blockDescMatchesFilter
bool BlockTreeWidget::blockDescMatchesFilter(const Poco::JSON::Object::Ptr &blockDesc)
{
if (_filter.isEmpty()) return true;
const auto path = blockDesc->get("path").extract<std::string>();
const auto name = blockDesc->get("name").extract<std::string>();
//construct a candidate string from path, name, categories, and keywords.
std::string candidate = path+name;
if (blockDesc->isArray("categories")) for (auto categoryObj : *blockDesc->getArray("categories"))
{
candidate += categoryObj.extract<std::string>();
}
if(blockDesc->isArray("keywords"))
{
const auto keywords = blockDesc->getArray("keywords");
for(auto keyword : *keywords) candidate += keyword.extract<std::string>();
}
//reject if filter string not found in candidate
candidate = Poco::toLower(candidate);
const auto searchToken = Poco::toLower(_filter.toStdString());
return (candidate.find(searchToken) != std::string::npos);
}
示例6: loadFromConfig
void AffinityZoneEditor::loadFromConfig(const Poco::JSON::Object::Ptr &config)
{
if (config->has("color"))
{
auto color = QString::fromStdString(config->getValue<std::string>("color"));
_colorPicker->blockSignals(true);
_colorPicker->setCurrentColor(QColor(color));
_colorPicker->blockSignals(false);
}
if (config->has("hostUri"))
{
auto uri = QString::fromStdString(config->getValue<std::string>("hostUri"));
this->selectThisUri(uri);
}
if (config->has("processName"))
{
auto name = QString::fromStdString(config->getValue<std::string>("processName"));
_processNameEdit->setText(name);
}
if (config->has("numThreads"))
{
_numThreadsSpin->setValue(config->getValue<int>("numThreads"));
}
if (config->has("priority"))
{
_prioritySpin->setValue(int(config->getValue<double>("priority")*100));
}
if (config->has("affinityMode") and config->has("affinityMask"))
{
auto mode = config->getValue<std::string>("affinityMode");
auto mask = config->getArray("affinityMask");
std::vector<size_t> selection;
for (size_t i = 0; i < mask->size(); i++) selection.push_back(mask->getElement<int>(i));
_cpuSelection->setup(mode, selection);
}
if (config->has("yieldMode"))
{
auto mode = QString::fromStdString(config->getValue<std::string>("yieldMode"));
for (int i = 0; i < _yieldModeBox->count(); i++)
{
if (_yieldModeBox->itemData(i).toString() == mode) _yieldModeBox->setCurrentIndex(i);
}
}
}
示例7: flattenDump
static bool flattenDump(Poco::JSON::Object::Ptr &topObj)
{
assert(topObj);
bool hierFound = false;
//create new blocks object that flattens any hierarchy to 1 depth
//if this block is a hierarchy -- bring its blocks to the top level
const auto blocksObj = topObj->getObject("blocks");
assert(blocksObj);
Poco::JSON::Object::Ptr flatBlocksObj(new Poco::JSON::Object());
std::vector<std::string> blockUids; blocksObj->getNames(blockUids);
for (const auto &uid : blockUids)
{
const auto blockObj = blocksObj->getObject(uid);
assert(blockObj);
if (blockIsHier(blockObj))
{
hierFound = true;
const auto subBlocksObj = blockObj->getObject("blocks");
assert(subBlocksObj);
const auto thisName = blockObj->getValue<std::string>("name");
std::vector<std::string> subBlockUids; subBlocksObj->getNames(subBlockUids);
for (const auto &subUid : subBlockUids)
{
auto subBlockObj = subBlocksObj->getObject(subUid);
assert(subBlockObj);
const auto subName = subBlockObj->getValue<std::string>("name");
subBlockObj->set("name", thisName+"/"+subName); //heritage name
flatBlocksObj->set(subUid, subBlockObj);
}
}
else flatBlocksObj->set(uid, blockObj);
}
//create new connections array folding out depth 1 hierarchies
const auto connsArray = topObj->getArray("connections");
assert(connsArray);
Poco::JSON::Array::Ptr flatConnsArray(new Poco::JSON::Array());
for (size_t c_i = 0; c_i < connsArray->size(); c_i++)
{
const auto connObj = connsArray->getObject(c_i);
assert(connObj);
for (const auto & resolvedSrc : resolvePorts(topObj, connObj->getValue<std::string>("srcId"), connObj->getValue<std::string>("srcName"), true))
{
for (const auto & resolvedDst : resolvePorts(topObj, connObj->getValue<std::string>("dstId"), connObj->getValue<std::string>("dstName"), false))
{
Poco::JSON::Object::Ptr flatConnObj(new Poco::JSON::Object());
flatConnsArray->add(flatConnObj);
flatConnObj->set("srcId", resolvedSrc.first);
flatConnObj->set("srcName", resolvedSrc.second);
flatConnObj->set("dstId", resolvedDst.first);
flatConnObj->set("dstName", resolvedDst.second);
}
}
}
//resolve pass-through connections and totally internal connections
for (const auto &uid : blockUids)
{
const auto blockObj = blocksObj->getObject(uid);
assert(blockObj);
if (not blockIsHier(blockObj)) continue;
const auto subConnsArray = blockObj->getArray("connections");
for (size_t c_i = 0; c_i < subConnsArray->size(); c_i++)
{
const auto subConnObj = subConnsArray->getObject(c_i);
assert(subConnObj);
const bool srcIsThis = subConnObj->getValue<std::string>("srcId") == uid;
const bool dstIsThis = subConnObj->getValue<std::string>("dstId") == uid;
//totally internal connection
if (not srcIsThis and not dstIsThis) flatConnsArray->add(subConnObj);
//otherwise not a pass-through
if (not srcIsThis or not dstIsThis) continue;
//find sources where the destination is this pass-through
for (size_t c_s = 0; c_s < connsArray->size(); c_s++)
{
const auto connObj_s = connsArray->getObject(c_s);
assert(connObj_s);
if (connObj_s->getValue<std::string>("dstId") != uid) continue;
if (connObj_s->getValue<std::string>("dstName") != subConnObj->getValue<std::string>("srcName")) continue;
//find sources where the destination is this pass-through
for (size_t c_d = 0; c_d < connsArray->size(); c_d++)
{
const auto connObj_d = connsArray->getObject(c_d);
assert(connObj_d);
if (connObj_d->getValue<std::string>("srcId") != uid) continue;
if (connObj_d->getValue<std::string>("srcName") != subConnObj->getValue<std::string>("dstName")) continue;
Poco::JSON::Object::Ptr flatConnObj(new Poco::JSON::Object());
flatConnsArray->add(flatConnObj);
flatConnObj->set("srcId", connObj_s->get("srcId"));
flatConnObj->set("srcName", connObj_s->get("srcName"));
flatConnObj->set("dstId", connObj_d->get("dstId"));
flatConnObj->set("dstName", connObj_d->get("dstName"));
}
//.........这里部分代码省略.........