本文整理汇总了C++中poco::json::object::Ptr::getNames方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::getNames方法的具体用法?C++ Ptr::getNames怎么用?C++ Ptr::getNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类poco::json::object::Ptr
的用法示例。
在下文中一共展示了Ptr::getNames方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: args
/***********************************************************************
* make topology from JSON string - implementation
**********************************************************************/
std::shared_ptr<Pothos::Topology> Pothos::Topology::make(const std::string &json)
{
//parse the json string/file to a JSON object
const auto topObj = parseJSONStr(json);
//create the proxy environment (local) and the registry
auto env = Pothos::ProxyEnvironment::make("managed");
auto registry = env->findProxy("Pothos/BlockRegistry");
auto evaluator = env->findProxy("Pothos/Util/EvalEnvironment").callProxy("make");
//create thread pools
std::map<std::string, Pothos::Proxy> threadPools;
Poco::JSON::Object::Ptr threadPoolObj;
if (topObj->isObject("threadPools")) threadPoolObj = topObj->getObject("threadPools");
std::vector<std::string> threadPoolNames;
if (threadPoolObj) threadPoolObj->getNames(threadPoolNames);
for (const auto &name : threadPoolNames)
{
std::stringstream ss;
threadPoolObj->getObject(name)->stringify(ss);
Pothos::ThreadPoolArgs args(ss.str());
threadPools[name] = env->findProxy("Pothos/ThreadPool").callProxy("new", args);
}
//create the topology and add it to the blocks
//the IDs 'self', 'this', and '' can be used
std::map<std::string, Pothos::Proxy> blocks;
auto topology = Pothos::Topology::make();
blocks["self"] = env->makeProxy(topology);
blocks["this"] = env->makeProxy(topology);
blocks[""] = env->makeProxy(topology);
//create the blocks
Poco::JSON::Array::Ptr blockArray;
if (topObj->isArray("blocks")) blockArray = topObj->getArray("blocks");
if (blockArray) for (size_t i = 0; i < blockArray->size(); i++)
{
if (not blockArray->isObject(i)) throw Pothos::DataFormatException(
"Pothos::Topology::make()", "blocks["+std::to_string(i)+"] must be an object");
const auto &blockObj = blockArray->getObject(i);
if (not blockObj->has("id")) throw Pothos::DataFormatException(
"Pothos::Topology::make()", "blocks["+std::to_string(i)+"] missing 'id' field");
const auto id = blockObj->getValue<std::string>("id");
blocks[id] = makeBlock(registry, evaluator, blockObj);
//set the thread pool
const auto threadPoolName = blockObj->optValue<std::string>("threadPool", "default");
auto threadPoolIt = threadPools.find(threadPoolName);
if (threadPoolIt != threadPools.end()) blocks[id].callVoid("setThreadPool", threadPoolIt->second);
else if (threadPoolName != "default") throw Pothos::DataFormatException(
"Pothos::Topology::make()", "blocks["+id+"] unknown threadPool = " + threadPoolName);
}
//create the topology and connect the blocks
Poco::JSON::Array::Ptr connArray;
if (topObj->isArray("connections")) connArray = topObj->getArray("connections");
if (connArray) for (size_t i = 0; i < connArray->size(); i++)
{
if (not connArray->isArray(i)) throw Pothos::DataFormatException(
"Pothos::Topology::make()", "connections["+std::to_string(i)+"] must be an array");
const auto &connArgs = connArray->getArray(i);
if (connArgs->size() != 4) throw Pothos::DataFormatException(
"Pothos::Topology::make()", "connections["+std::to_string(i)+"] must be size 4");
//extract connection arg fields
const auto srcId = connArgs->getElement<std::string>(0);
const auto srcPort = connArgs->get(1).toString();
const auto dstId = connArgs->getElement<std::string>(2);
const auto dstPort = connArgs->get(3).toString();
//check that the block IDs exist
if (blocks.count(srcId) == 0) throw Pothos::DataFormatException(
"Pothos::Topology::make()", "connections["+std::to_string(i)+"] no such ID: " + srcId);
if (blocks.count(dstId) == 0) throw Pothos::DataFormatException(
"Pothos::Topology::make()", "connections["+std::to_string(i)+"] no such ID: " + dstId);
//make the connection
topology->connect(blocks.at(srcId), srcPort, blocks.at(dstId), dstPort);
}
return topology;
}