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


C++ Document::Parse方法代码示例

本文整理汇总了C++中rapidjson::Document::Parse方法的典型用法代码示例。如果您正苦于以下问题:C++ Document::Parse方法的具体用法?C++ Document::Parse怎么用?C++ Document::Parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rapidjson::Document的用法示例。


在下文中一共展示了Document::Parse方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: parse_object

 bool etcd_packer::parse_object(rapidjson::Document &doc, const char *data) {
     try {
         doc.Parse(data);
         return doc.IsObject();
     } catch (...) {
         return false;
     }
 }
开发者ID:atframework,项目名称:atsf4g-co,代码行数:8,代码来源:etcd_packer.cpp

示例2: ParseJson

bool JsonUtils::ParseJson(rapidjson::Document& doc, fastcgi::DataBuffer& buffer)
{
    std::string json;
    buffer.toString(json);



    rapidjson::ParseResult ok = doc.Parse(json.c_str());
    if (ok.IsError())
	printf( "JSON parse error: %s (%lu)\n", rapidjson::GetParseError_En(ok.Code()), ok.Offset());
    return !ok.IsError();
}
开发者ID:ruslanfedoseenko,项目名称:FastCGICuteTorrentTracking,代码行数:12,代码来源:JsonUtils.cpp

示例3: load

void MapInfo::load(const std::string& json_file)
{
  std::ifstream file(json_file);
  if (!file) {
    logger << Log::WARN << "Did not find minimap: " << json_file << Log::ENDL;
    map_json.Parse("{}");
    // disable map entirely
    this->tex = nullptr;
    this->current_map = "";
    return;
  }

  const std::string str((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
  const auto& res = map_json.Parse(str.c_str());
  DM_ASSERT(map_json.IsObject(), "Could not parse map JSON file properly!");
  if (res.HasParseError()) {
    DM_ASSERT(false, "Could not parse map JSON file properly!");
  }

  if (map_json.HasMember("filename")) {
    this->set_map(map_json["filename"].GetString());
  }

  this->mask.enabled = map_json.HasMember("mask");
  if (this->mask.enabled)
  {
    auto mask_json = map_json["mask"].GetObject();
    if (mask_json.HasMember("active")) {
      this->mask.enabled = mask_json["active"].GetBool();
    }
    if (this->mask.enabled)
    {
      this->mask.radius = mask_json["radius"].GetInt();
      this->mask.border = mask_json["border"].GetInt();
      if (this->map_changed) {
        // create new mask
        this->mask.reset(tex->getWidth(), tex->getHeight());
      }
    }
  }

  // play area is used to restrict the player icon
  // the player location is transformed from the world into this area
  if (map_json.HasMember("play_area"))
  {
    auto area = map_json["play_area"].GetArray();
    this->play_area = glm::ivec4(area[0].GetInt(), area[1].GetInt(),
                                 area[2].GetInt(), area[3].GetInt());
  }
  else {
    // use whole image if play area is not specified
    this->play_area = glm::ivec4(0, 0, tex->getWidth(), tex->getHeight());
  }

  this->gridmode = map_json.HasMember("grid");
  if (this->gridmode)
  {
    auto& grid = map_json["grid"];
    this->grid_base_coord = glm::ivec2(grid["base_x"].GetInt(),
                                       grid["base_y"].GetInt());
    this->grid_dimensions = glm::ivec2(grid["size_x"].GetInt(),
                                       grid["size_y"].GetInt());
    // grid to pixel multiplier
    const int w = this->grid_pixel_multiplier().x;
    const int h = this->grid_pixel_multiplier().y;
    logger << Log::INFO << "Map screen is a grid of " << w << "x" << h << " pixels" << Log::ENDL;
  }
  else
  {
    const int w = this->tex->getWidth();
    const int h = this->tex->getHeight();
    // not a grid
    logger << Log::INFO << "Map screen is a bitmap of size " << w << "x" << h << " pixels" << Log::ENDL;
  }
  
  this->icons.clear();
  if (map_json.HasMember("icons") == false) return;
  auto& icon_json = map_json["icons"];
  const std::string icon_file = icon_json["filename"].GetString();
  this->sprite_texid = textures.add(icon_file);
  
  for (auto& m : icon_json.GetObject())
  {
    if (std::string("icon") == m.name.GetString())
    {
      const auto icon = m.value.GetObject();
      int px = icon["x"].GetInt();
      int py = icon["y"].GetInt();
      assert(icon.HasMember("sprite") && "Icons must have a sprite object");
      const auto sprite = icon["sprite"].GetObject();
      short x = sprite["x"].GetInt();
      short y = sprite["y"].GetInt();
      short w = sprite["w"].GetInt();
      short h = sprite["h"].GetInt();
      
      const Sprite spr {x, y, w, h, sprite_texid};
      this->icons.push_back(Icon{spr, glm::ivec2(px, py)});
    }
  }
  
//.........这里部分代码省略.........
开发者ID:fwsGonzo,项目名称:dm2,代码行数:101,代码来源:map_screen.cpp

示例4: _Parse

 void _Parse(const std::string& json) {
     document_.Parse(json.c_str());
     _CheckError();
 }
开发者ID:csieber,项目名称:hvbench,代码行数:4,代码来源:etcd_reply.hpp


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