//-------------------------------------------------------------- //-------------------------------------------------------------- void TaggedFilePathResolver::SetFromJson(const Json::Value& in_json) { std::vector<std::string> supportedLanguages; const Json::Value& languages = in_json["Languages"]; if(languages.isNull() == false) { for(u32 i=0; i<languages.size(); ++i) { supportedLanguages.push_back(languages[i].asString()); } } std::vector<RangeRule> supportedResolutions; const Json::Value& resolutions = in_json["Resolutions"]; if(resolutions.isNull() == false) { for(auto it = resolutions.begin(); it != resolutions.end(); ++it) { Vector2 res = ParseVector2((*it).asString()); RangeRule rule(it.memberName(), res.x * res.y); supportedResolutions.push_back(rule); } } std::vector<RangeRule> supportedAspectRatios; const Json::Value& aspects = in_json["AspectRatios"]; if(aspects.isNull() == false) { for(auto it = aspects.begin(); it != aspects.end(); ++it) { RangeRule rule(it.memberName(), (f32)(*it).asDouble()); supportedAspectRatios.push_back(rule); } } SetTags(supportedLanguages, supportedResolutions, supportedAspectRatios); TagGroup priorityIndices[(u32)TagGroup::k_total]; const Json::Value& priorities = in_json["Priorities"]; if(priorities.isNull() == false) { CS_ASSERT(priorities.size() == (u32)TagGroup::k_total, "TaggedFilePathResolver: Need to specify all groups when setting priorities"); for(u32 i=0; i<priorities.size(); ++i) { priorityIndices[i] = ParseGroup(priorities[i].asString()); } } SetPriority(priorityIndices[0], priorityIndices[1], priorityIndices[2], priorityIndices[3]); }
std::string ValueIteratorBase::name() const { char const* keey; char const* end; keey = memberName(&end); if (!keey) return std::string(); return std::string(keey, end); }
bool MatchStart::parse(std::string json) { Json::Reader reader; Json::Value root; if (!reader.parse(json, root, false)) { throw std::invalid_argument("Unable to parse json"); } romingSettings.parse(root.get("roamingSettings", Json::nullValue)); clientVersionFromXml = root.get("clientVersionFromXml", Json::nullValue).asString(); clientVersionFromExe = root.get("clientVersionFromExe", Json::nullValue).asString(); mapDisplayName = root.get("mapDisplayName", Json::nullValue).asString(); gameplayID = root.get("gameplayID", Json::nullValue).asString(); regionCode = root.get("regionCode", Json::nullValue).asString(); playerID = root.get("playerID", Json::nullValue).asUInt(); serverName = root.get("serverName", Json::nullValue).asString(); Json::Value vehiclesRoot = root.get("vehicles", Json::nullValue); if (vehiclesRoot.size() > 0) { for (auto it = vehiclesRoot.begin(); it != vehiclesRoot.end(); it++) { std::string key(it.memberName()); Json::Value vehicleRoot = vehiclesRoot.get(key, Json::nullValue); Vehicle value; value.parse(vehicleRoot); vehicles.insert(std::make_pair(key, value)); } } dateTime = root.get("dateTime", Json::nullValue).asString(); mapName = root.get("mapName", Json::nullValue).asString(); playerName = root.get("playerName", Json::nullValue).asString(); battleType = root.get("battleType", Json::nullValue).asUInt(); playerVehicle = root.get("playerVehicle", Json::nullValue).asString(); return true; }
void TConfigParser::MergeAndLoadChannels(PDeviceConfig device_config, const Json::Value& device_data, PTemplate tmpl) { std::set<std::string> loaded; if (device_data.isMember("channels")) { const Json::Value& channels = device_data["channels"]; if (!channels.isArray()) throw TConfigParserException("device channels member must be an array"); // Merge channels mentioned both in template and device definition for(Json::ArrayIndex i = 0; i < channels.size(); ++i) { Json::Value channel_data = channels[i]; if (!channel_data.isObject()) throw TConfigParserException("channel definition is not an object"); std::string name = channel_data["name"].asString(); if (name.empty()) throw TConfigParserException("channel name is empty"); loaded.insert(name); // If the template has a channel with the same name as current one, // pull template channel properties if (tmpl && tmpl->ChannelMap.isMember(name)) { const Json::Value& tmpl_channel_data = tmpl->ChannelMap[name]; for (auto it = tmpl_channel_data.begin(); it != tmpl_channel_data.end(); ++it) { // Channel fields from current device config // take precedence over template field values if (!channel_data.isMember(it.memberName())) channel_data[it.memberName()] = *it; } } LoadChannel(device_config, channel_data); } } if (tmpl) { // Load template channels that weren't mentioned in device definition const Json::Value& template_channels = tmpl->DeviceData["channels"]; for(Json::ArrayIndex i = 0; i < template_channels.size(); ++i) { Json::Value channel_data = template_channels[i]; if (loaded.find(channel_data["name"].asString()) == loaded.end()) LoadChannel(device_config, channel_data); } } }
size_t CompoundType::memberOffset (size_t i) const { ASSERT (i <= std::numeric_limits<unsigned>::max ()); unsigned i2 = static_cast<unsigned> (i); size_t result = H5Tget_member_offset (handle (), i2); if (result == 0) { // Check for errors, H5Tget_member_offset fails only if H5Tget_member_name also fails // http://www.hdfgroup.org/HDF5/doc/RM/RM_H5T.html#Datatype-GetMemberOffset memberName (i); } return result; }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ VListLayoutDef::VListLayoutDef(const Json::Value& in_json) { const char k_typeKey[] = "Type"; const char k_numCellsKey[] = "NumCells"; const char k_relativeMarginsKey[] = "RelMargins"; const char k_absoluteMarginsKey[] = "AbsMargins"; const char k_relativeSpacingKey[] = "RelSpacing"; const char k_absoluteSpacingKey[] = "AbsSpacing"; for(auto it = in_json.begin(); it != in_json.end(); ++it) { CS_ASSERT((*it).isString() == true, "All properties in a Layout Description must be a string: " + std::string(it.memberName())); std::string key = it.memberName(); std::string value = (*it).asString(); if (key == k_relativeMarginsKey) { m_relativeMargins = Core::ParseVector4(value); } else if (key == k_absoluteMarginsKey) { m_absoluteMargins = Core::ParseVector4(value); } else if (key == k_numCellsKey) { m_numCells = Core::ParseU32(value); } else if (key == k_relativeSpacingKey) { m_relativeSpacing = Core::ParseF32(value); } else if (key == k_absoluteSpacingKey) { m_absoluteSpacing = Core::ParseF32(value); } else if (key == k_typeKey) { //ignore } else { CS_LOG_FATAL("Invalid property found in a List layout description: " + key); } } }
void Client::updateUI(const Json::Value& data) { for (auto it = data.begin(); it != data.end(); ++it) { const char* name = it.memberName(); const Json::Value& value = *it; if (value.isString() && strcmp(name, "candFontName") == 0) { wstring fontName = utf8ToUtf16(value.asCString()); textService_->setCandFontName(fontName); } else if (value.isInt() && strcmp(name, "candFontSize") == 0) { textService_->setCandFontSize(value.asInt()); } else if (value.isInt() && strcmp(name, "candPerRow") == 0) { textService_->setCandPerRow(value.asInt()); } else if (value.isBool() && strcmp(name, "candUseCursor") == 0) { textService_->setCandUseCursor(value.asBool()); } } }
// account_dividend [account] Json::Value doAccountDividend (RPC::Context& context) { auto const& params (context.params); if (! params.isMember (jss::account)) return RPC::missing_field_error (jss::account); std::shared_ptr<ReadView const> ledger; auto result = RPC::lookupLedger (ledger, context); if (! ledger) return result; std::string strIdent (params[jss::account].asString ()); AccountID accountID; if (auto jv = RPC::accountFromString (accountID, strIdent)) { for (auto it = jv.begin (); it != jv.end (); ++it) result[it.memberName ()] = it.key (); return result; } auto accountSLE = ledger->read (keylet::account (accountID)); if (!accountSLE) return rpcError (rpcACT_NOT_FOUND); result[jss::account] = context.app.accountIDCache ().toBase58 (accountID); std::uint32_t baseLedgerSeq = 0; auto dividendSLE = ledger->read (keylet::dividend ()); if (dividendSLE) { if (dividendSLE->getFieldU8 (sfDividendState) != DividendMaster::DivState_Done) { return RPC::make_error (rpcNOT_READY, "Dividend in progress"); } Json::Value resumeToken; baseLedgerSeq = dividendSLE->getFieldU32 (sfDividendLedger); auto txns = context.netOps.getTxsAccount ( accountID, baseLedgerSeq, ledger->info ().seq, false, resumeToken, 1, context.role == Role::ADMIN, "Dividend"); if (!txns.empty ()) { auto& txn = txns.begin ()->first->getSTransaction (); result["DividendCoins"] = to_string (txn->getFieldU64 (sfDividendCoins)); result["DividendCoinsVBC"] = to_string (txn->getFieldU64 (sfDividendCoinsVBC)); result["DividendCoinsVBCRank"] = to_string (txn->getFieldU64 (sfDividendCoinsVBCRank)); result["DividendCoinsVBCSprd"] = to_string (txn->getFieldU64 (sfDividendCoinsVBCSprd)); result["DividendTSprd"] = to_string (txn->getFieldU64 (sfDividendTSprd)); result["DividendVRank"] = to_string (txn->getFieldU64 (sfDividendVRank)); result["DividendVSprd"] = to_string (txn->getFieldU64 (sfDividendVSprd)); result["DividendLedger"] = to_string (txn->getFieldU32 (sfDividendLedger)); return result; } } result["DividendCoins"] = "0"; result["DividendCoinsVBC"] = "0"; result["DividendCoinsVBCRank"] = "0"; result["DividendCoinsVBCSprd"] = "0"; result["DividendTSprd"] = "0"; result["DividendVRank"] = "0"; result["DividendVSprd"] = "0"; result["DividendLedger"] = to_string (baseLedgerSeq); return result; }
Json::Value doAccountObjects (RPC::Context& context) { auto const& params = context.params; if (! params.isMember (jss::account)) return RPC::missing_field_error (jss::account); std::shared_ptr<ReadView const> ledger; auto result = RPC::lookupLedger (ledger, context); if (ledger == nullptr) return result; AccountID accountID; { auto const strIdent = params[jss::account].asString (); if (auto jv = RPC::accountFromString (accountID, strIdent)) { for (auto it = jv.begin (); it != jv.end (); ++it) result[it.memberName ()] = it.key (); return result; } } if (! ledger->exists(keylet::account (accountID))) return rpcError (rpcACT_NOT_FOUND); auto type = ltINVALID; if (params.isMember (jss::type)) { static std::array<std::pair<char const *, LedgerEntryType>, 9> const types {{ { jss::account, ltACCOUNT_ROOT }, { jss::amendments, ltAMENDMENTS }, { jss::directory, ltDIR_NODE }, { jss::fee, ltFEE_SETTINGS }, { jss::hashes, ltLEDGER_HASHES }, { jss::offer, ltOFFER }, { jss::signer_list, ltSIGNER_LIST }, { jss::state, ltRIPPLE_STATE }, { jss::ticket, ltTICKET } } }; auto const& p = params[jss::type]; if (! p.isString ()) return RPC::expected_field_error (jss::type, "string"); auto const filter = p.asString (); auto iter = std::find_if (types.begin (), types.end (), [&filter](decltype (types.front ())& t) { return t.first == filter; }); if (iter == types.end ()) return RPC::invalid_field_error (jss::type); type = iter->second; } unsigned int limit; if (auto err = readLimitField(limit, RPC::Tuning::accountObjects, context)) return *err; uint256 dirIndex; uint256 entryIndex; if (params.isMember (jss::marker)) { auto const& marker = params[jss::marker]; if (! marker.isString ()) return RPC::expected_field_error (jss::marker, "string"); std::stringstream ss (marker.asString ()); std::string s; if (!std::getline(ss, s, ',')) return RPC::invalid_field_error (jss::marker); if (! dirIndex.SetHex (s)) return RPC::invalid_field_error (jss::marker); if (! std::getline (ss, s, ',')) return RPC::invalid_field_error (jss::marker); if (! entryIndex.SetHex (s)) return RPC::invalid_field_error (jss::marker); } if (! RPC::getAccountObjects (*ledger, accountID, type, dirIndex, entryIndex, limit, result)) { result[jss::account_objects] = Json::arrayValue; } result[jss::account] = context.app.accountIDCache().toBase58 (accountID); context.loadType = Resource::feeMediumBurdenRPC; return result; }
// { // account: <account>|<account_public_key> // account_index: <number> // optional, defaults to 0. // ledger_hash : <ledger> // ledger_index : <ledger_index> // limit: integer // optional // marker: opaque // optional, resume previous query // } Json::Value doAccountLines (RPC::Context& context) { auto const& params (context.params); if (! params.isMember (jss::account)) return RPC::missing_field_error (jss::account); Ledger::pointer ledger; Json::Value result (RPC::lookupLedger (params, ledger, context.netOps)); if (! ledger) return result; std::string strIdent (params[jss::account].asString ()); bool bIndex (params.isMember (jss::account_index)); int iIndex (bIndex ? params[jss::account_index].asUInt () : 0); DivvyAddress divvyAddress; auto jv = RPC::accountFromString ( divvyAddress, bIndex, strIdent, iIndex, false); if (! jv.empty ()) { for (auto it = jv.begin (); it != jv.end (); ++it) result[it.memberName ()] = it.key (); return result; } if (! ledger->exists(getAccountRootIndex( divvyAddress.getAccountID()))) return rpcError (rpcACT_NOT_FOUND); std::string strPeer (params.isMember (jss::peer) ? params[jss::peer].asString () : ""); bool bPeerIndex (params.isMember (jss::peer_index)); int iPeerIndex (bIndex ? params[jss::peer_index].asUInt () : 0); DivvyAddress divvyAddressPeer; if (! strPeer.empty ()) { result[jss::peer] = divvyAddress.humanAccountID (); if (bPeerIndex) result[jss::peer_index] = iPeerIndex; result = RPC::accountFromString ( divvyAddressPeer, bPeerIndex, strPeer, iPeerIndex, false); if (! result.empty ()) return result; } AccountID raPeerAccount; if (divvyAddressPeer.isValid ()) raPeerAccount = divvyAddressPeer.getAccountID (); unsigned int limit; if (params.isMember (jss::limit)) { auto const& jvLimit (params[jss::limit]); if (! jvLimit.isIntegral ()) return RPC::expected_field_error (jss::limit, "unsigned integer"); limit = jvLimit.isUInt () ? jvLimit.asUInt () : std::max (0, jvLimit.asInt ()); if (context.role != Role::ADMIN) { limit = std::max (RPC::Tuning::minLinesPerRequest, std::min (limit, RPC::Tuning::maxLinesPerRequest)); } } else { limit = RPC::Tuning::defaultLinesPerRequest; } Json::Value& jsonLines (result[jss::lines] = Json::arrayValue); AccountID const& raAccount(divvyAddress.getAccountID ()); VisitData visitData = { {}, raAccount, divvyAddressPeer, raPeerAccount }; unsigned int reserve (limit); uint256 startAfter; std::uint64_t startHint; if (params.isMember (jss::marker)) { // We have a start point. Use limit - 1 from the result and use the // very last one for the resume. Json::Value const& marker (params[jss::marker]); if (! marker.isString ()) return RPC::expected_field_error (jss::marker, "string"); startAfter.SetHex (marker.asString ()); auto const sleLine = fetch(*ledger, startAfter, getApp().getSLECache()); if (sleLine == nullptr || sleLine->getType () != ltRIPPLE_STATE) return rpcError (rpcINVALID_PARAMS); if (sleLine->getFieldAmount (sfLowLimit).getIssuer () == raAccount) startHint = sleLine->getFieldU64 (sfLowNode); else if (sleLine->getFieldAmount (sfHighLimit).getIssuer () == raAccount) startHint = sleLine->getFieldU64 (sfHighNode); else return rpcError (rpcINVALID_PARAMS); // Caller provided the first line (startAfter), add it as first result auto const line = DivvyState::makeItem (raAccount, sleLine); if (line == nullptr) return rpcError (rpcINVALID_PARAMS); addLine (jsonLines, *line); visitData.items.reserve (reserve); } else { startHint = 0; // We have no start point, limit should be one higher than requested. visitData.items.reserve (++reserve); } if (! forEachItemAfter(*ledger, raAccount, getApp().getSLECache(), startAfter, startHint, reserve, [&visitData](std::shared_ptr<SLE const> const& sleCur) { auto const line = DivvyState::makeItem (visitData.accountID, sleCur); if (line != nullptr && (! visitData.divvyAddressPeer.isValid () || visitData.raPeerAccount == line->getAccountIDPeer ())) { visitData.items.emplace_back (line); return true; } return false; })) { return rpcError (rpcINVALID_PARAMS); } if (visitData.items.size () == reserve) { result[jss::limit] = limit; DivvyState::pointer line (visitData.items.back ()); result[jss::marker] = to_string (line->key()); visitData.items.pop_back (); } result[jss::account] = divvyAddress.humanAccountID (); for (auto const& item : visitData.items) addLine (jsonLines, *item.get ()); context.loadType = Resource::feeMediumBurdenRPC; return result; }
Json::Value doAccountObjects (RPC::Context& context) { auto const& params = context.params; if (! params.isMember (jss::account)) return RPC::missing_field_error (jss::account); Ledger::pointer ledger; auto result = RPC::lookupLedger (params, ledger, context.netOps); if (ledger == nullptr) return result; DivvyAddress raAccount; { bool bIndex; auto const strIdent = params[jss::account].asString (); auto iIndex = context.params.isMember (jss::account_index) ? context.params[jss::account_index].asUInt () : 0; auto jv = RPC::accountFromString ( raAccount, bIndex, strIdent, iIndex, false); if (! jv.empty ()) { for (auto it = jv.begin (); it != jv.end (); ++it) result[it.memberName ()] = it.key (); return result; } } if (! ledger->exists(getAccountRootIndex( raAccount.getAccountID()))) return rpcError (rpcACT_NOT_FOUND); auto type = ltINVALID; if (params.isMember (jss::type)) { using filter_types = std::vector <std::pair <std::string, LedgerEntryType>>; static beast::static_initializer <filter_types> const types ([]() -> filter_types { return { { "account", ltACCOUNT_ROOT }, { "amendments", ltAMENDMENTS }, { "directory", ltDIR_NODE }, { "fee", ltFEE_SETTINGS }, { "hashes", ltLEDGER_HASHES }, { "offer", ltOFFER }, { "state", ltRIPPLE_STATE }, { "ticket", ltTICKET } }; }()); auto const& p = params[jss::type]; if (! p.isString ()) return RPC::expected_field_error (jss::type, "string"); auto const filter = p.asString (); auto iter = std::find_if (types->begin (), types->end (), [&filter](decltype (types->front ())& t) { return t.first == filter; }); if (iter == types->end ()) return RPC::invalid_field_error (jss::type); type = iter->second; } auto limit = RPC::Tuning::defaultObjectsPerRequest; if (params.isMember (jss::limit)) { auto const& jvLimit = params[jss::limit]; if (! jvLimit.isIntegral ()) return RPC::expected_field_error (jss::limit, "unsigned integer"); limit = jvLimit.isUInt () ? jvLimit.asUInt () : std::max (0, jvLimit.asInt ()); if (context.role != Role::ADMIN) { limit = std::max (RPC::Tuning::minObjectsPerRequest, std::min (limit, RPC::Tuning::maxObjectsPerRequest)); } } uint256 dirIndex; uint256 entryIndex; if (params.isMember (jss::marker)) { auto const& marker = params[jss::marker]; if (! marker.isString ()) return RPC::expected_field_error (jss::marker, "string"); std::stringstream ss (marker.asString ()); std::string s; if (!std::getline(ss, s, ',')) return RPC::invalid_field_error (jss::marker); if (! dirIndex.SetHex (s)) return RPC::invalid_field_error (jss::marker); if (! std::getline (ss, s, ',')) return RPC::invalid_field_error (jss::marker); if (! entryIndex.SetHex (s)) return RPC::invalid_field_error (jss::marker); } if (! RPC::getAccountObjects (*ledger, raAccount.getAccountID (), type, dirIndex, entryIndex, limit, result)) { return RPC::invalid_field_error (jss::marker); } result[jss::account] = raAccount.humanAccountID (); context.loadType = Resource::feeMediumBurdenRPC; return result; }