本文整理汇总了C++中json::Value::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::begin方法的具体用法?C++ Value::begin怎么用?C++ Value::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::Value
的用法示例。
在下文中一共展示了Value::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CompareJson
void CompareJson(json::Value& lhs, json::Value& rhs, json::Value& output) {
std::string lstr, rstr;
if (rhs.type() != lhs.type()) return;
switch (lhs.type()) {
case json::Value::tString:
lstr = lhs.getString();
rstr = rhs.getString();
if (!lstr.empty() && lstr[0] == '$' && lstr.back() == '$') {
size_t slash = lstr.find('/');
std::string cat = lstr.substr(1, slash - 1);
std::string name = lstr.substr(slash + 1, lstr.length() - slash - 2);
output[cat][name] = rstr;
}
break;
case json::Value::tArray:
for (size_t i = 0; i < lhs.length(); ++i) {
if (i < rhs.length()) {
CompareJson(lhs[i], rhs[i], output);
}
}
break;
case json::Value::tObject:
for (auto it = lhs.begin(); it != lhs.end(); ++it) {
if (rhs.has(it.key())) {
CompareJson(*it, rhs[it.key()], output);
}
}
break;
}
}
示例2: buildSurfaceStruct
void FileParser::buildSurfaceStruct(const Json::Value& node, const Matrix4& matrix, unordered_map<string, SurfaceStruct>& structMap) const {
const Json::Value::const_iterator& v = node.begin();
string name = parseString((*v)["name"], "entity name");
SurfaceStruct s;
s.node = node;
s.obj2world = matrix;
structMap[name] = s;
}
示例3: deserializeItems
void ItemHandler::deserializeItems(Json::Value& root) {
Item* item;
for (Json::ValueIterator it = root.begin(); it != root.end(); it++) {
item = new Item();
item->deserialize(*it);
this->addItem(item);
}
}
示例4: deserializeEquippedItems
void ItemEquipper::deserializeEquippedItems(Json::Value& root) {
Item* item;
for (Json::ValueIterator it = root.begin(); it != root.end(); it++) {
item = new Item();
item->deserialize(*it);
_equippedItems[it.key().asInt()] = item;
}
}
示例5: ValueToValueVector
vector<Json::Value> ValueToValueVector(const Json::Value& value) {
vector<Json::Value> result;
if (value.isNull())
return result;
result.reserve(value.size());
for (auto it = value.begin(); it != value.end(); ++it)
result.push_back((*it));
return result;
}
示例6: parseAsDistributions
bool Model::parseAsDistributions(const Json::Value& root, const std::string& entryName) {
Json::Value array;
if (!ParserUtils::parseAsArray(root, entryName, &array)) return false;
for (Json::Value::iterator iter = array.begin(); iter != array.end(); iter++) {
if (!parseAsDistribution(*iter)) return false;
}
return true;
}
示例7: CWaveContactStatus
CWaveContactStatusCollection::CWaveContactStatusCollection(Json::Value & vRoot)
{
for (Json::Value::iterator iter = vRoot.begin(); iter != vRoot.end(); iter++)
{
CWaveContactStatus * lpStatus = new CWaveContactStatus(*iter);
m_vStatuses[lpStatus->GetEmailAddress()] = lpStatus;
}
}
示例8: fromJsonArray
void fromJsonArray(const Json::Value& parent, std::vector<T>& ref) {
ref.clear();
ref.reserve(parent.size());
for (Json::Value::const_iterator it = parent.begin(); it != parent.end(); ++it) {
T t;
fromJson(*it, t);
ref.push_back(t);
}
}
示例9: GetLangFromLCode
std::map<std::string, std::string> CLCodeHandler::GetTranslatorsDatabase(const std::string& strContributorType, const std::string& strProjectName,
const CResData& ResData)
{
std::map<std::string, std::string> mapOfContributors;
g_HTTPHandler.Cleanup();
g_HTTPHandler.ReInit();
for (itmapLCodes = m_mapLCodes.begin(); itmapLCodes != m_mapLCodes.end() ; itmapLCodes++)
{
std::string strLangCode = itmapLCodes->first;
std::string strTXLformat = ResData.TRX.LForm;
g_HTTPHandler.SetLocation("TRX");
g_HTTPHandler.SetProjectName(ResData.TRX.ProjectName);
g_HTTPHandler.SetResName("");
g_HTTPHandler.SetLCode(strLangCode);
g_HTTPHandler.SetFileName("ContributorList.json");
g_HTTPHandler.SetDataFile(true);
std::string strJson = g_HTTPHandler.GetURLToSTR("https://www.transifex.com/api/2/project/"+ strProjectName + "/language/" +
GetLangFromLCode(strLangCode, strTXLformat) + "/" + strContributorType + "/");
if (strJson.empty())
CLog::Log(logERROR, "CLCodeHandler::GetTranslatorsDatabase: error getting translator groups list for project: %s", strProjectName.c_str());
Json::Value root; // will contains the root value after parsing.
Json::Reader reader;
bool parsingSuccessful = reader.parse(strJson, root );
if ( !parsingSuccessful )
CLog::Log(logERROR, "CLCodeHandler::GetTranslatorsDatabase: no valid JSON data downloaded from Transifex");
const Json::Value JRoot = root;
const Json::Value JNames = JRoot[strContributorType];
CLog::Log(logPRINT, "\n%s%s%s ", KMAG, strLangCode.c_str(), RESET);
std::list<std::string> listNames;
for(Json::ValueIterator itr = JNames.begin() ; itr !=JNames.end() ; itr++)
{
Json::Value JValu = *itr;
std::string strName =JValu.asString();
if (strName == "")
CLog::Log(logERROR, "CJSONHandler::ParseTranslatorsDatabase: no valid JSON data downloaded from Github");
CLog::Log(logPRINT, "%s%s%s ", KCYN, strName.c_str(), RESET);
listNames.push_back(strName);
}
if (!listNames.empty())
mapOfContributors[strLangCode] = g_CharsetUtils.CleanTranslatorlist(strJson);
};
return mapOfContributors;
}
示例10: register_sensor
//Controlla l'esistenza di lfid (uno solo!) nel nodo json "sd" passato e in quelli in esso contenuti. Se non presenti in "rs" li registra usando "device_mac".
//La funzione ritorna:
//- ABORTED se tutti i nuovi sensori erano già registrati,
//- NICE se almeno un nuovo sensore è stato registrato perché non presente,
//- ERROR se almeno un sensore DOVEVA essere registrato ma la registrazione è fallita.
int register_sensor( const string device_mac, const Json::Value& node, const string rs )
{
int esito=ABORTED, inner_esito=ERROR;
string my_sensor_s;
string server_response_s;
//if you find an lfid code in the node..
if(node.isMember("lfid"))
{
//check if the sensor already exists:
my_sensor_s="\"local_feed_id\":"+node.get("lfid",0).asString();
if (rs.find(my_sensor_s) == std::string::npos) //NO
{
Json::Value new_sensor;
new_sensor["feed_id"]=0;
new_sensor["tags"]=node.get("tags",0).asString();
new_sensor["local_feed_id"]=node.get("lfid",0).asInt();
new_sensor["raspb_wifi_mac"]=device_mac;
esito=http_post_auth( params["report"].get("API_URL","").asString() + "devices/" +device_mac+"/feeds", new_sensor.toStyledString(), server_response_s);
//cerr<<"\nRISPOSTA SERVER SU REGISTER SENSOR "<<node.get("lfid",0).asString()<<":\n"<<server_response_s<<endl;
}
else //YES
{
cerr<<"This sensor was already registered... ";
esito=ABORTED;
}
}
//otherwise maybe the attributes may contain lfids..
else
{
for(Json::Value::iterator i = node.begin(); i !=node.end(); ++i)
{
Json::Value element = (*i);
//END CONDITION: if the attribute contains other attributes, recursively call myself
if(element.size()!=0)
{
inner_esito=register_sensor(device_mac, element, rs);
//PROPAGAZIONE STATO DI ERRORE
//esito deve riportare l'errore più grave avvenuto in una delle sottochiamate (inner_esito)
if(inner_esito!=esito && esito!=ERROR) //Verifica solo se ci sono stati cambiamenti (se esito era ERROR non ci importa più)
{
if(inner_esito != ABORTED) esito = inner_esito; //se esito era ABORTED, inner_esito avrà riportato un cambiamento: reg. effettuata (NICE) o fallita (ERROR)
//se esito era NICE, l'algoritmo va comunque bene.
}
}
}
}
//Esito riporterà:
//- ABORTED se i sensori erano già tutti registrati,
//- NICE se almeno una registrazione è avvenuta (TUTTE con successo),
//- ERROR se almeno una registrazione era necessaria MA è fallita.
return esito;
}
示例11: main
int main(int argc, char** argv) {
std::string script = "/xchip/gistic/Jeremiah/GIT/SeqLib/test.json";
const string document = GetScriptContents(script);
// set up JsonCPP reader and attempt to parse script
Json::Value root;
Json::Reader reader;
if ( !reader.parse(document, root) ) {
// use built-in error reporting mechanism to alert user what was wrong with the script
cerr << "bamtools filter ERROR: failed to parse script - see error message(s) below" << endl;
return false;
}
// see if root object contains multiple filters
const Json::Value filters = root["filters"];
cerr << " root size " << root.size() << std::endl;
cerr << " filters size " << filters.size() << std::endl;
// iterate over any filters found
int filterIndex = 0;
Json::Value::const_iterator filtersIter = filters.begin();
Json::Value::const_iterator filtersEnd = filters.end();
for ( ; filtersIter != filtersEnd; ++filtersIter, ++filterIndex ) {
Json::Value filter = (*filtersIter);
// convert filter index to string
string filterName;
// if id tag supplied
const Json::Value id = filter["id"];
if ( !id.isNull() )
filterName = id.asString();
// use array index
else {
stringstream convert;
convert << filterIndex;
filterName = convert.str();
}
cerr << "filter " << filterName << std::endl;
// create & parse filter
bool success = true;
success &= ParseFilterObject(filterName, filter);
}
/// make mini rules
cerr << " ... maing mini rules " << endl;
SeqLib::MiniRulesCollection mrc(script);
}
示例12: config
channel_config::channel_config(const Json::Value& value)
: config(value),
zero_delay(value["zero_delay"].asInt()),
one_delay(value["one_delay"].asInt()),
warm(value["warm"].asInt())
{
Json::Value msg = value["msg"];
bits.resize(msg.size());
std::transform(msg.begin(), msg.end(), bits.begin(), [](const Json::Value& v){return v.asBool();});
}
示例13: AddComponent
void ActorCreator::AddComponent( int32_t componentId, Json::Value& setters )
{
std::auto_ptr<PropertyLoaderBase<Component> > compLoader = mComponentLoaderFactory( componentId );
if( setters.isArray() && !setters.empty() )
{
compLoader->Load( *setters.begin() );
}
mComponentLoaders.insert( componentId, static_cast<ComponentLoader_t*>( compLoader.release() ) );
}
示例14: parseGeometry
void JsonParser::parseGeometry(Json::Value &root){
LOG_DEBUG("Parsing Geometry.");
bool foundGeometry = false;
for( Json::ValueIterator itr = root.begin() ; itr != root.end() ; itr++ ) {
std::string key = itr.key().asString();
if (key == "objects") {
foundGeometry = true;
// find object
Json::Value objRoot = *itr;
for( Json::ValueIterator objItr = objRoot.begin() ; objItr != objRoot.end() ; objItr++ ) {
LOG_DEBUG("Found object: " << objItr.key().asString());
// check if we're dealing with a light or mesh
std::string objType = getStringAttr("type", *objItr);
if (objType == "geometry"){
std::tr1::shared_ptr<AuroraObject> geo = getGeometry(*cameraTransform, *objItr, renderEnv);
objects.push_back(geo);
}
else if (objType == "light"){
Light* light = getLight(*cameraTransform, *objItr, (*renderEnv->globals)[LightSamples], renderEnv);
lights.push_back(light);
}
else if (objType == "envlight"){
Light* light = getEnvLight(*cameraTransform, *objItr, (*renderEnv->globals)[LightSamples], renderEnv);
lights.push_back(light);
}
else {
LOG_WARNING("Unknown object type found: " << objType);
}
}
// apply to globals
LOG_DEBUG("Done parsing Geometry.\n");
break;
}
}
if (!foundGeometry) {
LOG_WARNING("No geometry found in file " << filename << ".");
}
}
示例15: streamMetaInformationCb
static void streamMetaInformationCb(hbm::streaming::StreamClient& stream, const std::string& method, const Json::Value& params)
{
if (method == hbm::streaming::META_METHOD_AVAILABLE) {
// simply subscibe all signals that become available.
hbm::streaming::signalReferences_t signalReferences;
for (Json::ValueConstIterator iter = params.begin(); iter!= params.end(); ++iter) {
const Json::Value& element = *iter;
signalReferences.push_back(element.asString());
}
try {
stream.subscribe(signalReferences);
std::cout << __FUNCTION__ << "the following " << signalReferences.size() << " signal(s) were subscribed: ";
} catch(const std::runtime_error& e) {
std::cerr << __FUNCTION__ << "error '" << e.what() << "' subscribing the following signal(s): ";
}
for(hbm::streaming::signalReferences_t::const_iterator iter=signalReferences.begin(); iter!=signalReferences.end(); ++iter) {
std::cout << "'" << *iter << "' ";
}
std::cout << std::endl;
} else if(method==hbm::streaming::META_METHOD_UNAVAILABLE) {
std::cout << __FUNCTION__ << "the following signal(s) are not available anyore: ";
for (Json::ValueConstIterator iter = params.begin(); iter!= params.end(); ++iter) {
const Json::Value& element = *iter;
std::cout << element.asString() << ", ";
}
std::cout << std::endl;
} else if(method==hbm::streaming::META_METHOD_ALIVE) {
// We do ignore this. We are using TCP keep alive in order to detect communication problems.
} else if(method==hbm::streaming::META_METHOD_FILL) {
if(params.empty()==false) {
unsigned int fill = params[0u].asUInt();
if(fill>25) {
std::cout << stream.address() << ": ring buffer fill level is " << params[0u].asUInt() << "%" << std::endl;
}
}
} else {
std::cout << __FUNCTION__ << " " << method << " " << Json::FastWriter().write(params) << std::endl;
}
}