本文整理汇总了C++中JsonNode类的典型用法代码示例。如果您正苦于以下问题:C++ JsonNode类的具体用法?C++ JsonNode怎么用?C++ JsonNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JsonNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadPatches
static JsonNode loadPatches(std::string path)
{
JsonNode node = JsonUtils::assembleFromFiles(path);
for (auto & entry : node.Struct())
JsonUtils::validate(entry.second, "vcmi:mapHeader", "patch for " + entry.first);
return node;
}
示例2: loadJsonOrMax
static ui32 loadJsonOrMax(const JsonNode & input)
{
if (input.isNull())
return std::numeric_limits<ui32>::max();
else
return input.Float();
}
示例3: JsonNode
JsonNode JsonReader::ParseArray() {
JsonNode object = JsonNode(JsonNode::Type::Array);
bool end = false;
/* Verify we're parsing an array */
if (*m_data == '[') m_data++;
while (!end) {
/* Use the index value as the key name */
object[object.ChildCount()] = this->ParseValue();
while (*m_data != ',' && *m_data != ']' && !EndOfFile()) m_data++;
switch (*m_data) {
case ',':
m_data++;
break;
case ']':
end = true;
m_data++;
break;
default:
PrintError("Syntax Error : ',' , ']' were expected. ");
end = true;
break;
};
}
return object;
}
示例4:
void CContentHandler::ContentTypeHandler::preloadModData(std::string modName, std::vector<std::string> fileList)
{
JsonNode data = JsonUtils::assembleFromFiles(fileList);
data.setMeta(modName);
ModInfo & modInfo = modData[modName];
for(auto entry : data.Struct())
{
size_t colon = entry.first.find(':');
if (colon == std::string::npos)
{
// normal object, local to this mod
modInfo.modData[entry.first].swap(entry.second);
}
else
{
std::string remoteName = entry.first.substr(0, colon);
std::string objectName = entry.first.substr(colon + 1);
// patching this mod? Send warning and continue - this situation can be handled normally
if (remoteName == modName)
logGlobal->warnStream() << "Redundant namespace definition for " << objectName;
JsonNode & remoteConf = modData[remoteName].patches[objectName];
JsonUtils::merge(remoteConf, entry.second);
}
}
}
示例5: extractArray
bool JsonParser::extractArray(JsonNode &node)
{
pos++;
node.setType(JsonNode::DATA_VECTOR);
if (!extractWhitespace())
return false;
//Empty array found
if (input[pos] == ']')
{
pos++;
return true;
}
while (true)
{
//NOTE: currently 50% of time is this vector resizing.
//May be useful to use list during parsing and then swap() all items to vector
node.Vector().resize(node.Vector().size()+1);
if (!extractElement(node.Vector().back(), ']'))
return false;
if (input[pos] == ']')
{
pos++;
return true;
}
}
}
示例6: loadSettings
void CSettingsView::loadSettings()
{
int resX = settings["video"]["screenRes"]["width"].Float();
int resY = settings["video"]["screenRes"]["height"].Float();
int resIndex = ui->comboBoxResolution->findText(QString("%1x%2").arg(resX).arg(resY));
ui->comboBoxResolution->setCurrentIndex(resIndex);
ui->comboBoxFullScreen->setCurrentIndex(settings["video"]["fullscreen"].Bool());
int neutralAIIndex = ui->comboBoxNeutralAI->findText(QString::fromUtf8(settings["server"]["neutralAI"].String().c_str()));
int playerAIIndex = ui->comboBoxPlayerAI->findText(QString::fromUtf8(settings["server"]["playerAI"].String().c_str()));
ui->comboBoxNeutralAI->setCurrentIndex(neutralAIIndex);
ui->comboBoxPlayerAI->setCurrentIndex(playerAIIndex);
ui->spinBoxNetworkPort->setValue(settings["server"]["port"].Float());
ui->comboBoxEnableMods->setCurrentIndex(settings["launcher"]["enableInstalledMods"].Bool());
// all calls to plainText will trigger textChanged() signal overwriting config. Create backup before editing widget
JsonNode urls = settings["launcher"]["repositoryURL"];
ui->plainTextEditRepos->clear();
for (auto entry : urls.Vector())
ui->plainTextEditRepos->appendPlainText(QString::fromUtf8(entry.String().c_str()));
ui->lineEditUserDataDir->setText(QString::fromUtf8(VCMIDirs::get().userDataPath().c_str()));
QStringList dataDirs;
for (auto string : VCMIDirs::get().dataPaths())
dataDirs += QString::fromUtf8(string.c_str());
ui->lineEditGameDir->setText(dataDirs.join(':'));
}
示例7: extractString
bool JsonParser::extractString(JsonNode &node)
{
std::string str;
if (!extractString(str))
return false;
node.setType(JsonNode::DATA_STRING);
node.String() = str;
return true;
}
示例8: selectNextID
si32 selectNextID(const JsonNode & fixedID, const Map & map, si32 defaultID)
{
if (!fixedID.isNull() && fixedID.Float() < defaultID)
return fixedID.Float(); // H3M object with fixed ID
if (map.empty())
return defaultID; // no objects loaded, keep gap for H3M objects
if (map.rbegin()->first >= defaultID)
return map.rbegin()->first + 1; // some modded objects loaded, return next available
return defaultID; // some H3M objects loaded, first modded found
}
示例9: handleData
void CModHandler::handleData(Handler handler, const JsonNode & source, std::string listName, std::string schemaName)
{
JsonNode config = JsonUtils::assembleFromFiles(source[listName].convertTo<std::vector<std::string> >());
for(auto & entry : config.Struct())
{
if (!entry.second.isNull()) // may happens if mod removed object by setting json entry to null
{
JsonUtils::validate(entry.second, schemaName, entry.first);
handler->load(entry.first, entry.second);
}
}
}
示例10: switch
void JsonWriter::writeNode(const JsonNode &node)
{
switch(node.getType())
{
break; case JsonNode::DATA_NULL:
out << "null";
break; case JsonNode::DATA_BOOL:
if (node.Bool())
out << "true";
else
out << "false";
break; case JsonNode::DATA_FLOAT:
out << node.Float();
break; case JsonNode::DATA_STRING:
writeString(node.String());
break; case JsonNode::DATA_VECTOR:
out << "[" << "\n";
writeContainer(node.Vector().begin(), node.Vector().end());
out << prefix << "]";
break; case JsonNode::DATA_STRUCT:
out << "{" << "\n";
writeContainer(node.Struct().begin(), node.Struct().end());
out << prefix << "}";
}
}
示例11: schema
void SettingsStorage::invalidateNode(const std::vector<std::string> &changedPath)
{
for(SettingsListener * listener : listeners)
listener->nodeInvalidated(changedPath);
JsonNode savedConf = config;
JsonNode schema(ResourceID("config/schemas/settings.json"));
savedConf.Struct().erase("session");
JsonUtils::minimize(savedConf, "vcmi:settings");
std::ofstream file(*CResourceHandler::get()->getResourceName(ResourceID("config/settings.json")), std::ofstream::trunc);
file << savedConf;
}
示例12: check
std::string check(const JsonNode & schema, const JsonNode & data, ValidationData & validator)
{
const TValidatorMap & knownFields = getKnownFieldsFor(data.getType());
std::string errors;
for(auto & entry : schema.Struct())
{
auto checker = knownFields.find(entry.first);
if (checker != knownFields.end())
errors += checker->second(validator, schema, entry.second, data);
//else
// errors += validator.makeErrorMessage("Unknown entry in schema " + entry.first);
}
return errors;
}
示例13: ResourceID
CMappedFileLoader::CMappedFileLoader(const std::string & mountPoint, const JsonNode &config)
{
for(auto entry : config.Struct())
{
fileList[ResourceID(mountPoint + entry.first)] = ResourceID(mountPoint + entry.second.String());
}
}
示例14: requestIdentifier
void CIdentifierStorage::requestIdentifier(const JsonNode & name, const std::function<void(si32)> & callback)
{
auto pair = splitString(name.String(), ':'); // remoteScope:<type.name>
auto pair2 = splitString(pair.second, '.'); // type.name
requestIdentifier(ObjectCallback(name.meta, pair.first, pair2.first, pair2.second, callback));
}
示例15: load
void CBonusTypeHandler::load(const JsonNode& config)
{
for(auto & node : config.Struct())
{
auto it = bonusNameMap.find(node.first);
if(it == bonusNameMap.end())
{
//TODO: new bonus
// CBonusType bt;
// loadItem(node.second, bt);
//
// auto new_id = bonusTypes.size();
//
// bonusTypes.push_back(bt);
logBonus->warnStream() << "Adding new bonuses not implemented (" << node.first << ")";
}
else
{
CBonusType& bt = bonusTypes[it->second];
loadItem(node.second, bt);
logBonus->traceStream() << "Loaded bonus type " << node.first;
}
}
}