本文整理汇总了C++中JSONNode::find方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONNode::find方法的具体用法?C++ JSONNode::find怎么用?C++ JSONNode::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONNode
的用法示例。
在下文中一共展示了JSONNode::find方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseAll
bool JSONReader::parseAll(const std::string& text, IdType& nextId, std::string& filepath, std::string& checksum,
std::vector<std::shared_ptr<MetadataStream::VideoSegment>>& segments,
std::vector<std::shared_ptr<MetadataSchema>>& schemas,
std::vector<std::shared_ptr<MetadataInternal>>& metadata)
{
if(text.empty())
{
VMF_LOG_ERROR("Empty input JSON string");
return false;
}
schemas.clear();
metadata.clear();
JSONNode root;
try
{
root = libjson::parse(text);
}
catch(...)
{
VMF_LOG_ERROR("Can't get JSON root");
return false;
}
if(root.size() != 1)
{
VMF_LOG_ERROR("More than one JSON root");
return false;
}
JSONNode localRootNode = root[0];
if( localRootNode.name() == TAG_VMF )
{
auto nextIdIter = localRootNode.find(ATTR_VMF_NEXTID);
if(nextIdIter != localRootNode.end() )
nextId = nextIdIter->as_int();
auto filepathIter = localRootNode.find(ATTR_VMF_FILEPATH);
if(filepathIter != localRootNode.end() )
filepath = filepathIter->as_string();
auto checksumIter = localRootNode.find(ATTR_VMF_CHECKSUM);
if(checksumIter != localRootNode.end() )
checksum = checksumIter->as_string();
if(!parseVideoSegments(text, segments))
return false;
if(!parseSchemas(text, schemas))
return false;
if(!parseMetadata(text, schemas, metadata))
return false;
}
else
{
VMF_LOG_ERROR("Root JSON element isn't 'vmf'");
return false;
}
return true;
}
示例2: loadJSON
bool Programmer::loadJSON(JSONNode data) {
auto devices = data.find("devices");
if (devices == data.end()) {
Logger::log(ERR, "No devices found in Programmer");
return false;
}
auto it = devices->begin();
while (it != devices->end()) {
Device* device = new Device(it->name(), *it);
// We're overwriting data here, so make sure to actually delete the old data.
// if there is any
if (m_devices.count(device->getId()) > 0)
delete m_devices[device->getId()];
m_devices[device->getId()] = device;
it++;
}
auto c = data.find("captured");
if (c == data.end()) {
Logger::log(WARN, "No captured set found in Programmer");
captured = DeviceSet(m_rig);
}
else {
captured = DeviceSet(m_rig, *c);
}
return true;
}
示例3: Test
bool Condition::Test(JSONNode row, bool oldValue)
{
bool result;
string operand1Value = operand1IsConstant ? operand1 : row.find(operand1)->as_string();
string operand2Value = operand2IsConstant ? operand2 : row.find(operand2)->as_string();
//cout << "operand1 " << operand1Value << endl;
//cout << "operand2 " << operand2Value << endl;
//cout << "mode " << (mode == 0 ? "and" : "or") << endl;
//cout << "operator " << (operatorMode == 0 ? "==" : "!=") << endl;
switch (operatorMode)
{
case 0 :
result = operand1Value == operand2Value;
break;
case 1 :
result = operand1Value != operand2Value;
break;
}
switch (mode)
{
case 0 :
return oldValue && result;
case 1 :
return oldValue || result;
}
return false;
}
示例4:
Keyframe::Keyframe(JSONNode node) {
auto jt = node.find("t");
if (jt == node.end()) {
Logger::log(ERR, "Keyframe has no assigned time. Defaulting to 0.");
t = 0;
}
else {
t = jt->as_int();
}
auto v = node.find("val");
if (v == node.end()) {
val = nullptr;
}
else {
val = shared_ptr<LumiverseType>(LumiverseTypeUtils::loadFromJSON(*v));
}
auto ucs = node.find("useCurrentState");
if (ucs == node.end()) {
useCurrentState = false;
}
else {
useCurrentState = ucs->as_bool();
}
auto tid = node.find("timelineID");
if (tid == node.end()) {
timelineID = "";
}
else {
timelineID = tid->as_string();
}
auto to = node.find("timelineOffset");
if (to == node.end()) {
timelineOffset = 0;
}
else {
timelineOffset = to->as_int();
}
}
示例5: parseVideoSegmentFromNode
static std::shared_ptr<MetadataStream::VideoSegment> parseVideoSegmentFromNode(JSONNode& segmentNode)
{
auto segmentTitleIter = segmentNode.find(ATTR_SEGMENT_TITLE);
auto segmentFPSIter = segmentNode.find(ATTR_SEGMENT_FPS);
auto segmentTimeIter = segmentNode.find(ATTR_SEGMENT_TIME);
auto segmentDurationIter = segmentNode.find(ATTR_SEGMENT_DURATION);
auto segmentWidthIter = segmentNode.find(ATTR_SEGMENT_WIDTH);
auto segmentHeightIter = segmentNode.find(ATTR_SEGMENT_HEIGHT);
if(segmentTitleIter == segmentNode.end())
VMF_EXCEPTION(vmf::InternalErrorException, "JSON element has no title");
if(segmentFPSIter == segmentNode.end())
VMF_EXCEPTION(vmf::InternalErrorException, "JSON element has no fps value");
if(segmentTimeIter == segmentNode.end())
VMF_EXCEPTION(vmf::InternalErrorException, "JSON element has no time value");
std::string title = segmentTitleIter->as_string();
double fps = segmentFPSIter->as_float();
long long timestamp = segmentTimeIter->as_int();
if(title.empty())
VMF_EXCEPTION(vmf::InternalErrorException, "JSON element has invalid title");
if(fps <= 0)
VMF_EXCEPTION(vmf::InternalErrorException, "JSON element has invalid fps value");
if(timestamp < 0)
VMF_EXCEPTION(vmf::InternalErrorException, "JSON element has invalid time value");
std::shared_ptr<MetadataStream::VideoSegment> spSegment(new MetadataStream::VideoSegment(title, fps, timestamp));
if(segmentDurationIter != segmentNode.end())
{
long long duration = segmentDurationIter->as_int();
if(duration > 0)
spSegment->setDuration(duration);
}
if(segmentWidthIter != segmentNode.end() && segmentHeightIter != segmentNode.end())
{
long width = segmentWidthIter->as_int(), height = segmentHeightIter->as_int();
if(width > 0 && height > 0)
spSegment->setResolution(width, height);
}
return spSegment;
}
示例6: if
static std::shared_ptr<MetadataSchema> parseSchemaFromNode(JSONNode& schemaNode)
{
std::shared_ptr<vmf::MetadataSchema> spSchema;
auto schemaNameIter = schemaNode.find(ATTR_NAME);
auto schemaAuthorIter = schemaNode.find(ATTR_SCHEMA_AUTHOR);
if(schemaNameIter != schemaNode.end())
{
if(schemaAuthorIter != schemaNode.end())
spSchema = std::make_shared<vmf::MetadataSchema>(schemaNameIter->as_string(), schemaAuthorIter->as_string());
else
spSchema = std::make_shared<vmf::MetadataSchema>(schemaNameIter->as_string());
}
else
VMF_EXCEPTION(IncorrectParamException, "Schema has no name");
auto descsArrayIter = schemaNode.find(TAG_DESCRIPTIONS_ARRAY);
if(descsArrayIter == schemaNode.end())
VMF_EXCEPTION(IncorrectParamException, "Can't find descriptions-array JSON node");
std::shared_ptr<vmf::MetadataDesc> spDesc;
for(auto descNode = descsArrayIter->begin(); descNode != descsArrayIter->end(); descNode++)
{
auto descNameIter = descNode->find(ATTR_NAME);
if(descNameIter == descNode->end())
VMF_EXCEPTION(IncorrectParamException, "Description has no name");
auto fieldsArrayIter = descNode->find(TAG_FIELDS_ARRAY);
if(fieldsArrayIter == descNode->end())
VMF_EXCEPTION(IncorrectParamException, "Description has no fields array");
std::vector<FieldDesc> vFields;
for(auto fieldNode = fieldsArrayIter->begin(); fieldNode != fieldsArrayIter->end(); fieldNode++)
{
auto fieldNameIter = fieldNode->find(ATTR_NAME);
auto fieldTypeIter = fieldNode->find(ATTR_FIELD_TYPE);
if(fieldNameIter == fieldNode->end() || fieldTypeIter == fieldNode->end() )
VMF_EXCEPTION(IncorrectParamException, "Field has no 'name' or 'type' attribute");
vmf::Variant::Type field_type = Variant::typeFromString(fieldTypeIter->as_string());
bool field_optional = false;
auto fieldsOptionalityIter = fieldNode->find(ATTR_FIELD_OPTIONAL);
if(fieldsOptionalityIter != fieldNode->end())
{
if(fieldsOptionalityIter->as_string() == "true")
field_optional = true;
else if (fieldsOptionalityIter->as_string() == "false")
field_optional = false;
else
VMF_EXCEPTION(vmf::IncorrectParamException, "Invalid value of boolean attribute 'optional'");
}
vFields.push_back(FieldDesc(fieldNameIter->as_string(), field_type, field_optional));
}
auto refsArrayIter = descNode->find(TAG_METADATA_REFERENCES_ARRAY);
if (refsArrayIter == descNode->end())
VMF_EXCEPTION(IncorrectParamException, "Description has no references array");
std::vector<std::shared_ptr<ReferenceDesc>> vReferences;
for (auto refNode = refsArrayIter->begin(); refNode != refsArrayIter->end(); refNode++)
{
auto refNameIter = refNode->find(ATTR_NAME);
if (refNameIter == refNode->end())
VMF_EXCEPTION(IncorrectParamException, "Field has no 'name' attribute");
auto refUniqueIter = refNode->find(ATTR_REFERENCE_UNIQUE);
bool isUnique = false;
if (refUniqueIter != refNode->end())
{
if (refUniqueIter->as_string() == "true")
isUnique = true;
else if (refUniqueIter->as_string() == "false")
isUnique = false;
else
VMF_EXCEPTION(vmf::IncorrectParamException, "Invalid value of boolean attribute 'isUnique'");
}
auto refCustomIter = refNode->find(ATTR_REFERENCE_CUSTOM);
bool isCustom = false;
if (refCustomIter != refNode->end())
{
if (refCustomIter->as_string() == "true")
isCustom = true;
else if (refCustomIter->as_string() == "false")
isCustom = false;
else
VMF_EXCEPTION(vmf::IncorrectParamException, "Invalid value of boolean attribute 'isCustom'");
}
vReferences.emplace_back(std::make_shared<ReferenceDesc>(refNameIter->as_string(), isUnique, isCustom));
}
spDesc = std::make_shared<vmf::MetadataDesc>(descNameIter->as_string(), vFields, vReferences);
spSchema->add(spDesc);
}
return spSchema;
}
示例7: parseMetadataFromNode
static std::shared_ptr<MetadataInternal> parseMetadataFromNode(JSONNode& metadataNode, const std::vector<std::shared_ptr<MetadataSchema>>& schemas)
{
auto schemaIter = metadataNode.find(ATTR_METADATA_SCHEMA);
auto descIter = metadataNode.find(ATTR_METADATA_DESCRIPTION);
auto idIter = metadataNode.find(ATTR_ID);
if(schemaIter == metadataNode.end() || descIter == metadataNode.end() || idIter == metadataNode.end())
VMF_EXCEPTION(vmf::IncorrectParamException, "Metadata item has no schema name, description name or id");
auto schema = schemas.begin();
for(; schema != schemas.end(); schema++)
if((*schema)->getName() == schemaIter->as_string())
break;
if(schema == schemas.end())
VMF_EXCEPTION(vmf::IncorrectParamException, "Unknown schema for metadata item");
std::shared_ptr<MetadataDesc> spDesc;
if( (spDesc = (*schema)->findMetadataDesc(descIter->as_string())) == nullptr)
VMF_EXCEPTION(vmf::IncorrectParamException, "Unknown description for metadata item");
std::shared_ptr<MetadataInternal> spMetadataInternal(new MetadataInternal(spDesc));
spMetadataInternal->setId(idIter->as_int());
auto frameIdxLoIter = metadataNode.find(ATTR_METADATA_FRAME_IDX_LO);
auto frameIdxHiIter = metadataNode.find(ATTR_METADATA_FRAME_IDX_HI);
auto nFramesLoIter = metadataNode.find(ATTR_METADATA_NFRAMES_LO);
auto nFramesHiIter = metadataNode.find(ATTR_METADATA_NFRAMES_HI);
auto timeLoIter = metadataNode.find(ATTR_METADATA_TIMESTAMP_LO);
auto timeHiIter = metadataNode.find(ATTR_METADATA_TIMESTAMP_HI);
auto durationLoIter = metadataNode.find(ATTR_METADATA_DURATION_LO);
auto durationHiIter = metadataNode.find(ATTR_METADATA_DURATION_HI);
if (frameIdxLoIter != metadataNode.end() && frameIdxHiIter != metadataNode.end())
{
unsigned long lo = frameIdxLoIter->as_int();
unsigned long hi = frameIdxHiIter->as_int();
long long frmIdx = ((long long)hi << 32) | lo;
if (nFramesLoIter != metadataNode.end() && nFramesHiIter != metadataNode.end())
{
unsigned long lo = nFramesLoIter->as_int();
unsigned long hi = nFramesHiIter->as_int();
long long numFrm = ((long long)hi << 32) | lo;
spMetadataInternal->setFrameIndex(frmIdx, numFrm);
}
else
spMetadataInternal->setFrameIndex(frmIdx);
}
if (timeLoIter != metadataNode.end() && timeHiIter != metadataNode.end())
{
unsigned long lo = timeLoIter->as_int();
unsigned long hi = timeHiIter->as_int();
long long time = ((long long)hi << 32) | lo;
if (durationLoIter != metadataNode.end() && durationHiIter != metadataNode.end())
{
unsigned long lo = durationLoIter->as_int();
unsigned long hi = durationHiIter->as_int();
long long dur = ((long long)hi << 32) | lo;
spMetadataInternal->setTimestamp(time, dur);
}
else
spMetadataInternal->setTimestamp(time);
}
auto metadataFieldsArrayIter = metadataNode.find(TAG_FIELDS_ARRAY);
if(metadataFieldsArrayIter == metadataNode.end())
VMF_EXCEPTION(vmf::IncorrectParamException, "No metadata fields array");
for(auto fieldNode = metadataFieldsArrayIter->begin(); fieldNode != metadataFieldsArrayIter->end(); fieldNode++)
{
FieldDesc fieldDesc;
auto fieldNameIter = fieldNode->find(ATTR_NAME);
auto fieldValueIter = fieldNode->find(ATTR_VALUE);
if(fieldNameIter == fieldNode->end() || fieldValueIter == fieldNode->end() )
VMF_EXCEPTION(vmf::IncorrectParamException, "Missing field name or field value");
vmf::Variant field_value;
spDesc->getFieldDesc(fieldDesc, fieldNameIter->as_string());
field_value.fromString(fieldDesc.type, fieldValueIter->as_string());
spMetadataInternal->setFieldValue(fieldNameIter->as_string(), field_value);
}
auto referencesArrayIter = metadataNode.find(TAG_METADATA_REFERENCES_ARRAY);
if(referencesArrayIter != metadataNode.end())
{
for(auto referenceNode = referencesArrayIter->begin(); referenceNode != referencesArrayIter->end(); referenceNode++)
{
auto referenceIdIter = referenceNode->find(ATTR_ID);
if(referenceIdIter == referenceNode->end()) VMF_EXCEPTION(vmf::IncorrectParamException, "Missing reference 'id'");
auto referenceNameIter = referenceNode->find(ATTR_NAME);
if(referenceNameIter == referenceNode->end()) VMF_EXCEPTION(vmf::IncorrectParamException, "Missing reference 'name'");
spMetadataInternal->vRefs.push_back(std::make_pair(IdType(referenceIdIter->as_int()), referenceNameIter->as_string()));
}
}
return spMetadataInternal;
}
示例8: jsonBoolProp
inline bool jsonBoolProp(JSONNode &n, const char* prop){
JSONNode::iterator i = n.find(prop);
if (i != n.end() && i->type() == JSON_BOOL) return i->as_bool();
else throw ErrorStringException(string("JSON missing bool property: ") + prop);
}
示例9: makeStreamListener
listener_ptr makeStreamListener(StreamingDevice* dev, ClientConn* client, JSONNode &n){
std::auto_ptr<WSStreamListener> listener(new WSStreamListener());
listener->id = jsonIntProp(n, "id");
listener->device = dev;
listener->client = client;
listener->decimateFactor = jsonIntProp(n, "decimateFactor", 1);
// Prevent divide by 0
if (listener->decimateFactor == 0) listener->decimateFactor = 1;
int start = jsonIntProp(n, "start", -1);
if (start < 0){ // Negative indexes are relative to latest sample
start = (dev->buffer_max()) + start + 1;
}
if (start < 0) listener->index = 0;
else listener->index = start;
listener->count = jsonIntProp(n, "count");
JSONNode j_streams = n.at("streams");
for(JSONNode::iterator i=j_streams.begin(); i!=j_streams.end(); i++){
listener->streams.push_back(
dev->findStream(
jsonStringProp(*i, "channel"),
jsonStringProp(*i, "stream")));
}
JSONNode::iterator t = n.find("trigger");
if (t != n.end() && (t->type()) == JSON_NODE){
JSONNode &trigger = *t;
string type = jsonStringProp(trigger, "type", "in");
if (type == "in"){
listener->triggerType = INSTREAM;
listener->triggerLevel = jsonFloatProp(trigger, "level");
listener->triggerStream = dev->findStream(
jsonStringProp(trigger, "channel"),
jsonStringProp(trigger, "stream"));
}else if (type == "out"){
listener->triggerType = OUTSOURCE;
listener->triggerChannel = dev->channelById(jsonStringProp(trigger, "channel"));
if (!listener->triggerChannel) throw ErrorStringException("Trigger channel not found");
}else{
throw ErrorStringException("Invalid trigger type");
}
listener->triggerRepeat = jsonBoolProp(trigger, "repeat", true);
listener->triggerHoldoff = jsonIntProp(trigger, "holdoff", 0);
listener->triggerOffset = jsonIntProp(trigger, "offset", 0);
if (listener->triggerOffset<0 && -listener->triggerOffset >= listener->triggerHoldoff){
// Prevent big negative offsets that could cause infinite loops
listener->triggerHoldoff = -listener->triggerOffset;
}
listener->triggerForce = jsonIntProp(trigger, "force", 0);
listener->triggerForceIndex = listener->index + listener->triggerForce;
}
return listener_ptr(listener.release());
}
示例10: jsonFloatProp
inline double jsonFloatProp(JSONNode &n, const char* prop, double def){
JSONNode::iterator i = n.find(prop);
if (i != n.end() && i->type() == JSON_NUMBER) return i->as_float();
else return def;
}
示例11: jsonIntProp
inline int jsonIntProp(JSONNode &n, const char* prop, int def){
JSONNode::iterator i = n.find(prop);
if (i != n.end() && i->type() == JSON_NUMBER) return i->as_int();
else return def;
}
示例12: jsonStringProp
inline string jsonStringProp(JSONNode &n, const char* prop, string def){
JSONNode::iterator i = n.find(prop);
if (i != n.end() && i->type() == JSON_STRING) return i->as_string();
else return def;
}
示例13: runtime_error
void xmm::TrainingSet::from_json(JSONNode root)
{
if (!owns_data)
throw std::runtime_error("Cannot read Training Set with Shared memory");
try {
if (root.type() != JSON_NODE)
throw JSONException("Wrong type: was expecting 'JSON_NODE'", root.name());
JSONNode::const_iterator root_it = root.begin();
// Get Number of modalities
root_it = root.find("bimodal");
if (root_it == root.end())
throw JSONException("JSON Node is incomplete", root_it->name());
if (root_it->type() != JSON_BOOL)
throw JSONException("Wrong type for node 'bimodal': was expecting 'JSON_BOOL'", root_it->name());
if(bimodal_ != root_it->as_bool()) {
if (bimodal_)
throw JSONException("Trying to read an unimodal model in a bimodal model.", root.name());
else
throw JSONException("Trying to read a bimodal model in an unimodal model.", root.name());
}
// Get Dimension
root_it = root.find("dimension");
if (root_it == root.end())
throw JSONException("JSON Node is incomplete", root_it->name());
if (root_it->type() != JSON_NUMBER)
throw JSONException("Wrong type for node 'dimension': was expecting 'JSON_NUMBER'", root_it->name());
dimension_ = static_cast<unsigned int>(root_it->as_int());
// Get Input Dimension if bimodal_
if (bimodal_){
root_it = root.find("dimension_input");
if (root_it == root.end())
throw JSONException("JSON Node is incomplete", root_it->name());
if (root_it->type() != JSON_NUMBER)
throw JSONException("Wrong type for node 'dimension_input': was expecting 'JSON_NUMBER'", root_it->name());
dimension_input_ = static_cast<unsigned int>(root_it->as_int());
}
// Get Column Names
column_names_.assign(dimension_, "");
root_it = root.find("column_names");
if (root_it != root.end()) {
if (root_it->type() != JSON_ARRAY)
throw JSONException("Wrong type for node 'column_names': was expecting 'JSON_ARRAY'", root_it->name());
json2vector(*root_it, column_names_, dimension_);
}
// Get Size: Number of Phrases
root_it = root.find("size");
if (root_it == root.end())
throw JSONException("JSON Node is incomplete", root_it->name());
if (root_it->type() != JSON_NUMBER)
throw JSONException("Wrong type for node 'size': was expecting 'JSON_NUMBER'", root_it->name());
unsigned int ts_size = static_cast<unsigned int>(root_it->as_int());
// Get Default label
root_it = root.find("defaultlabel");
if (root_it == root.end())
throw JSONException("JSON Node is incomplete", root_it->name());
if (root_it->type() != JSON_NODE)
throw JSONException("Wrong type for node 'defaultlabel': was expecting 'JSON_NODE'", root_it->name());
defaultLabel_.from_json(*root_it);
// Get Phrases
phrases.clear();
phraseLabels.clear();
root_it = root.find("phrases");
if (root_it == root.end())
throw JSONException("JSON Node is incomplete", root_it->name());
if (root_it->type() != JSON_ARRAY)
throw JSONException("Wrong type for node 'phrases': was expecting 'JSON_ARRAY'", root_it->name());
for (unsigned int i=0 ; i<ts_size ; i++)
{
JSONNode::const_iterator array_it = (*root_it)[i].end();
// Get Index
array_it = (*root_it)[i].find("index");
if (array_it == (*root_it)[i].end())
throw JSONException("JSON Node is incomplete", array_it->name());
if (array_it->type() != JSON_NUMBER)
throw JSONException("Wrong type for node 'index': was expecting 'JSON_NUMBER'", array_it->name());
unsigned int phraseIndex = static_cast<unsigned int>(array_it->as_int());
// Get Label
array_it = (*root_it)[i].find("label");
if (array_it == (*root_it)[i].end())
throw JSONException("JSON Node is incomplete", array_it->name());
if (array_it->type() != JSON_NODE)
throw JSONException("Wrong type for node 'label': was expecting 'JSON_NODE'", array_it->name());
phraseLabels[phraseIndex].from_json(*array_it);
updateLabelList();
// Get Phrase Content
array_it = (*root_it)[i].find("Phrase");
if (array_it == (*root_it)[i].end())
throw JSONException("JSON Node is incomplete", array_it->name());
if (array_it->type() != JSON_NODE)
throw JSONException("Wrong type for node 'Phrase': was expecting 'JSON_NODE'", array_it->name());
//.........这里部分代码省略.........