本文整理汇总了C++中poco::json::Parser类的典型用法代码示例。如果您正苦于以下问题:C++ Parser类的具体用法?C++ Parser怎么用?C++ Parser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Parser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AffinityZoneEditor
AffinityZoneEditor *AffinityZonesDock::createZoneFromName(const QString &zoneName)
{
auto editor = new AffinityZoneEditor(this);
_editorsTabs->addTab(editor, zoneName);
if (zoneName == getSettings().value("AffinityZones/currentZone").toString()) _editorsTabs->setCurrentWidget(editor);
//restore the settings from save -- even if this is a new panel with the same name as a previous one
auto json = getSettings().value("AffinityZones/zones/"+zoneName).toString();
if (not json.isEmpty()) try
{
Poco::JSON::Parser p; p.parse(json.toStdString());
auto dataObj = p.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();
editor->loadFromConfig(dataObj);
}
catch (const Poco::JSON::JSONException &ex)
{
poco_error_f2(Poco::Logger::get("PothosGui.AffinityZonesDock"), "Failed to load editor for zone '%s' -- %s", zoneName.toStdString(), ex.displayText());
}
//now connect the changed signal after initialization+restore changes
connect(editor, SIGNAL(settingsChanged(void)), this, SLOT(handleZoneEditorChanged(void)));
connect(editor, SIGNAL(settingsChanged(void)), _mapper, SLOT(map(void)));
_mapper->setMapping(editor, zoneName);
//when to update colors
connect(editor, SIGNAL(settingsChanged(void)), this, SLOT(updateTabColors(void)));
this->updateTabColors();
return editor;
}
示例2: setType
void WindowFunction::setType(const std::string &type)
{
//parse the input
Poco::RegularExpression::MatchVec matches;
Poco::RegularExpression("^\\s*(\\w+)\\s*(\\((.*)\\))?\\s*$").match(type, 0, matches);
if (matches.empty()) throw Pothos::InvalidArgumentException("WindowFunction("+type+")", "cant parse window type");
//parse the args
Poco::JSON::Array::Ptr args(new Poco::JSON::Array());
if (matches.size() > 3)
{
auto argsStr = type.substr(matches[3].offset, matches[3].length);
Poco::JSON::Parser p; p.parse("["+argsStr+"]");
args = p.getHandler()->asVar().extract<Poco::JSON::Array::Ptr>();
}
//check input
auto name = Poco::toLower(type.substr(matches[1].offset, matches[1].length));
if (name == "kaiser")
{
if (args->size() != 1) throw Pothos::InvalidArgumentException("WindowFunction("+type+")", "expects format: kaiser(beta)");
}
else if (args->size() != 0) throw Pothos::InvalidArgumentException("WindowFunction("+type+")", name + " takes no arguments");
//bind window function
if (name == "rectangular") _calc = &rectangular;
else if (name == "hann") _calc = &hann;
else if (name == "hamming") _calc = &hamming;
else if (name == "blackman") _calc = &blackman;
else if (name == "bartlett") _calc = &bartlett;
else if (name == "flattop") _calc = &flattop;
else if (name == "kaiser") _calc = std::bind(&kaiser, std::placeholders::_1, std::placeholders::_2, args->getElement<double>(0));
else throw Pothos::InvalidArgumentException("WindowFunction::setType("+type+")", "unknown window name");
this->reload();
}
示例3: async
std::future<bool> UserData::SendFriendResponse(const UUID &id, const UUID &requester, const std::string &response,
BooleanCallback success, APIFailureCallback failure)
{
return std::async(std::launch::async, [=]() -> bool {
std::stringstream url;
url << "/friends/" << id.toString() << "/response";
std::map<std::string, std::string> params{
std::make_pair("requester_id", requester.toString()),
std::make_pair("action", response)
};
std::string error;
APIRequestManager *manager = APIRequestManager::GetDefaultManager();
boost::optional<std::string> response = manager->Send(url.str(), "POST", params, error);
if (response.is_initialized()) {
Poco::JSON::Parser parser;
auto jsonObject = parser.parse(response.get()).extract<JSONObject::Ptr>();
return jsonObject->getValue<bool>("success");
}
else {
if (failure) {
failure(error);
}
return false;
}
});
}
示例4: 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 "";
}
}
示例5: 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;
}
示例6: FromJSONString
void BaseData::FromJSONString(const std::string &json)
{
Poco::JSON::Parser parser;
std::stringstream stream(json);
auto object = parser.parse(stream).extract<JSONObject::Ptr>();
return this->FromJSON(object);
}
示例7: dropEvent
void GraphDraw::dropEvent(QDropEvent *event)
{
const auto &byteArray = event->mimeData()->data("text/json/pothos_block");
Poco::JSON::Parser p; p.parse(std::string(byteArray.constData(), byteArray.size()));
const auto blockDesc = p.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();
this->getGraphEditor()->handleAddBlock(blockDesc, event->pos());
QWidget::dropEvent(event);
}
示例8: load
void load(Archive & ar, Poco::JSON::Object::Ptr &t, const unsigned int)
{
bool isNull = false;
ar >> isNull;
if (isNull) return;
std::string s; ar >> s;
Poco::JSON::Parser p; p.parse(s);
t = p.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();
}
示例9: exprToDynVar
//! Turn a simple expression into a type-specific container
static Poco::Dynamic::Var exprToDynVar(const std::string &expr)
{
try
{
Poco::JSON::Parser p; p.parse("["+expr+"]");
return p.getHandler()->asVar().extract<Poco::JSON::Array::Ptr>()->get(0);
}
catch (const Poco::Exception &){}
return expr;
}
示例10: clGetPlatformIDs
OpenClKernel::OpenClKernel(const std::string &deviceId, const std::string &portMarkup):
_localSize(1),
_globalFactor(1.0),
_productionFactor(1.0)
{
const auto colon = deviceId.find(":");
const auto platformIndex = Poco::NumberParser::parseUnsigned(deviceId.substr(0, colon));
const auto deviceIndex = Poco::NumberParser::parseUnsigned(deviceId.substr(colon+1));
/* Identify a platform */
cl_int err = 0;
cl_uint num_platforms = 0;
cl_platform_id platforms[64];
err = clGetPlatformIDs(64, platforms, &num_platforms);
if (err < 0) throw Pothos::Exception("OpenClKernel::clGetPlatformIDs()", clErrToStr(err));
if (platformIndex >= num_platforms) throw Pothos::Exception("OpenClKernel()", "platform index does not exist");
_platform = platforms[platformIndex];
/* Access a device */
cl_uint num_devices = 0;
cl_device_id devices[64];
err = clGetDeviceIDs(_platform, CL_DEVICE_TYPE_ALL, 64, devices, &num_devices);
if (err < 0) throw Pothos::Exception("OpenClKernel::clGetDeviceIDs()", clErrToStr(err));
if (deviceIndex >= num_devices) throw Pothos::Exception("OpenClKernel()", "device index does not exist");
_device = devices[deviceIndex];
/* Create context */
_context = lookupContextCache(_device);
/* Create ports */
_myDomain = "OpenCl_"+std::to_string(size_t(_device));
Poco::JSON::Parser p; p.parse(portMarkup);
const auto ports = p.getHandler()->asVar().extract<Poco::JSON::Array::Ptr>();
const auto inputs = ports->getArray(0);
const auto outputs = ports->getArray(1);
for (size_t i = 0; i < inputs->size(); i++)
{
this->setupInput(i, Pothos::DType("custom", inputs->getElement<int>(i)), _myDomain);
}
for (size_t i = 0; i < outputs->size(); i++)
{
this->setupOutput(i, Pothos::DType("custom", outputs->getElement<int>(i)), _myDomain);
}
this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, setSource));
this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, setLocalSize));
this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, getLocalSize));
this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, setGlobalFactor));
this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, getGlobalFactor));
this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, setProductionFactor));
this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, getProductionFactor));
}
示例11: getInfo
/***********************************************************************
* information aquisition
**********************************************************************/
static InfoResult getInfo(const std::string &uriStr)
{
InfoResult info;
POTHOS_EXCEPTION_TRY
{
auto env = Pothos::RemoteClient(uriStr).makeEnvironment("managed");
info.hostInfo = env->findProxy("Pothos/System/HostInfo").call<Pothos::System::HostInfo>("get");
info.numaInfo = env->findProxy("Pothos/System/NumaInfo").call<std::vector<Pothos::System::NumaInfo>>("get");
auto deviceInfo = env->findProxy("Pothos/Util/DeviceInfoUtils").call<std::string>("dumpJson");
Poco::JSON::Parser p; p.parse(deviceInfo);
info.deviceInfo = p.getHandler()->asVar().extract<Poco::JSON::Array::Ptr>();
}
POTHOS_EXCEPTION_CATCH(const Pothos::Exception &ex)
{
poco_error_f2(Poco::Logger::get("PothosGui.SystemInfoTree"), "Failed to query system info %s - %s", uriStr, ex.displayText());
}
示例12: ParseSpellList
/* Private */
void SpellData::ParseSpellList(std::string &response, TSpellDataList &items)
{
Poco::JSON::Parser parser;
auto parsed = parser.parse(response);
if (parsed.isArray()) {
auto spellObjects = parsed.extract<JSONArray::Ptr>();
for (int i = 0; i < spellObjects->size(); i++) {
JSONObject *object = spellObjects->getObject(i);
auto data = std::make_shared<SpellData>();
data->FromJSON(object);
items.push_back(data);
}
}
}
示例13: queryWorkStats
/***********************************************************************
* create JSON stats object
**********************************************************************/
static Poco::JSON::Object::Ptr queryWorkStats(const Pothos::Proxy &block)
{
//try recursive traversal
try
{
auto json = block.call<std::string>("queryJSONStats");
Poco::JSON::Parser p; p.parse(json);
return p.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();
}
catch (Pothos::Exception &) {}
//otherwise, regular block, query stats
auto actor = block.callProxy("get:_actor");
auto workStats = actor.call<Poco::JSON::Object::Ptr>("queryWorkStats");
Poco::JSON::Object::Ptr topStats(new Poco::JSON::Object());
topStats->set(block.call<std::string>("uid"), workStats);
return topStats;
}
示例14: GetSpellById
void SpellData::GetSpellById(const UUID &id, std::function<void(SpellDataPtr)> success, APIFailureCallback failure)
{
APIRequestManager *manager = APIRequestManager::GetDefaultManager();
std::stringstream url;
url << "/spell/" << id.toString();
manager->Send(url.str(), "GET", "", [success](std::istream &stream) {
Poco::JSON::Parser parser;
auto object = parser.parse(stream).extract<JSONObject::Ptr>();
auto data = std::make_shared<SpellData>();
data->FromJSON(object);
success(data);
}, [failure](const std::string &error) {
failure(error);
});
}
示例15: ifs
/***********************************************************************
* String/file parser - make JSON object from string
**********************************************************************/
static Poco::JSON::Object::Ptr parseJSONStr(const std::string &json)
{
//determine markup string or file path
bool isPath = false;
try {isPath = Poco::File(json).exists();}
catch (...){}
//parse the json string/file to a JSON object
Poco::JSON::Parser p;
if (isPath)
{
std::ifstream ifs(json);
p.parse(ifs);
}
else
{
p.parse(json);
}
return p.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();
}