本文整理汇总了C++中poco::json::object::Ptr类的典型用法代码示例。如果您正苦于以下问题:C++ Ptr类的具体用法?C++ Ptr怎么用?C++ Ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: extract_token
string ExposerConfig::extract_token(string response_string) {
try
{
//Try to extract token
Poco::JSON::Parser parser;
Poco::Dynamic::Var result = parser.parse(response_string);
Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
string tmptoken = object->get("token");
ostringstream tmpmsg;
//tmpmsg << " ===== Got a token: " << tmptoken;
tmpmsg << " ===== Got a token.";
Log::log(Log::INFO, tmpmsg.str());
return tmptoken;
}
catch (std::exception &ex)
{
ostringstream tmpmsg;
tmpmsg << "Exception when trying to read token: " << ex.what();
Log::log(Log::ERROR, tmpmsg.str());
return "";
}
}
示例2: copy
void ChannelController::copy()
{
Poco::JSON::Object::Ptr pcfParameters;
if (data().has("input") && data().isObject("input"))
{
pcfParameters = data().getObject("input");
}
else
{
pcfParameters = new Poco::JSON::Object();
std::vector<std::string> parameters = getParameters();
if (parameters.size() > 2)
{
pcfParameters->set("FromChannelName", parameters[2]);
}
if (parameters.size() > 1)
{
pcfParameters->set("ToChannelName", parameters[1]);
}
// Copy all query parameters to PCF
for (Poco::Net::NameValueCollection::ConstIterator it = form().begin(); it != form().end(); ++it)
{
pcfParameters->set(it->first, it->second);
}
}
ChannelCopy command(*commandServer(), pcfParameters);
command.execute();
}
示例3: start
void ChannelController::start()
{
Poco::JSON::Object::Ptr pcfParameters;
if ( data().has("input") && data().isObject("input") )
{
pcfParameters = data().getObject("input");
}
else
{
pcfParameters = new Poco::JSON::Object();
setData("input", pcfParameters);
std::vector<std::string> parameters = getParameters();
// First parameter is queuemanager
// Second parameter is a channelname
if ( parameters.size() > 1 )
{
pcfParameters->set("ChannelName", parameters[1]);
}
else
{
if ( form().has("ChannelName") ) pcfParameters->set("ChannelName", form().get("ChannelName"));
}
if ( form().has("CommandScope") ) pcfParameters->set("CommandScope", form().get("CommandScope"));
if ( form().has("ChannelDisposition") ) pcfParameters->set("ChannelDisposition", form().get("ChannelDisposition"));
}
ChannelStart command(*commandServer(), pcfParameters);
setData("data", command.execute());
}
示例4: 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>();
}
}
}
示例5: inquire
void QueueStatusController::inquire()
{
Poco::JSON::Object::Ptr pcfParameters;
if ( data().has("input") && data().isObject("input") )
{
pcfParameters = data().getObject("input");
}
else
{
pcfParameters = new Poco::JSON::Object();
setData("input", pcfParameters);
std::vector<std::string> parameters = getParameters();
// First parameter is queuemanager
// Second parameter can be a queuename. If this is passed, the
// query parameter QName or queueName is ignored.
if ( parameters.size() > 1 )
{
pcfParameters->set("QName", parameters[1]);
}
else
{
// Handle query parameters
pcfParameters->set("QName", form().get("QName", "*"));
}
pcfParameters->set("ExcludeSystem", form().get("ExcludeSystem", "false").compare("true") == 0);
pcfParameters->set("ExcludeTemp", form().get("ExcludeTemp", "false").compare("true") == 0);
if ( form().has("CommandScope") )
{
pcfParameters->set("CommandScope", form().get("CommandScope"));
}
if ( form().has("QSGDisposition") )
{
pcfParameters->set("QSGDisposition", form().get("QSGDisposition"));
}
if ( form().has("StatusType") ) pcfParameters->set("StatusType", form().get("StatusType"));
if ( form().has("OpenType") ) pcfParameters->set("OpenType", form().get("OpenType"));
handleFilterForm(pcfParameters);
Poco::JSON::Array::Ptr attrs = new Poco::JSON::Array();
formElementToJSONArray("QStatusAttrs", attrs);
if ( attrs->size() == 0 ) // Nothing found for QStatusAttrs, try Attrs
{
formElementToJSONArray("Attrs", attrs);
}
if ( attrs->size() > 0 )
{
pcfParameters->set("QStatusAttrs", attrs);
}
}
QueueStatusInquire command(*commandServer(), pcfParameters);
setData("data", command.execute());
}
示例6: create
void ChannelController::create()
{
Poco::JSON::Object::Ptr pcfParameters;
if (data().has("input") && data().isObject("input"))
{
pcfParameters = data().getObject("input");
}
else
{
pcfParameters = new Poco::JSON::Object();
std::vector<std::string> parameters = getParameters();
if (parameters.size() > 1)
{
pcfParameters->set("ChannelName", parameters[1]);
}
if (parameters.size() > 2)
{
pcfParameters->set("ChannelType", parameters[2]);
}
// Copy all query parameters to PCF, except ChannelName if it is already set on the URI
for (Poco::Net::NameValueCollection::ConstIterator it = form().begin(); it != form().end(); ++it)
{
if (parameters.size() > 1 && Poco::icompare(it->first, "ChannelName") == 0) continue;
if (parameters.size() > 2 && Poco::icompare(it->first, "ChannelType") == 0) continue;
pcfParameters->set(it->first, it->second);
}
}
ChannelCreate command(*commandServer(), pcfParameters);
command.execute();
}
示例7: 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;
}
示例8: main
int main(int argc, char** argv)
{
Poco::JSON::Object::Ptr obj;
std::string dir = Poco::Environment::get("POCO_BASE") + "/JSON/samples/Benchmark/";
Poco::Path filePath(dir, "input");
std::ostringstream ostr;
if ( filePath.isFile() )
{
Poco::File inputFile(filePath);
if ( inputFile.exists() )
{
Poco::FileInputStream fis(filePath.toString());
Poco::StreamCopier::copyStream(fis, ostr);
}
else
{
std::cout << filePath.toString() << " doesn't exist!" << std::endl;
return 1;
}
}
std::cout << std::setw(25) << "POCO JSON";
std::string jsonStr = ostr.str();
try
{
Poco::JSON::DefaultHandler handler;
Poco::JSON::Parser parser;
parser.setHandler(&handler);
Poco::Timestamp time1;
parser.parse(jsonStr);
Poco::DynamicAny result = handler.result();
Poco::Timestamp time2;
printTimeDiff(time1, time2);
if ( result.type() == typeid(Poco::JSON::Object::Ptr) )
{
obj = result.extract<Poco::JSON::Object::Ptr>();
}
//Serialize to string
std::ostringstream out;
Poco::Timestamp time3;
obj->stringify(out);
Poco::Timestamp time4;
printTimeDiff(time3, time4);
std::cout << std::endl;
}
catch(Poco::JSON::JSONException jsone)
{
std::cout << jsone.message() << std::endl;
}
return 0;
}
示例9: save
void save(Archive & ar, const Poco::JSON::Object::Ptr &t, const unsigned int)
{
bool isNull = t.isNull();
ar << isNull;
if (isNull) return;
std::ostringstream oss; t->stringify(oss);
std::string s = oss.str(); ar << s;
}
示例10: 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();
}
示例11: portInfosToJSON
//! helper to convert the port info vector into JSON for serialization of the block
static Poco::JSON::Array::Ptr portInfosToJSON(const std::vector<Pothos::PortInfo> &infos)
{
Poco::JSON::Array::Ptr array = new Poco::JSON::Array();
for (const auto &info : infos)
{
Poco::JSON::Object::Ptr portInfo = new Poco::JSON::Object();
portInfo->set("name", info.name);
portInfo->set("isSigSlot", info.isSigSlot);
portInfo->set("size", info.dtype.size());
portInfo->set("dtype", info.dtype.toMarkup());
array->add(portInfo);
}
return array;
}
示例12: 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;
}
示例13: deserialize
void GraphConnection::deserialize(Poco::JSON::Object::Ptr obj)
{
auto outputId = QString::fromStdString(obj->getValue<std::string>("outputId"));
auto inputId = QString::fromStdString(obj->getValue<std::string>("inputId"));
auto outputKey = QString::fromStdString(obj->getValue<std::string>("outputKey"));
auto inputKey = QString::fromStdString(obj->getValue<std::string>("inputKey"));
auto draw = dynamic_cast<GraphDraw *>(this->parent());
assert(draw != nullptr);
//resolve IO objects by id
QPointer<GraphObject> inputObj = nullptr;
QPointer<GraphObject> outputObj = nullptr;
for (const auto obj : draw->getGraphObjects(false))
{
if (obj->getId() == inputId) inputObj = obj;
if (obj->getId() == outputId) outputObj = obj;
}
if (inputObj.isNull()) throw Pothos::Exception("GraphConnection::deserialize()", "cant resolve object with ID: '"+inputId.toStdString()+"'");
if (outputObj.isNull()) throw Pothos::Exception("GraphConnection::deserialize()", "cant resolve object with ID: '"+outputId.toStdString()+"'");
this->setupEndpoint(GraphConnectionEndpoint(inputObj, GraphConnectableKey(inputKey, true)));
this->setupEndpoint(GraphConnectionEndpoint(outputObj, GraphConnectableKey(outputKey, false)));
assert(this->getInputEndpoint().isValid());
assert(this->getOutputEndpoint().isValid());
GraphObject::deserialize(obj);
}
示例14: 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));
}
示例15: assert
Poco::JSON::Object::Ptr AffinityZoneEditor::getCurrentConfig(void) const
{
Poco::JSON::Object::Ptr config = new Poco::JSON::Object();
config->set("color", _colorPicker->currentColor().name().toStdString());
config->set("hostUri", _hostsBox->itemText(_hostsBox->currentIndex()).toStdString());
config->set("processName", _processNameEdit->text().toStdString());
config->set("numThreads", _numThreadsSpin->value());
config->set("priority", _prioritySpin->value()/100.0);
assert(_cpuSelection != nullptr);
config->set("affinityMode", _cpuSelection->mode());
Poco::JSON::Array::Ptr affinityMask = new Poco::JSON::Array();
for (auto num : _cpuSelection->selection()) affinityMask->add(num);
config->set("affinityMask", affinityMask);
config->set("yieldMode", _yieldModeBox->itemData(_yieldModeBox->currentIndex()).toString().toStdString());
return config;
}