本文整理汇总了C++中JsonValue::IsString方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonValue::IsString方法的具体用法?C++ JsonValue::IsString怎么用?C++ JsonValue::IsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonValue
的用法示例。
在下文中一共展示了JsonValue::IsString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FromDocument
/**
* @brief Takes a JsonDocument object and parses it as a Jplace document into a PlacementMap object.
*
* Returns true iff successful.
*/
bool JplaceProcessor::FromDocument (const JsonDocument& doc, PlacementMap& placements)
{
placements.clear();
// check if the version is correct
JsonValue* val = doc.Get("version");
if (!val) {
LOG_WARN << "Jplace document does not contain a valid version number at key 'version'."
<< "Now continuing to parse in the hope that it still works.";
}
if (!CheckVersion(val->ToString())) {
LOG_WARN << "Jplace document has version '" << val->ToString() << "', however this parser "
<< "is written for version " << GetVersion() << " of the Jplace format. "
<< "Now continuing to parse in the hope that it still works.";
}
// find and process the reference tree
val = doc.Get("tree");
if (!val || !val->IsString() || !NewickProcessor::FromString(val->ToString(), placements.tree)) {
LOG_WARN << "Jplace document does not contain a valid Newick tree at key 'tree'.";
return false;
}
// create a map from edge nums to the actual edge pointers, for later use when processing
// the pqueries. we do not use PlacementMap::EdgeNumMap() here, because we need to do extra
// checking for validity first!
std::unordered_map<int, PlacementTree::EdgeType*> edge_num_map;
for (
PlacementTree::ConstIteratorEdges it = placements.tree.BeginEdges();
it != placements.tree.EndEdges();
++it
) {
PlacementTree::EdgeType* edge = *it;
if (edge_num_map.count(edge->edge_num) > 0) {
LOG_WARN << "Jplace document contains a tree where the edge num tag '"
<< edge->edge_num << "' is used more than once.";
return false;
}
edge_num_map.emplace(edge->edge_num, edge);
}
// get the field names and store them in array fields
val = doc.Get("fields");
if (!val || !val->IsArray()) {
LOG_WARN << "Jplace document does not contain field names at key 'fields'.";
return false;
}
JsonValueArray* fields_arr = JsonValueToArray(val);
std::vector<std::string> fields;
bool has_edge_num = false;
for (JsonValue* fields_val : *fields_arr) {
if (!fields_val->IsString()) {
LOG_WARN << "Jplace document contains a value of type '" << fields_val->TypeToString()
<< "' instead of a string with a field name at key 'fields'.";
return false;
}
// check field validity
std::string field = fields_val->ToString();
if (field == "edge_num" || field == "likelihood" || field == "like_weight_ratio" ||
field == "distal_length" || field == "pendant_length" || field == "parsimony"
) {
for (std::string fn : fields) {
if (fn == field) {
LOG_WARN << "Jplace document contains field name '" << field << "' more than "
<< "once at key 'fields'.";
return false;
}
}
fields.push_back(field);
} else {
LOG_WARN << "Jplace document contains a field name '" << field << "' "
<< "at key 'fields', which is not used by this parser and thus skipped.";
}
has_edge_num |= (field == "edge_num");
}
if (!has_edge_num) {
LOG_WARN << "Jplace document does not contain necessary field 'edge_num' at key 'fields'.";
return false;
}
// find and process the pqueries
val = doc.Get("placements");
if (!val || !val->IsArray()) {
LOG_WARN << "Jplace document does not contain pqueries at key 'placements'.";
return false;
}
JsonValueArray* placements_arr = JsonValueToArray(val);
for (JsonValue* pqry_val : *placements_arr) {
if (!pqry_val->IsObject()) {
LOG_WARN << "Jplace document contains a value of type '" << pqry_val->TypeToString()
<< "' instead of an object with a pquery at key 'placements'.";
return false;
}
JsonValueObject* pqry_obj = JsonValueToObject(pqry_val);
//.........这里部分代码省略.........
示例2: Load
bool TournamentConfig::Load(const std::string &fileName)
{
JsonValue json;
bool ret = JsonReader::ParseFile(json, fileName);
if (ret)
{
std::string value;
if (json.GetValue("version", value))
{
if (value == TOURNAMENT_CONFIG_VERSION)
{
// Setup tournament configuration
mOptions.turns.clear();
JsonValue tournament = json.FindValue("tournament");
if (tournament.GetArray().Size() > 0U)
{
for (JsonArray::Iterator iter = tournament.GetArray().Begin(); iter != tournament.GetArray().End(); ++iter)
{
if (iter->IsObject())
{
JsonValue value = iter->GetObj().GetValue("type");
Tarot::Distribution shuffle;
if (value.IsString())
{
if (value.GetString() == "custom")
{
shuffle.mType = Tarot::Distribution::CUSTOM_DEAL;
value = iter->GetObj().GetValue("file");
if (value.IsString())
{
shuffle.mFile = value.GetString();
}
else
{
ret = false;
}
}
else if (value.GetString() == "random")
{
shuffle.mType = Tarot::Distribution::RANDOM_DEAL;
}
else if (value.GetString() == "numbered")
{
shuffle.mType = Tarot::Distribution::NUMBERED_DEAL;
shuffle.mSeed = iter->GetObj().GetValue("number").GetInteger();
// FIXME we can add a test on the type here before setting the seed
}
else
{
TLogError("Unsupported deal type value");
ret = false;
}
}
if (ret)
{
mOptions.turns.push_back(shuffle);
}
}
}
}
else
{
TLogError("No tournament details");
ret = false;
}
}
else
{
TLogError("Wrong tournament configuration file version");
ret = false;
}
}
else
{
TLogError("Cannot read tournament configuration file version");
ret = false;
}
}
else
{
TLogError("Cannot open tournament configuration file" + fileName);
}
if (!ret)
{
// Overwrite old file with default value
mOptions = GetDefault();
ret = Save(fileName);
}
mLoaded = true;
return ret;
}