本文整理汇总了C++中nlohmann::json类的典型用法代码示例。如果您正苦于以下问题:C++ json类的具体用法?C++ json怎么用?C++ json使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了json类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: deserialize
//--------------------------------------------------------------
void Interlude::deserialize(const nlohmann::json & json)
{
// Restore Stripes.
if (json.count("Stripes Back"))
{
auto layout = render::Layout::Back;
auto jsonStripes = json["Stripes Back"];
for (int i = 0; i < jsonStripes.size(); ++i)
{
auto instance = this->addStripes(layout);
if (instance)
{
ofxPreset::Serializer::Deserialize(jsonStripes, instance->parameters);
}
}
}
if (json.count("Stripes Front"))
{
auto layout = render::Layout::Front;
auto jsonStripes = json["Stripes Front"];
for (int i = 0; i < jsonStripes.size(); ++i)
{
auto instance = this->addStripes(layout);
if (instance)
{
ofxPreset::Serializer::Deserialize(jsonStripes, instance->parameters);
}
}
}
}
示例2: deserializeDictionaryModel
void deserializeDictionaryModel(const nlohmann::json& input,
DictionaryModel& dictionaryModel) {
nlohmann::json::const_iterator it = input.find("entities");
if (it != input.end() && (*it).is_object()) {
deserializeDictionary(*it, dictionaryModel);
}
}
示例3: clickAndDragAbsolute
/**
* Click and drag absolute: move to a relative coordinate within the window
* windowname, clamped.
*/
bool clickAndDragAbsolute(std::string window_name, nlohmann::json action){
//populate the window variables.
int x_start, x_end, y_start, y_end, mouse_button;
bool no_clamp = false;
bool success = populateClickAndDragValues(action, window_name, x_start,
x_end, y_start, y_end, mouse_button, no_clamp);
//if we couldn't populate the values, do nothing (window doesn't exist)
if(!success){
std::cout << "Click and drag unsuccessful due to failure to populate click and drag values." << std::endl;
return false;
}
int start_x_position = action.value("start_x", -1);
int start_y_position = action.value("start_y", -1);
int end_x_position = action.value("end_x", -1);
int end_y_position = action.value("end_y", -1);
if (start_x_position == end_x_position && start_y_position == end_y_position){
std::cout << "Error, the click and drag action did not specify movement." << std::endl;
return false;
}
if(end_x_position == -1 || end_y_position == -1){
std::cout << "ERROR: the click and drag action must include an ending position" << std::endl;
return false;
}
//get the mouse into starting position if they are specified.
if(start_x_position != -1 && start_y_position != -1){
start_x_position = start_x_position + x_start;
start_y_position = start_y_position + y_start;
//don't move out of the window.
clamp(start_x_position, x_start, x_end);
clamp(start_y_position, y_start, y_end);
mouse_move(window_name, start_x_position, start_y_position,x_start, x_end,
y_start, y_end, false);
}
end_x_position = end_x_position + x_start;
end_y_position = end_y_position + y_start;
//clamp the end position so we don't exit the window.
clamp(end_x_position, x_start, x_end);
clamp(end_y_position, y_start, y_end);
//These functions won't do anything if the window doesn't exist.
mouseDown(window_name,mouse_button);
mouse_move(window_name, end_x_position, end_y_position,x_start, x_end,
y_start, y_end, false);
mouseUp(window_name,mouse_button);
return true;
}
示例4: from_json
inline void
from_json (const nlohmann::json& j, tileset& ts)
{
ts.firstgid = j["firstgid"].get<uint32>();
if (j.count("source"))
{
ts.type = tileset::tiled_tileset_type_external;
ts.source = j["source"].get<std::string>();
}
else
{
ts.type = tileset::tiled_tileset_type_embedded;
ts.name = j["name"].get<std::string>();
ts.tilewidth = j["tilewidth"].get<uint32>();
ts.tileheight = j["tileheight"].get<uint32>();
ts.spacing = j["spacing"].get<uint32>();
ts.margin = j["margin"].get<uint32>();
ts.tilecount = j["tilecount"].get<uint32>();
ts.columns = j["columns"].get<uint32>();
ts.image = j["image"].get<std::string>();
ts.imagewidth = j["imagewidth"].get<uint32>();
ts.imageheight = j["imageheight"].get<uint32>();
}
}
示例5: set
void ExprFunction<T>::set(const nlohmann::json &j, const Tvarvec &vars) {
Tconstvec consts;
auto it = j.find("constants");
if (it != j.end())
for (auto i = it->begin(); i != it->end(); ++i)
consts.push_back({i.key(), i.value()});
set(j.at("function"), vars, consts);
}
示例6: deserializeChatbotActionModel
void deserializeChatbotActionModel(const nlohmann::json& input,
ChatbotActionModel& chatbotActionModel) {
nlohmann::json::const_iterator it;
it = input.find("chatbot");
if (it != input.end() && (*it).is_object()) {
deserializeChatbotActions(*it, chatbotActionModel);
}
}
示例7: deserializeIntentStoryModel
void deserializeIntentStoryModel(const nlohmann::json& input,
IntentStoryModel& intentStoryModel) {
nlohmann::json::const_iterator it;
it = input.find("intent_story");
if (it != input.end() && (*it).is_object()) {
deserializeIntentStory(*it, intentStoryModel);
}
}
示例8: deserializeIntentModel
void deserializeIntentModel(const nlohmann::json& input,
const DictionaryModel& dictionaryModel,
IntentModel& intentModel) {
nlohmann::json::const_iterator it = input.find("intents");
if (it != input.end() && (*it).is_array()) {
const nlohmann::json::array_t& intents = *it;
deserializeIntents(intents, dictionaryModel, intentModel);
}
}
示例9: Unit
Unit(const nlohmann::json &obj) : Point(obj)
{
if (obj.count("M"))
mass = obj["M"].get<double>();
if (obj.count("SX"))
speed.x = obj["SX"].get<double>();
if (obj.count("SY"))
speed.y = obj["SY"].get<double>();
}
示例10: loadFromJSON
void RaytracingConfig::loadFromJSON(const nlohmann::json & config) {
enabled = config.get<bool>("enabled");
title = config.get<std::string>("title");
controlsCamera = config.get<bool>("controlsCamera");
renderOutputWidth = config.get<int>("outputWidth");
renderOutputHeight = config.get<int>("outputHeight");
computationDevice = (ComputationDevice) config.get<int>("computationDevice");
brdfType = (SupportedBRDF) config.get<int>("brdfType");
supportedPhotonMap = (SupportedPhotonMap) config.get<int>("supportedPhotonMap");
numberOfPhotonsToGather = config.get<int>("numberOfPhotonsToGather");
raysPerLight = config.get<int>("raysPerLight");
float maxPhotonGatherDistance = config.get<double>("maxPhotonGatherDistance", -1.0);
if (maxPhotonGatherDistance != -1.0f) {
this->maxPhotonGatherDistance = maxPhotonGatherDistance;
}
else {
this->maxPhotonGatherDistance = std::numeric_limits<float>::infinity();
}
lumensPerLight = config.get<int>("lumensPerLight");
photonBounceProbability = config.get<double>("photonBounceProbability");
photonBounceEnergyMultipler = config.get<double>("photonBounceEnergyMultipler");
usePhotonMappingForDirectIllumination = config.get<bool>("usePhotonMappingForDirectIllumination");
directIlluminationEnabled = config.get<bool>("directIlluminationEnabled");
indirectIlluminationEnabled = config.get<bool>("indirectIlluminationEnabled");
shadowsEnabled = config.get<bool>("shadowsEnabled");
if (config.has("Hashmap_properties")) {
hashmapCellsize = config["Hashmap_properties"].get<double>("cellsize");
hashmapSpacing = config["Hashmap_properties"].get<int>("spacing");
hashmapGridStart = vec3FromData(config["Hashmap_properties"].get<std::vector<double>>("gridStart", make_vector<double>(0,0,0)));
hashmapGridEnd = vec3FromData(config["Hashmap_properties"].get<std::vector<double>>("gridEnd", make_vector<double>(0,0,0)));
}
if (config.has("Tile_properties")) {
tile_width = config["Tile_properties"].get<int>("tileHeight");
tile_height = config["Tile_properties"].get<int>("tileWidth");
tile_photonEffectRadius = config["Tile_properties"].get<double>("photonEffectRadius");
tile_photonSampleRate = config["Tile_properties"].get<double>("photonSampleRate");
}
if (config.has("photonEffectRadius")) {
this->maxPhotonGatherDistance = config.get<double>("photonEffectRadius", 1.0);
tile_photonEffectRadius = this->maxPhotonGatherDistance;
}
}
示例11: deserializeChatbotActions
void deserializeChatbotActions(const nlohmann::json& chatbot,
ChatbotActionModel& chatbotActionModel) {
nlohmann::json::const_iterator it;
it = chatbot.find("replies");
if (it != chatbot.end() && (*it).is_object()) {
deserializeReplies(*it, chatbotActionModel);
}
it = chatbot.find("replies_by_state_action");
if (it != chatbot.end() && (*it).is_object()) {
deserializeReplyIdsByStateAndActionId(*it, chatbotActionModel);
}
}
示例12: deserializeVectors
std::vector<Vector<dim>> deserializeVectors(const nlohmann::json &data) {
std::vector<Vector<dim>> vectors;
if (data.empty())
return vectors;
if (data["Dimension"].get<unsigned int>() != dim) {
Logging::error("Data has wrong dimension", "JsonSerializer");
return vectors;
}
std::vector<std::vector<double>> stdVectors = data["data"].get<std::vector<std::vector<double>>>();
size_t size = data["NumberConfigurations"].get<size_t>();
if (stdVectors.size() != size) {
Logging::error("Wrong vector size of file", "JsonSerializer");
return vectors;
}
for (const auto &vec : stdVectors) {
Vector<dim> eigenVec;
for (unsigned int j = 0; j < dim; ++j)
eigenVec[j] = vec[j];
vectors.push_back(eigenVec);
}
return vectors;
}
示例13: populateClickAndDragValues
/**
* This function sets the window variables (using populateWindowData), and
* mouse_button (pressed) destination (an x,y tuple we are dragging to), and
* no_clamp (which is currently disabled/false). returns false on failure.
* It is on the programmer to check.
*/
bool populateClickAndDragValues(nlohmann::json action, std::string window_name,
int& window_left, int& window_right, int& window_top, int& window_bottom, int& mouse_button,
bool& no_clamp){
int height, width;
//Get the window dimensions.
populateWindowData(window_name,height,width,window_left,window_right,window_top,window_bottom);
// if(command.find("no clamp") != std::string::npos){
// std::cout << "Multiple windows are not yet supported. (No 'no clamp' option available)" << std::endl;
// no_clamp = false;
// }
std::string mouse_button_string = action.value("mouse_button", "left");
if(mouse_button_string == "left"){
mouse_button = 1;
}
else if (mouse_button_string == "middle"){
mouse_button = 2;
}
else if (mouse_button_string == "right"){
mouse_button = 3;
}
else{ //default.
mouse_button = 1;
}
return true;
}
示例14: runtime_error
localization::ssd::config::config(nlohmann::json js)
{
if (js.is_null())
{
throw std::runtime_error("missing ssd config in json config");
}
for (auto& info : config_list)
{
info->parse(js);
}
verify_config("localization_ssd", config_list, js);
add_shape_type({2, 1}, "int32_t");
add_shape_type({max_gt_boxes, 4}, "float");
add_shape_type({1, 1}, "int32_t");
add_shape_type({max_gt_boxes, 1}, "int32_t");
// 'difficult' tag for gt_boxes
add_shape_type({max_gt_boxes, 1}, "int32_t");
class_name_map.clear();
for (int i = 0; i < class_names.size(); i++)
{
class_name_map.insert({class_names[i], i});
}
validate();
}
示例15: find_json
inline std::optional<nlohmann::json::const_iterator> find_json(const nlohmann::json& json,
const std::string& key) {
auto it = json.find(key);
if (it != std::end(json)) {
return it;
}
return std::nullopt;
}