示例#1
0
void SuperastCPP::addElemsToArray(rapidjson::Value& parentValue,
    rapidjson::Value& elemsValue) {
  assert(parentValue.IsArray());
  assert(elemsValue.IsArray());
  for (unsigned i = 0; i < elemsValue.Size(); ++i) {
    parentValue.PushBack(elemsValue[i], allocator);
  }
}
示例#2
0
// フラグの確認
bool GameEventHelper::detectFlg(rapidjson::Value& json, bool negative)
{
    bool detection { false };
    
    
    if (!json.IsArray())
    {
        // 自分自身のステータスを確認
        detection = PlayerDataManager::getInstance()->getLocalData()->checkEventStatus(DungeonSceneManager::getInstance()->getLocation().map_id, DungeonSceneManager::getInstance()->getRunningEventId(), json.GetInt());
        if(negative) detection = !detection;
    }
    else if (!json[0].IsArray())
    {
        detection = PlayerDataManager::getInstance()->getLocalData()->checkEventStatus(stoi(json[0].GetString()), stoi(json[1].GetString()), json[2].GetInt());
        if(negative) detection = !detection;
    }
    else
    {
        // 複数の場合
        for(int i { 0 }; i < json.Size(); i++)
        {
            detection = PlayerDataManager::getInstance()->getLocalData()->checkEventStatus(stoi(json[i][0].GetString()), stoi(json[i][1].GetString()), json[i][2].GetInt());
            if(negative) detection = !detection;
            if(!detection) break;
        }
    }
    
    return detection;
}
示例#3
0
int32_t fetch_event_diff::parse(const rapidjson::Value& _node_event_data)
{
    try
    {
        if (!_node_event_data.IsArray())
            return wpie_error_parse_response;

        for (auto iter = _node_event_data.Begin(), end = _node_event_data.End(); iter != end; ++iter)
        {
            std::string type;
            const auto iter_type = iter->FindMember("type");
            if (iter_type != iter->MemberEnd() && iter_type->value.IsString())
                type = rapidjson_get_string(iter_type->value);

            const auto iter_data = iter->FindMember("data");
            if (iter_data != iter->MemberEnd() && iter_data->value.IsArray())
            {
                auto cl = std::make_shared<contactlist>();
                cl->unserialize_from_diff(iter_data->value);
                diff_->insert(std::make_pair(std::move(type), std::move(cl)));
            }
        }
    }
    catch (const std::exception&)
    {
        return wpie_error_parse_response;
    }

    return 0;
}
示例#4
0
文件: utils.hpp 项目: raphaelrpl/tws
template<class OutputIterator> inline void
tws::core::copy_string_array(const rapidjson::Value& jvalues,
                             OutputIterator result)
{
  if(!jvalues.IsArray())
    throw conversion_error() << tws::error_description("copy_string_array: can only copy arrays of strings.");
  
  if(jvalues.Empty())
    return;
  
  const rapidjson::SizeType nelements = jvalues.Size();
  
  for(rapidjson::SizeType i = 0; i != nelements; ++i)
  {
    const rapidjson::Value& jelement = jvalues[i];
    
    if(!jelement.IsString())
      throw conversion_error() << tws::error_description("copy_string_array: only string elements are allowed in array.");
    
    if(jelement.IsNull())
      continue;
    
    *result++ = jelement.GetString();
  }
}
bool System::Parse(rapidjson::Value& node) {
    if(node.IsArray()) {
        for(auto sound_itr = node.Begin(); sound_itr != node.End(); sound_itr ++) {
            if(sound_itr->IsObject()) {
                auto& element = (*sound_itr);

                std::shared_ptr<sound_info> sinfo = std::shared_ptr<sound_info>(new sound_info());

                if(element.HasMember("id") && element["id"].IsString()) {
                    sinfo->id = element["id"].GetString();
                }
                if(element.HasMember("src") && element["src"].IsString()) {
                    sinfo->src = element["src"].GetString();
                }
                if(element.HasMember("loop") && element["loop"].IsBool()) {
                    sinfo->loop = element["loop"].GetBool();
                }
                if(element.HasMember("volume") && element["volume"].IsNumber()) {
                    sinfo->volume = element["volume"].GetDouble();
                }
                if(element.HasMember("spatial") && element["spatial"].IsBool()) {
                    sinfo->spatial = element["spatial"].GetBool();
                }
                // store sound info
                sounds[sinfo->id] = sinfo;
            }
        }
    }

    return true;
}
示例#6
0
 void OptionParser::values(rapidjson::Value& arrayValue, std::vector<std::string>& var) {
     if (!arrayValue.IsArray()) {
         return;
     }
     for (int i = 0; i < arrayValue.Size(); i++) {
         var.push_back(arrayValue[i].GetString());
     }
 }
bool JSASTNode::ParseRange(const rapidjson::Value& value)
{
    assert(value.IsArray() && value.Size() == 2);

    rangeStart_ = value[SizeType(0)].GetInt();
    rangeEnd_ = value[SizeType(1)].GetInt();

    return true;

}
static void node_set_flip(cocos2d::Sprite *node, const rapidjson::Value &value)
{
    if(value.IsArray() && value.Size() >= 2)
    {
        bool flipX, flipY;
        value[0u] >> flipX;
        value[1] >> flipY;

        node->setFlipX(flipX);
        node->setFlipY(flipY);
    }
bool DictionaryHelper::checkObjectExist_json(const rapidjson::Value &root, int index)
{
    bool bRet = false;
    do {   
        CC_BREAK_IF(root.IsNull());
        CC_BREAK_IF(!root.IsArray());
        CC_BREAK_IF(index < 0 || root.Size() <= (unsigned int )index);
        bRet = true;
    } while (0);

    return bRet;
}
示例#10
0
void JSONArrayToStringSet(const rapidjson::Value& Obj, std::set<T>& Set)
{
    Set.clear();

    if (Obj.IsArray() && !Obj.Empty())
    {
        for (unsigned int i=0; i<Obj.Capacity(); i++)
        {
            if (Obj[i].IsString())
                Set.insert(T(Obj[i].GetString()));
        }
    }
}
示例#11
0
void JSONArrayToStringVector(const rapidjson::Value& Obj, std::vector<std::string>& Vector)
{
    Vector.clear();

    if (Obj.IsArray() && !Obj.Empty())
    {
        for (unsigned int i=0; i<Obj.Capacity(); i++)
        {
            if (Obj[i].IsString())
                Vector.push_back(std::string(Obj[i].GetString()));
        }
    }
}
示例#12
0
bool CAssetsBuilder::Do(ISceneImpl* const& rpScene, const rapidjson::Value& roConfig, const void* const& rpPtr) const
{
  assert(roConfig.IsArray());
  if (!roConfig.IsArray()) return false;

  for (int i = 0; i < static_cast<int>(roConfig.Size()); ++i)
  {
    const rapidjson::Value& jasset = roConfig[i];
    assert(jasset.IsObject());
    if (!jasset.IsObject()) continue;
    const rapidjson::Value& jtype = jasset["type"];
    assert(jtype.IsString());
    const rapidjson::Value& jvalue = jasset["value"];
    assert(jvalue.IsObject());

    std::string type = jtype.GetString();
    if (type == "image")
    {
      if (!jtype.IsString()) continue;
      const rapidjson::Value& jid = jvalue["id"];
      assert(jid.IsString());
      if (!jid.IsString()) continue;
      const rapidjson::Value& jfile = jvalue["file"];
      assert(jfile.IsString());
      if (!jfile.IsString()) continue;

      int width = 0;
      int height = 0;
      unsigned char* buffer_ptr = NULL;
      rpScene->GetAssetPtr()->LoadImagePNG(std::string(rpScene->GetDataPath()) + "/" + jfile.GetString(), width, height, buffer_ptr);
      if (NULL == m_pRender) continue;
      int texid = m_pRender->GenerateTexId(width, height, buffer_ptr);
      rpScene->GetAssetPtr()->PushImageInfo(jid.GetString(), width, height, texid);
    }
  }

  return true;
}
示例#13
0
bool CGlyphListBuilder::Do(ISceneImpl* const& rpScene, const rapidjson::Value& roConfig, std::vector<base::Glyph>& rGlyphList) const
{
  if (!roConfig.IsArray()) return false;

  for (int i = 0; i < static_cast<int>(roConfig.Size()); ++i)
  {
    const rapidjson::Value& jglyph = roConfig[i];
    if (!jglyph.IsObject()) continue;
    base::Glyph glyph;
    if (!CGlyphBuilder::instance.Do(rpScene, jglyph, glyph)) continue;
    rGlyphList.push_back(glyph);
  }
  return (0 >= rGlyphList.size());
}
示例#14
0
std::string Effect_provider::get_defines_source(const rapidjson::Value& defines)
{
	std::stringstream source;

	if (defines.IsArray())
	{
		for (rapidjson::SizeType i = 0; i < defines.Size(); ++i)
		{
			source << "#define " << defines[i].GetString() << std::endl;
		}
	}

	return source.str();
}
bool JSASTNode::ParseStatementArray(const rapidjson::Value &value, Vector<JSASTStatement *> &statements)
{

    assert(value.IsArray());

    for (Value::ConstValueIterator itr = value.Begin(); itr != value.End(); itr++)
    {
        JSASTStatement* stmt = ParseStatement(*itr);
        //assert(stmt);
        statements.Push(stmt);

    }

    return true;
}
示例#16
0
	Mat3x3f Deserialize_Mat3x3f(const rapidjson::Value& value)
	{
		Mat3x3f result;

		assert(value.IsArray());
		assert(value.Size() == 9);

		for (unsigned i = 0; i < 9; ++i)
		{
			assert(value[i].IsNumber());
			result[i] = value[i].GetFloat();
		}

		return result;
	}
bool JSASTNode::ParseExpressionArray(const rapidjson::Value &value, Vector<JSASTExpression *> &expressions)
{

    assert(value.IsArray());

    for (Value::ConstValueIterator itr = value.Begin(); itr != value.End(); itr++)
    {
        JSASTExpression* expr = ParseExpression(*itr);
        //assert(expr);
        expressions.Push(expr);

    }

    return true;
}
示例#18
0
文件: query.cpp 项目: FritzX6/osquery
Status deserializeQueryData(const rj::Value& arr, QueryData& qd) {
  if (!arr.IsArray()) {
    return Status(1);
  }

  for (const auto& i : arr.GetArray()) {
    Row r;
    auto status = deserializeRow(i, r);
    if (!status.ok()) {
      return status;
    }
    qd.push_back(r);
  }
  return Status();
}
示例#19
0
文件: query.cpp 项目: FritzX6/osquery
Status deserializeQueryData(const rj::Value& v, QueryDataSet& qd) {
  if (!v.IsArray()) {
    return Status(1, "JSON object was not an array");
  }

  for (const auto& i : v.GetArray()) {
    Row r;
    auto status = deserializeRow(i, r);
    if (!status.ok()) {
      return status;
    }
    qd.insert(std::move(r));
  }
  return Status();
}
示例#20
0
void Json_Parser::read_print_for_array(rapidjson::Value &va,int i){
    
    if (va.IsBool()) {
        const bool flag=va.GetBool();
        
        CCLOG("%d:%d",i,flag);
    }
    else if (va.IsDouble()) {
        const double flag=va.GetDouble();
        CCLOG("%d:%f",i,flag);
    }
    else if (va.IsInt()) {
        const int flag=va.GetInt();
        CCLOG("%d:%d",i,flag);
    }
    else if (va.IsString()) {
        const std::string flag=va.GetString();
        CCLOG("%d:%s",i,flag.c_str());
    }
    else if (va.IsNull()) {
        
        CCLOG("%d:null",i);
    }
    else if(va.IsObject())
    {
        CCLOG("obj----------%d",i);
        auto it=va.MemberBegin();
        for (;it!=va.MemberEnd();it++) {
            if (va.HasMember(it->name)) {
                read_print(va,it->name.GetString());
                
            }
        }
        
    }
    else if(va.IsArray())
    {
        CCLOG("array-------%d",i);
        for (int i=0; i<va.Size();i++) {
            
            read_print_for_array(va[i],i);
            
            
        }
        
    }
    
}
// parse coordinate pair from JSON array
osmium::geom::Coordinates parse_coordinate(const rapidjson::Value& value) {
    if (!value.IsArray()) {
        throw config_error{"Coordinates must be an array."};
    }

    const auto array = value.GetArray();
    if (array.Size() != 2) {
        throw config_error{"Coordinates array must have exactly two elements."};
    }

    if (array[0].IsNumber() && array[1].IsNumber()) {
        return osmium::geom::Coordinates{array[0].GetDouble(), array[1].GetDouble()};
    }

    throw config_error{"Coordinates array must contain numbers."};
}
示例#22
0
void Client::parseExtensions(const rapidjson::Value &value)
{
    if (!value.IsArray()) {
        return;
    }

    for (const rapidjson::Value &ext : value.GetArray()) {
        if (!ext.IsString()) {
            continue;
        }

        if (strcmp(ext.GetString(), "nicehash") == 0) {
            m_nicehash = true;
        }
    }
}
示例#23
0
bool fromJson(const rapidjson::Value &v, Vec<ElementType, Size> &dst)
{
    if (!v.IsArray()) {
        dst = Vec<ElementType, Size>(as<ElementType>(v));
        return true;
    }
    ASSERT(v.Size() == 1 || v.Size() == Size,
        "Cannot convert Json Array to vector: Invalid size. Expected 1 or %d, received %d", Size, v.Size());

    if (v.Size() == 1)
        dst = Vec<ElementType, Size>(as<ElementType>(v[0u]));
    else
        for (unsigned i = 0; i < Size; ++i)
            dst[i] = as<ElementType>(v[i]);
    return true;
}
示例#24
0
文件: utils.hpp 项目: raphaelrpl/tws
template<class InputIterator> inline void
tws::core::copy_numeric_array(InputIterator first,
                              InputIterator last,
                              rapidjson::Value& jvalues,
                              rapidjson::Document::AllocatorType& allocator)
{
  if(!jvalues.IsArray())
    throw conversion_error() << tws::error_description("copy_numeric_array: can only copy arrays of numeric data.");
  
  while(first != last)
  {
    jvalues.PushBack(*first, allocator);
    
    ++first;
  }
}
示例#25
0
void Json_Parser::read_to_map_for_array(cocos2d::ValueVector &temp,rapidjson::Value &va,int i){
     CCLOG("dex:%d",i);
    if (va.IsBool()) {
        const bool flag=va.GetBool();
          temp.push_back(Value(flag));
    }
    else if (va.IsDouble()) {
        const double flag=va.GetDouble();
         temp.push_back(Value(flag));
    }
    else if (va.IsInt()) {
        const int flag=va.GetInt();
          temp.push_back(Value(flag));
    }
    else if (va.IsString()) {
        const std::string flag=va.GetString();
        temp.push_back(Value(flag));
       // CCLOG("++:%d",temp.size());
    }
    else if (va.IsNull()) {
      
           temp.push_back(Value(nullptr));
        
    }
    else if(va.IsObject())
    {
        cocos2d::ValueMap temp2;
        auto it=va.MemberBegin();
        for (;it!=va.MemberEnd();it++) {
            if (va.HasMember(it->name)) {
                read_to_map(temp2,va,it->name.GetString());
            }
        }
           temp.push_back(Value(temp2));
        // CCLOG("mapinvectro层:%lu",temp2.size());
    }
    else if(va.IsArray())
    {
        cocos2d::ValueVector temp2;
        for (int i=0; i<va.Size();i++) {
            read_to_map_for_array(temp2,va[i],i);
        }
         temp.push_back(Value(temp2));
        // CCLOG("vectorinvectro层:%lu",temp.size());
    }
    
}
                Eegeo::v4 HighlightColorMapper::GetColorFromValue(rapidjson::Value& value) const {
                    if (value.IsArray()) {
                        Eegeo::v4 highlightColor = m_defaultColor;

                        if (value.Size() == 4) {
                            highlightColor.Set(value[0].GetDouble() / 255.0,
                                               value[1].GetDouble() / 255.0,
                                               value[2].GetDouble() / 255.0,
                                               value[3].GetDouble() / 255.0);
                        }

                        return highlightColor;
                    }
                    else {
                        return m_defaultColor;
                    }
                }
示例#27
0
std::array<T, Size> get_array(const rapidjson::Value& arr)
{
  if (arr.IsArray())
  {
    assert(arr.Size() == Size);
    std::array<T, Size> ret;
    for (rapidjson::SizeType i = 0; i < arr.Size(); i++)
    {
      ret[i] = get_value<T>(arr[i]);
    }
    return ret;
  }
  else
  {
    throw std::system_error(std::error_code(), "Parse error.");
  }
}
示例#28
0
    //-----------------------------------------------------------------------------------
    ResourceAccess::ResourceAccess HlmsJsonCompute::parseAccess( const rapidjson::Value &json )
    {
        uint8 access = 0;
        if( json.IsArray() )
        {
            for( rapidjson::SizeType i=0; i<json.Size(); ++i )
            {
                if( json[i].IsString() )
                    access |= parseAccess( json[i].GetString() );
            }
        }
        else if( json.IsString() )
        {
            access = parseAccess( json.GetString() );
        }

        return static_cast<ResourceAccess::ResourceAccess>( access );
    }
std::vector<osmium::geom::Coordinates> parse_ring(const rapidjson::Value& value) {
    if (!value.IsArray()) {
        throw config_error{"Ring must be an array."};
    }

    const auto array = value.GetArray();
    if (array.Size() < 3) {
        throw config_error{"Ring must contain at least three coordinate pairs."};
    }

    std::vector<osmium::geom::Coordinates> coordinates;

    for (const rapidjson::Value& item : array) {
        coordinates.push_back(parse_coordinate(item));
    }

    return coordinates;
}
std::size_t parse_multipolygon_array(const rapidjson::Value& value, osmium::memory::Buffer& buffer) {
    assert(value.IsArray());
    const auto array = value.GetArray();
    if (array.Empty()) {
        throw config_error{"Multipolygon must contain at least one polygon array."};
    }

    {
        osmium::builder::AreaBuilder builder{buffer};
        for (const auto& polygon : array) {
            if (!polygon.IsArray()) {
                throw config_error{"Polygon must be an array."};
            }
            parse_rings(polygon, builder);
        }
    }

    return buffer.commit();
}