本文整理汇总了C++中poco::json::object::Ptr::has方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::has方法的具体用法?C++ Ptr::has怎么用?C++ Ptr::has使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类poco::json::object::Ptr
的用法示例。
在下文中一共展示了Ptr::has方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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>();
}
}
}
示例3: searchSimilarRequest
void Controller::searchSimilarRequest(std::map<std::string, std::string>& params, const Poco::Dynamic::Var& request) {
Record record;
vector<uint8_t>* image_data = NULL;
int count = 10;
if (params.count("blockHash")) {
record.getHashes()[BlockHash] = str2bin(params["blockHash"]);
}
if (params.count("dHash")) {
record.getHashes()[DHash] = str2bin(params["dHash"]);
}
if (params.count("gaussDHash")) {
record.getHashes()[GaussDHash] = str2bin(params["gaussDHash"]);
}
if (params.count("gauss2DHash")) {
record.getHashes()[Gauss2DHash] = str2bin(params["gauss2DHash"]);
}
if (params.count("gaussBlockHash")) {
record.getHashes()[GaussBlockHash] = str2bin(params["gaussBlockHash"]);
}
if (params.count("url")) {
image_data = Image::fromUrl(params["url"]);
}
if (params.count("count")) {
count = atoi(params["count"].c_str());
}
if (!request.isEmpty()) {
Poco::JSON::Object::Ptr json = request.extract<Poco::JSON::Object::Ptr>();
if (!image_data && json->has("image_base64")) {
image_data = Image::fromBase64(json->getValue<string>("image_base64"));
}
if (!image_data && json->has("image_url")) {
image_data = Image::fromUrl(json->getValue<string>("image_url"));
}
}
if (image_data) {
HashAlgorithmManager::getInstance().attachSimilarHashes(record, image_data);
delete image_data;
}
appio::print_ok(HashManager::getInstance().searchSimilar(record, count));
}
示例4: 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);
}
}
}
示例5: getDevVersion
bool CSystemManager::getDevVersion(Poco::JSON::Object::Ptr& param, std::string& detail)
{
CConfigManager* config = CConfigManager::instance();
JSON::Object::Ptr pUpdate;
config->getConfig("Update", pUpdate);
if(pUpdate.isNull() || !pUpdate->has("infoPath"))
{
detail = "901";
return false;
}
std::string infoPath = pUpdate->getValue<std::string>("infoPath");
File file(infoPath);
if(!file.exists())
{
detail = "465";
return false;
}
Util::JSONConfiguration info;
std::string version;
std::string buildtime;
try
{
info.load(infoPath);
version = info.getString(UPDATE_VERSION_STR);
buildtime = info.getString(UPDATE_BUILDTIME_STR);
}
catch(Exception& e)
{
detail = "465";
warnf("%s, %d: Load device info file failed, %s", __FILE__, __LINE__, e.message().c_str());
return false;
}
if(param->has(REG_TOKEN_STR))
{
param->remove(REG_TOKEN_STR);
}
param->set(SYSTEM_VERSION_STR, version);
param->set(SYSTEM_BUILDTIME_STR, buildtime);
return true;
}
示例6: assert
std::string Pothos::Topology::dumpJSON(const std::string &request)
{
//extract input request
Poco::JSON::Parser p; p.parse(request.empty()?"{}":request);
auto configObj = p.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();
assert(configObj);
const auto modeConfig = configObj->optValue<std::string>("mode", "flat");
//parse request into traversal arguments
const bool flatten = (modeConfig == "flat");
const bool traverse = (modeConfig != "rendered");
const auto &flows = (modeConfig == "rendered")?_impl->activeFlatFlows:_impl->flows;
//replace rendered names with names from flattened hierarchy
Poco::JSON::Object::Ptr flatBlocks;
if (modeConfig == "rendered")
{
Poco::JSON::Parser pFlat; pFlat.parse(this->dumpJSON("{\"mode\":\"flat\"}"));
auto flatObj = pFlat.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();
assert(flatObj);
flatBlocks = flatObj->getObject("blocks");
assert(flatBlocks);
}
//output object
Poco::JSON::Object::Ptr topObj(new Poco::JSON::Object());
//create blocks map
Poco::JSON::Object::Ptr blocksObj(new Poco::JSON::Object());
topObj->set("blocks", blocksObj);
for (const auto &block : getObjSetFromFlowList(flows))
{
//gather block info
Poco::JSON::Object::Ptr blockObj(new Poco::JSON::Object());
const auto blockId = block.call<std::string>("uid");
blocksObj->set(blockId, blockObj);
//replace rendered names with names from flattened hierarchy
blockObj->set("name", block.call<std::string>("getName"));
if (flatBlocks and flatBlocks->has(blockId))
{
blockObj->set("name", flatBlocks->getObject(blockId)->getValue<std::string>("name"));
}
//input port info
Poco::JSON::Array::Ptr inputsArray(new Poco::JSON::Array());
for (const auto &portInfo : block.call<std::vector<PortInfo>>("inputPortInfo"))
{
inputsArray->add(portInfoToObj(portInfo));
}
if (inputsArray->size() > 0) blockObj->set("inputs", inputsArray);
//output port info
Poco::JSON::Array::Ptr outputsArray(new Poco::JSON::Array());
for (const auto &portInfo : block.call<std::vector<PortInfo>>("outputPortInfo"))
{
outputsArray->add(portInfoToObj(portInfo));
}
if (outputsArray->size() > 0) blockObj->set("outputs", outputsArray);
//sub-topology info
if (traverse and this->uid() != blockId) try
{
auto subDump = block.call<std::string>("dumpJSON", "{\"mode\":\"top\"}");
Poco::JSON::Parser psub; psub.parse(subDump);
auto subObj = psub.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();
assert(subObj);
std::vector<std::string> names; subObj->getNames(names);
for (const auto &name : names) blockObj->set(name, subObj->get(name));
}
catch (const Pothos::Exception &){}
}
//create connections list
Poco::JSON::Array::Ptr connsArray(new Poco::JSON::Array());
topObj->set("connections", connsArray);
for (const auto &flow : flows)
{
Poco::JSON::Object::Ptr connObj(new Poco::JSON::Object());
connsArray->add(connObj);
connObj->set("srcId", flow.src.uid);
connObj->set("srcName", flow.src.name);
connObj->set("dstId", flow.dst.uid);
connObj->set("dstName", flow.dst.name);
}
//recursive flatten when instructed
while (flatten and flattenDump(topObj));
//return the string-formatted result
std::stringstream ss; topObj->stringify(ss, 4);
return ss.str();
}
示例7: blockIsHier
static bool blockIsHier(const Poco::JSON::Object::Ptr &blockObj)
{
assert(blockObj);
return blockObj->has("connections");
}
示例8: ingestRequest
void Controller::ingestRequest(const Poco::Dynamic::Var& request) {
if (request.type() != typeid(Poco::JSON::Array::Ptr)) {
throw RequestException("Invalid JSON format, root must be array.");
}
try {
Poco::JSON::Array::Ptr jsonArray = request.extract<Poco::JSON::Array::Ptr>();
for (Poco::JSON::Array::ConstIterator it = jsonArray->begin(); it != jsonArray->end(); it++) {
Poco::JSON::Object::Ptr json = it->extract<Poco::JSON::Object::Ptr>();
Record record;
vector<uint8_t>* image_data = NULL;
if (json->has("id")) {
record.setId(json->getValue<string>("id"));
}
if (json->has("thumbnail")) {
record.setThumbnail(json->getValue<string>("thumbnail"));
}
if (json->has("metadata")) {
record.setMetadata(json->getValue<string>("metadata"));
}
if (json->has("blockHash")) {
record.getHashes()[BlockHash] = str2bin(json->getValue<string>("blockHash"));
}
if (json->has("dHash")) {
record.getHashes()[DHash] = str2bin(json->getValue<string>("dHash"));
}
if (json->has("gaussDHash")) {
record.getHashes()[GaussDHash] = str2bin(json->getValue<string>("gaussDHash"));
}
if (json->has("gauss2DHash")) {
record.getHashes()[Gauss2DHash] = str2bin(json->getValue<string>("gauss2DHash"));
}
if (json->has("gaussBlockHash")) {
record.getHashes()[GaussBlockHash] = str2bin(json->getValue<string>("gaussBlockHash"));
}
if (json->has("image_base64")) {
image_data = Image::fromBase64(json->getValue<string>("image_base64"));
}
if (!image_data && json->has("image_url")) {
image_data = Image::fromUrl(json->getValue<string>("image_url"));
}
if (json->has("status")) {
string status = json->getValue<string>("status");
if (status == "deleted") {
deleteRequest(record);
continue;
} else {
throw RequestException("Invalid status value.");
}
}
if (image_data) {
HashAlgorithmManager::getInstance().attachHashes(record, image_data);
delete image_data;
}
putRequest(record);
}
} catch (Poco::JSON::JSONException& e) {
throw RequestException("Invalid JSON format.");
}
appio::print_ok("Data was successfully changed.");
}