当前位置: 首页>>代码示例>>C++>>正文


C++ nlohmann::json类代码示例

本文整理汇总了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);
					}
				}
			}
		}
开发者ID:Entropy,项目名称:Entropy,代码行数:31,代码来源:Interlude.cpp

示例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);
  }
}
开发者ID:open-intent-io,项目名称:open-intent,代码行数:7,代码来源:Deserializer.cpp

示例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;
}
开发者ID:Submitty,项目名称:Submitty,代码行数:63,代码来源:window_utils.cpp

示例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>();
    }
}
开发者ID:JoshBramlett,项目名称:RDGE,代码行数:25,代码来源:tiled.hpp

示例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);
}
开发者ID:mlund,项目名称:faunus,代码行数:8,代码来源:functionparser.cpp

示例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);
  }
}
开发者ID:open-intent-io,项目名称:open-intent,代码行数:9,代码来源:Deserializer.cpp

示例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);
  }
}
开发者ID:open-intent-io,项目名称:open-intent,代码行数:9,代码来源:Deserializer.cpp

示例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);
  }
}
开发者ID:open-intent-io,项目名称:open-intent,代码行数:9,代码来源:Deserializer.cpp

示例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>();
	}
开发者ID:tyamgin,项目名称:AiCup,代码行数:9,代码来源:Unit.hpp

示例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;
    }
}
开发者ID:nshkurkin,项目名称:TealTracer,代码行数:54,代码来源:RaytracingConfig.cpp

示例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);
  }
}
开发者ID:open-intent-io,项目名称:open-intent,代码行数:14,代码来源:Deserializer.cpp

示例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;
}
开发者ID:SaschaKaden,项目名称:RobotMotionPlanner,代码行数:25,代码来源:JsonSerializer.hpp

示例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;
}
开发者ID:Submitty,项目名称:Submitty,代码行数:35,代码来源:window_utils.cpp

示例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();
}
开发者ID:NervanaSystems,项目名称:aeon,代码行数:29,代码来源:etl_localization_ssd.cpp

示例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;
}
开发者ID:tekezo,项目名称:Karabiner-Elements,代码行数:8,代码来源:json.hpp


注:本文中的nlohmann::json类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。