Example #1
0
// Convert rapidjson value to JSON value.
static void ToJSONValue(JSONValue& jsonValue, const rapidjson::Value& rapidjsonValue)
{
    switch (rapidjsonValue.GetType())
    {
    case kNullType:
        // Reset to null type
        jsonValue.SetType(JSON_NULL);
        break;

    case kFalseType:
        jsonValue = false;
        break;

    case kTrueType:
        jsonValue = true;
        break;

    case kNumberType:
        if (rapidjsonValue.IsInt())
            jsonValue = rapidjsonValue.GetInt();
        else if (rapidjsonValue.IsUint())
            jsonValue = rapidjsonValue.GetUint();
        else
            jsonValue = rapidjsonValue.GetDouble();
        break;

    case kStringType:
        jsonValue = rapidjsonValue.GetString();
        break;

    case kArrayType:
        {
            jsonValue.Resize(rapidjsonValue.Size());
            for (unsigned i = 0; i < rapidjsonValue.Size(); ++i)
            {
                ToJSONValue(jsonValue[i], rapidjsonValue[i]);
            }
        }
        break;

    case kObjectType:
        {
            jsonValue.SetType(JSON_OBJECT);
            for (rapidjson::Value::ConstMemberIterator i = rapidjsonValue.MemberBegin(); i != rapidjsonValue.MemberEnd(); ++i)
            {
                JSONValue& value = jsonValue[String(i->name.GetString())];
                ToJSONValue(value, i->value);
            }
        }
        break;

    default:
        break;
    }
}
Example #2
0
void PrintValue(rapidjson::Value &value)
{
	rapidjson::Type type = value.GetType();

	if (type == rapidjson::Type::kNumberType)
	{
		printf("%d", value.GetInt());
	}
	else if (type == rapidjson::Type::kStringType)
	{
		printf("%s", value.GetString());
	}
	else if (type == rapidjson::Type::kTrueType)
	{
		printf("가능");
	}
	else if (type == rapidjson::Type::kFalseType)
	{
		printf("불가능");
	}
	else if (type == rapidjson::Type::kArrayType)
	{
		for (int i = 0; i < value.Size(); i++)
		{
			PrintValue(value[i]);
			if (i < value.Size() - 1)
				printf(", ");
		}
		printf("\n");
	}
	else if (type == rapidjson::Type::kObjectType)
	{
		for (auto iter = value.MemberBegin(); iter != value.MemberEnd(); iter++)
		{
			rapidjson::Value &member = iter->value;
			std::string name = iter->name.GetString();

			if (member.GetType() == rapidjson::Type::kObjectType || member.GetType() == rapidjson::Type::kArrayType)
			{
				printf("\n- %s -\n", name.c_str());
				PrintValue(member);
			}
			else
			{
				printf("%s : ", name.c_str());
				PrintValue(member);
				printf("\n");
			}
		}
	}
	else
	{
		printf("Null");
	}
}
Example #3
0
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();
  }
}
Example #4
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;
}
Example #5
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;
}
Example #6
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);
  }
}
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.");
  }
}
Example #8
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());
     }
 }
Example #9
0
 //-----------------------------------------------------------------------------------
 void HlmsJsonPbs::parseScale( const rapidjson::Value &jsonArray, Vector4 &offsetScale )
 {
     const rapidjson::SizeType arraySize = std::min( 2u, jsonArray.Size() );
     for( rapidjson::SizeType i=0; i<arraySize; ++i )
     {
         if( jsonArray[i].IsNumber() )
             offsetScale[i+2u] = static_cast<float>( jsonArray[i].GetDouble() );
     }
 }
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;
}
Example #13
0
    //-----------------------------------------------------------------------------------
    inline Vector3 HlmsJsonPbs::parseVector3Array( const rapidjson::Value &jsonArray )
    {
        Vector3 retVal( Vector3::ZERO );

        const rapidjson::SizeType arraySize = std::min( 3u, jsonArray.Size() );
        for( rapidjson::SizeType i=0; i<arraySize; ++i )
        {
            if( jsonArray[i].IsNumber() )
                retVal[i] = static_cast<float>( jsonArray[i].GetDouble() );
        }

        return retVal;
    }
Example #14
0
// 装備状態の確認
bool GameEventHelper::detectEquipFlg(rapidjson::Value& json, bool negative)
{
    bool detection { false };

    for(int i { 0 }; i < json.Size(); i++)
    {
        detection = PlayerDataManager::getInstance()->getLocalData()->isEquipedItem(stoi(json[i].GetString()));
        if(negative) detection = !detection;
        if(!detection) break;
    }
    
    return detection;
}
Example #15
0
void BgMap::initGridData(rapidjson::Value & arr)
{
    m_grid = new unsigned char*[m_gridCol];
    for (unsigned int i=0; i<m_gridCol; i++)
    {
        m_grid[i] = new unsigned char[m_gridRow];
    }
    
    int size = arr.Size();
    for (unsigned int i=0; i<size; i++)
    {
        m_grid[i/m_gridRow][i%m_gridRow] = arr[i].GetInt();
    }
}
Example #16
0
    //-----------------------------------------------------------------------------------
    inline ColourValue HlmsJsonPbs::parseColourValueArray( const rapidjson::Value &jsonArray,
                                                           const ColourValue &defaultValue )
    {
        ColourValue retVal( defaultValue );

        const rapidjson::SizeType arraySize = std::min( 4u, jsonArray.Size() );
        for( rapidjson::SizeType i=0; i<arraySize; ++i )
        {
            if( jsonArray[i].IsNumber() )
                retVal[i] = static_cast<float>( jsonArray[i].GetDouble() );
        }

        return retVal;
    }
Example #17
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());
}
Example #18
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 PropertyItemType::loadValue(const rapidjson::Value & config)
    {
        if(!config.IsArray() || config.Size() < 2)
        {
            LOG_ERROR("Invalid value type");
            return false;
        }
        
        const rapidjson::Value * value = nullptr;

        value = &config[0u];
        if(!value->IsString())
        {
            LOG_ERROR("Invalid item type, #0 must be a string type.");
            return false;
        }
        type_ = value->GetString();

        value = &config[1];
        if(!value->IsString())
        {
            LOG_ERROR("Invalid item type, #1 must be a string type.");
            return false;
        }
        name_ = value->GetString();
        
        if(config.Size() > 2)
        {
            value = &config[2];
            if(value->IsString())
            {
                desc_ = value->GetString();
            }
        }
        
        return true;
    }
Example #20
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;
	}
Example #21
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);
            
            
        }
        
    }
    
}
Example #22
0
/// Parses a set of capabilities in the HSS response to a vector of integers.
bool ICSCFRouter::parse_capabilities(rapidjson::Value& caps,
                                     std::vector<int>& parsed_caps)
{
  for (size_t ii = 0; ii < caps.Size(); ++ii)
  {
    if (caps[(int)ii].IsUint())
    {
      parsed_caps.push_back(caps[(int)ii].GetUint());
    }
    else
    {
      return false;
    }
  }
  return true;
}
Example #23
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;
                    }
                }
Example #25
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 );
    }
Example #26
0
void printObj(const rapidjson::Value& data) {
    if (data.IsObject()) {
        for (rapidjson::Value::ConstMemberIterator itr = data.MemberBegin(); itr != data.MemberEnd(); ++itr) {
            printf("obj[%s] = ", itr->name.GetString());
            switch (itr->value.GetType()) {
                case 0:
                    printf("IsNull!");
                    break;
                case 1:
                    printf("False");
                    break;
                case 2:
                    printf("True");
                    break;
                case 3:
                    // IsObject
                    printf("{\n");
                    printObj(itr->value);
                    printf("}\n");
                    break;
                case 4:
                    // IsArray
                    printf("[\n");
                    printObj(itr->value);
                    printf("]\n");
                    break;
                case 5:
                    printf("%s", itr->value.GetString());
                    break;
                case 6:
                    printf("%d", itr->value.GetInt());
                    break;
            }

            printf("\n");
        }
    } else {
        for (rapidjson::SizeType i = 0; i < data.Size(); i++) {
            printf("{\n");
            printObj(data[i]);
            printf("}, \n");
        }
    }
}
Example #27
0
args_manager::args_manager(const rapidjson::Value& description)
{
    if ( description.IsArray() ){
        for (rapidjson::SizeType j = 0; j < description.Size(); j++){
            const rapidjson::Value& next_arg = description[j];
            const rapidjson::Value& name = next_arg["arg"];
            const rapidjson::Value& value = next_arg["value"];
            
            if ( name.IsString() ){
                if ( value.IsNumber() ){
                    this->set_float_arg(name.GetString(), value.GetDouble());
                } else if ( value.IsBool() ){
                    this->set_bool_arg(name.GetString(), value.GetBool());
                } else if ( value.IsString() ){
                    this->set_string_arg(name.GetString(), value.GetString());
                }
            }
        }
    }
}
Example #28
0
void Effect_provider::load_data_type_descriptions(const rapidjson::Value& layout_node, Shader_data_layout& layout) const
{
	if (!layout_node.IsArray())
	{
		return;
	}

	for (rapidjson::SizeType i = 0; i < layout_node.Size(); ++i)
	{
		Shader_data_struct data_struct;

		if (Shader_data_struct::load(data_struct, layout_node[i]))
		{
			if (!data_struct.elements.empty())
			{
				layout.add_description(data_struct.name, data_struct);
			}
		}
	}
}
Example #29
0
// トロフィー所持確認
bool GameEventHelper::detectTrophyFlg(rapidjson::Value& json, bool negative)
{
    bool detection { false };
    
    // 複数のトロフィー
    if (json.IsArray())
    {
        for (int i { 0 }; i < json.Size(); i++)
        {
            detection = PlayerDataManager::getInstance()->getGlobalData()->hasTrophy(stoi(json[i].GetString()));
            if (negative) detection = !detection;
            if (!detection) break;
        }
    }
    else
    {
        detection = PlayerDataManager::getInstance()->getGlobalData()->hasTrophy(stoi(json.GetString()));
        if(negative) detection = !detection;
    }
    return detection;
}
Example #30
0
std::vector<tws::geoarray::dimension_t>
tws::geoarray::read_dimensions(const rapidjson::Value& jdims)
{
  if(!jdims.IsArray() || jdims.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing array dimensions in metadata.");

  std::vector<dimension_t> dims;

  const rapidjson::SizeType nelements = jdims.Size();

  for(rapidjson::SizeType i = 0; i != nelements; ++i)
  {
    const rapidjson::Value& jdim = jdims[i];

    if(jdim.IsNull())
      continue;

    dims.push_back(read_dimension(jdim));
  }

  return dims;
}