Exemplo n.º 1
1
    void json2tvalue(QVariant & output, const rapidjson::Value & input, int itype)
    {
        if(input.IsNull())
        {
            output.clear();
        }
        else if(input.IsInt64())
        {
            output = QVariant(input.GetInt64());
        }
        else if(input.IsInt())
        {
            output = QVariant(input.GetInt());
        }
        else if(input.IsDouble())
        {
            output = QVariant(input.GetDouble());
        }
        else if(input.IsBool())
        {
            output = QVariant(input.GetBool());
        }
        else if(input.IsString())
        {
            output = QVariant(QString(input.GetString()));
        }
        else if(input.IsArray())
        {
            switch(itype)
            {
            case QVariant::Point:
            {
                assert(input.Size() == 2);
                output = QPoint(input[0u].GetDouble(), input[1].GetDouble());
                break;
            }
            case QVariant::PointF:
            {
                assert(input.Size() == 2);
                output = QPointF(input[0u].GetDouble(), input[1].GetDouble());
                break;
            }
            case QVariant::Size:
            {
                assert(input.Size() == 2);
                output = QSize(input[0u].GetDouble(), input[1].GetDouble());
                break;
            }
            case QVariant::SizeF:
            {
                assert(input.Size() == 2);
                output = QSizeF(input[0u].GetDouble(), input[1].GetDouble());
                break;
            }
            case QVariant::Rect:
            {
                assert(input.Size() == 4);
                output = QRect(input[0u].GetDouble(), input[1].GetDouble(), input[2].GetDouble(), input[3].GetDouble());
                break;
            }
            case QVariant::RectF:
            {
                assert(input.Size() == 4);
                output = QRectF(input[0u].GetDouble(), input[1].GetDouble(), input[2].GetDouble(), input[3].GetDouble());
                break;
            }
            case QVariant::Vector2D:
            {
                assert(input.Size() == 2);
                output = QVector2D(input[0u].GetDouble(), input[1].GetDouble());
                break;
            }
            case QVariant::Vector3D:
            {
                assert(input.Size() == 3);
                output = QVector3D(input[0u].GetDouble(), input[1].GetDouble(), input[2].GetDouble());
                break;
            }
            case QVariant::Vector4D:
            {
                assert(input.Size() == 4);
                output = QVector4D(input[0u].GetDouble(), input[1].GetDouble(), input[2].GetDouble(), input[3].GetDouble());
                break;
            }
            case QVariant::Color:
            {
                assert(input.Size() == 4);
                output = QColor(input[0u].GetDouble(), input[1].GetDouble(), input[2].GetDouble(), input[3].GetDouble());
                break;
            }
            case QVariant::StringList:
            {
                QStringList list;
                list.reserve(input.Size());

                for(rapidjson::Value::ConstValueIterator it = input.Begin(); it != input.End(); ++it)
                {
                    QString tmp(it->GetString());
                    list.append(tmp);
                }
                output = list;
                break;
            }
            case QVariant::List:
            default:
            {
                QList<QVariant> list;
                list.reserve(input.Size());

                for(rapidjson::SizeType i = 0; i < input.Size(); ++i)
                {
                    QVariant tmp;
                    json2tvalue(tmp, input[i], QVariant::Invalid);
                    list.append(tmp);
                }
                output = list;
                break;
            }
            }
        }
        else if(input.IsObject())
        {
            QMap<QString, QVariant> map;

            for(rapidjson::Value::ConstMemberIterator it= input.MemberBegin();
                it != input.MemberEnd(); ++it)
            {
                QString qstring(QLatin1String(it->name.GetString(), it->name.GetStringLength()));
                QVariant qvalue;
                json2tvalue(qvalue, it->value, QVariant::Invalid);

                map.insert(qstring, qvalue);
            }

            output = map;
        }
        else
        {
            output.clear();
            assert(false && "shouldn't execute to here.");
        }
    }
Exemplo n.º 2
0
void JSONObjectToDetailedWares(const rapidjson::Value& Obj,
                               FluidHubAPIClient::WaresDetailsByID_t& WMap)
{
    WMap.clear();

    if (Obj.IsObject())
    {
        for (rapidjson::Value::ConstMemberIterator it = Obj.MemberBegin(); it != Obj.MemberEnd(); ++it)
        {
            if (it->value.IsObject())
            {
                std::string WareID = it->name.GetString();

                WMap[WareID] = FluidHubAPIClient::WareDetailedDescription();

                rapidjson::Value::ConstMemberIterator itMember = it->value.FindMember("shortdesc");
                if (itMember != it->value.MemberEnd() && itMember->value.IsString())
                {
                    WMap[WareID].ShortDescription = std::string(itMember->value.GetString());
                }

                itMember = it->value.FindMember("git-url");
                if (itMember != it->value.MemberEnd() && itMember->value.IsString())
                {
                    WMap[WareID].GitUrl = std::string(itMember->value.GetString());
                }

                itMember = it->value.FindMember("git-branches");
                if (itMember != it->value.MemberEnd() && itMember->value.IsArray())
                {
                    JSONArrayToStringVector(itMember->value,WMap[WareID].GitBranches);
                }

                itMember = it->value.FindMember("issues-counts");
                if (itMember != it->value.MemberEnd() && itMember->value.IsObject())
                {
                    for (rapidjson::Value::ConstMemberIterator itCounters = itMember->value.MemberBegin();
                            itCounters != itMember->value.MemberEnd();
                            ++itCounters)
                    {
                        if (itCounters->value.IsInt())
                            WMap[WareID].IssuesCounters[itCounters->name.GetString()] = itCounters->value.GetInt();
                    }
                }

                itMember = it->value.FindMember("users-ro");
                if (itMember != it->value.MemberEnd() && itMember->value.IsArray())
                {
                    JSONArrayToStringSet(itMember->value,WMap[WareID].ROUsers);
                }

                itMember = it->value.FindMember("users-rw");
                if (itMember != it->value.MemberEnd() && itMember->value.IsArray())
                {
                    JSONArrayToStringSet(itMember->value,WMap[WareID].RWUsers);
                }
            }
        }
    }
}
Exemplo n.º 3
0
bool JSASTProgram::Parse(const rapidjson::Value& value)
{
    JSASTNode::Parse(value);

    for (Value::ConstMemberIterator itr = value.MemberBegin();
         itr != value.MemberEnd(); ++itr)
    {
        String name = itr->name.GetString();

        if (name == "body")
        {
            ParseStatementArray(itr->value, body_);
        }

        if (name == "comments")
        {
            if (itr->value.IsArray())
            {
                for (Value::ConstValueIterator citr = itr->value.Begin();
                     citr != itr->value.End();
                     citr++)
                {
                    JSASTComment* comment = new JSASTComment();
                    assert(citr->IsObject());
                    comment->Parse(*citr);
                    comments_.Push(comment);
                }
            }
        }

    }

    return true;

}
Exemplo n.º 4
0
bool JSASTNode::Parse(const rapidjson::Value& value)
{
    assert(value.IsObject());

    for (Value::ConstMemberIterator itr = value.MemberBegin();
         itr != value.MemberEnd(); ++itr)
    {
        String name = itr->name.GetString();

        if (name == "loc")
        {
            ParseLoc(itr->value);
        }
        else if (name == "type")
        {
            // TODO: Verify type
        }
        else if (name == "range")
        {
            ParseRange(itr->value);
        }

    }

    return true;

}
Exemplo n.º 5
0
void parseState(const std::string& tag, const rapidjson::Value& button, std::unordered_map<std::string, TexturePtr>& stateMap) {
	for (auto it = button.MemberBegin(); it != button.MemberEnd(); it++) {
		std::string name = it->name.GetString();
		const rapidjson::Value& value = it->value;
		TexturePtr texture(GCC_NEW Texture(tag, value["x"].GetDouble(), value["y"].GetDouble(), value["w"].GetDouble(), value["h"].GetDouble()));
		stateMap.emplace(name, texture);
	}
}
Exemplo n.º 6
0
 void Inspector::applyConfigToView(const rapidjson::Value &config)
 {
     for(rapidjson::Value::ConstMemberIterator it = config.MemberBegin();
         it != config.MemberEnd(); ++it)
     {
         setTargetProperty(it->name.GetString(), it->value);
     }
 }
Exemplo n.º 7
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;
    }
}
Exemplo n.º 8
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");
	}
}
Exemplo n.º 9
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);
            
            
        }
        
    }
    
}
Exemplo n.º 10
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());
    }
    
}
Exemplo n.º 11
0
void SettingRegistry::handleChildren(const rapidjson::Value& settings_list, std::list<std::string>& path, SettingsBase* settings_base, bool warn_duplicates)
{
    if (!settings_list.IsObject())
    {
        logError("ERROR: json settings list is not an object!\n");
        return;
    }
    for (rapidjson::Value::ConstMemberIterator setting_iterator = settings_list.MemberBegin(); setting_iterator != settings_list.MemberEnd(); ++setting_iterator)
    {
        handleSetting(setting_iterator, path, settings_base, warn_duplicates);
        if (setting_iterator->value.HasMember("children"))
        {
            std::list<std::string> path_here = path;
            path_here.push_back(setting_iterator->name.GetString());
            handleChildren(setting_iterator->value["children"], path_here, settings_base, warn_duplicates);
        }
    }
}
Exemplo n.º 12
0
 bool PropertyItemType::loadChildren(const rapidjson::Value &config)
 {
     for(rapidjson::Value::ConstMemberIterator it = config.MemberBegin();
         it != config.MemberEnd(); ++it)
     {
         PropertyItemType *child = new PropertyItemType();
         child->key_ = it->name.GetString();
         
         if(!child->loadValue(it->value))
         {
             delete child;
             return false;
         }
         this->items_.push_back(child);
     }
     
     return true;
 }
Exemplo n.º 13
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");
        }
    }
}
Exemplo n.º 14
0
    //-----------------------------------------------------------------------------------
    void HlmsJsonCompute::loadJobs( const rapidjson::Value &json, const HlmsJson::NamedBlocks &blocks )
    {
        HlmsCompute *hlmsCompute = mHlmsManager->getComputeHlms();

        StringVector pieceFiles;

        rapidjson::Value::ConstMemberIterator itJob = json.MemberBegin();
        rapidjson::Value::ConstMemberIterator enJob = json.MemberEnd();

        while( itJob != enJob )
        {
            if( itJob->value.IsObject() )
            {
                const String jobName( itJob->name.GetString(), itJob->name.GetStringLength() );
                pieceFiles.clear();

                rapidjson::Value::ConstMemberIterator itor = itJob->value.FindMember( "pieces" );
                if( itor != itJob->value.MemberEnd() && itor->value.IsString() )
                    pieceFiles.push_back( itor->value.GetString() );
                else if( itor != itJob->value.MemberEnd() && itor->value.IsArray() )
                {
                    const rapidjson::Value &jsonArray = itor->value;
                    for( rapidjson::SizeType i=0; i<jsonArray.Size(); ++i )
                    {
                        if( jsonArray[i].IsString() )
                            pieceFiles.push_back( jsonArray[i].GetString() );
                    }
                }

                itor = itJob->value.FindMember( "source" );
                if( itor != itJob->value.MemberEnd() && itor->value.IsString() )
                {
                    HlmsComputeJob *job = hlmsCompute->createComputeJob( jobName, jobName,
                                                                         itor->value.GetString(),
                                                                         pieceFiles );
                    loadJob( itJob->value, blocks, job, jobName );
                }
            }

            ++itJob;
        }
    }
Exemplo n.º 15
0
bool IdMessage::parsePayload(rapidjson::Value& value, IceServalBridge* bridge)
{
  if (false == value.IsObject())
  {
    _log->error("Payload could not be parsed: Is not an object");
    return false;
  }

  for (auto it = value.MemberBegin(); it != value.MemberEnd(); ++it)
  {
    if (false == it->name.IsString() || false == it->value.IsString())
    {
      _log->error("Payload could not be parsed: Id is not a string");
      return false;
    }

    this->ids.push_back(std::make_tuple(it->name.GetString(), it->value.GetString()));
  }

  return true;
}
Exemplo n.º 16
0
void CPlayer::Deserialize(rapidjson::Value& json)
{
	for (rapidjson::Value::MemberIterator it = json.MemberBegin(); it != json.MemberEnd(); ++it) {

		if (it->value.IsInt()) {
			SetFieldInt(GetFieldType(it->name.GetString()), it->value.GetInt());
		}
		else if (it->value.IsInt64()) {
			SetFieldI64(GetFieldType(it->name.GetString()), it->value.GetInt64());
		}
		else if (it->value.IsString()) {
			SetFieldStr(GetFieldType(it->name.GetString()), it->value.GetString());
		}
		else if (it->value.IsArray()) {

		}
		else if (it->value.IsObject()) {

		}
	}
}
Exemplo n.º 17
0
bool Account::load_config(rapidjson::Value& obj)
{
    if (!obj.IsObject()) {
        return false;
    }
    m_properties["Name"] = m_name;
    m_protocol = Protocol::from_object(obj["Protocol"], obj["Config"]);
    obj.RemoveMember("Config");
    if (obj.HasMember("Interval") && obj["Interval"].IsUint()) {
        unsigned interval = obj["Interval"].GetUint();
        if (interval > 0) {
            m_interval = interval;
        }
    }
    for (auto it = obj.MemberBegin(); it != obj.MemberEnd(); ++it) {
        if (Application::read_event(m_notifications, it)) {
            it->value.SetNull();
        }
    }
    Application::generate_properties("", m_properties, obj);
    return m_protocol != nullptr;
}
Exemplo n.º 18
0
double traverse_rapidjson(const rapidjson::Value &v)
{
	double x = 0;
	if (v.IsObject())
	{
		for (auto i = v.MemberBegin(); i != v.MemberEnd(); ++i)
		{
			x += traverse_rapidjson(i->value);
		}
	}
	else if (v.IsArray())
	{
		for (auto i = v.Begin(); i != v.End(); ++i)
		{
			x += traverse_rapidjson(*i);
		}
	}
	else if (v.IsNumber())
	{
		x = v.GetDouble();
	}
	return x;
}
Exemplo n.º 19
0
static void parseValue(SettingValue &value, const rapidjson::Value &json_val)
{
    if (json_val.IsInt())
        value = json_val.GetInt();
    else if (json_val.IsString())
        value = std::string(json_val.GetString(), json_val.GetStringLength());
    else if (json_val.IsBool())
        value = json_val.GetBool();
    else if (json_val.IsArray())
    {
        SettingList value_list;

        for (auto it = json_val.Begin(); it != json_val.End(); ++it)
        {
            SettingValue child_val;
            parseValue(child_val, *it);
            value_list.push_back(child_val);
        }

        value = value_list;
    }
    else if (json_val.IsObject())
    {
        SettingMap value_map;

        for (auto it = json_val.MemberBegin(); it != json_val.MemberEnd(); ++it)
        {
            SettingValue child_val;
            parseValue(child_val, it->value);
            value_map[it->name.GetString()] = child_val;
        }

        value = value_map;
    }
    else
        throw std::runtime_error("Unexpected JSON value type.");
}
Exemplo n.º 20
0
void CMetadata::_objJsonToBson(rapidjson::Value& json, mongo::BSONObjBuilder& objBuilder)
{
	for (rapidjson::Value::MemberIterator it = json.MemberBegin(); it != json.MemberEnd(); ++it) {
		this->_fieldJsonToBson(json, it->name.GetString(), objBuilder);
	}
}
Exemplo n.º 21
0
void ConvertToMsgPack(const rapidjson::Value& json, msgpack::object& object, msgpack::zone& zone)
{
	switch (json.GetType())
	{
		case rapidjson::kFalseType:
			object = false;
			break;

		case rapidjson::kTrueType:
			object = true;
			break;

		case rapidjson::kNumberType:
		{
			if (json.IsInt())
			{
				object = json.GetInt();
			}
			else if (json.IsUint())
			{
				object = json.GetUint();
			}
			else if (json.IsInt64())
			{
				object = json.GetInt64();
			}
			else if (json.IsUint64())
			{
				object = json.GetUint64();
			}
			else if (json.IsDouble())
			{
				object = json.GetDouble();
			}

			break;
		}

		case rapidjson::kStringType:
			// we allocate with 'zone', otherwise the std::string's raw pointer gets used, which won't work as it gets destructed later on
			object = msgpack::object(std::string(json.GetString(), json.GetStringLength()), zone);
			break;

		case rapidjson::kObjectType:
		{
			std::map<std::string, msgpack::object> list;

			for (auto it = json.MemberBegin(); it != json.MemberEnd(); it++)
			{
				msgpack::object newObject;
				ConvertToMsgPack(it->value, newObject, zone);

				list.insert({ it->name.GetString(), newObject });
			}

			object = msgpack::object(list, zone);

			break;
		}

		case rapidjson::kArrayType:
		{
			std::vector<msgpack::object> list;

			for (auto it = json.Begin(); it != json.End(); it++)
			{
				msgpack::object newObject;
				ConvertToMsgPack(*it, newObject, zone);

				list.push_back(newObject);
			}

			object = msgpack::object(list, zone);

			break;
		}

		default:
			object = msgpack::type::nil();
			break;
	}
}
Exemplo n.º 22
0
Arquivo: rf.cpp Projeto: rkday/ralf
// Create an ACR message from a JSON descriptor.  Most AVPs are auto-created from the
// contents parameter which should be a JSON object with keys named after AVPs.  For example
// this object could be the "event" part of the original HTTP request received by Ralf.
AccountingRequest::AccountingRequest(const Dictionary* dict,
                                     Diameter::Stack* diameter_stack,
                                     const std::string& session_id,
                                     const std::string& dest_host,
                                     const std::string& dest_realm,
                                     const uint32_t& record_number,
                                     const rapidjson::Value& contents) :
  Diameter::Message(dict, dict->ACCOUNTING_REQUEST, diameter_stack)
{
  LOG_DEBUG("Building an Accounting-Request");

  // Fill in the default fields
  if (session_id == "")
  {
    add_new_session_id();
  }
  else
  {
    add_session_id(session_id);
  }
  add_origin();
  add_app_id(Dictionary::Application::ACCT, dict->RF);

  // Fill in contributed fields
  Diameter::Dictionary::AVP dest_host_dict("Destination-Host");
  Diameter::AVP dest_host_avp(dest_host_dict);
  add(dest_host_avp.val_str(dest_host));

  Diameter::Dictionary::AVP dest_realm_dict("Destination-Realm");
  Diameter::AVP dest_realm_avp(dest_realm_dict);
  add(dest_realm_avp.val_str(dest_realm));

  Diameter::Dictionary::AVP record_number_dict("Accounting-Record-Number");
  Diameter::AVP record_number_avp(record_number_dict);
  add(record_number_avp.val_i32(record_number));

  if (contents.GetType() != rapidjson::kObjectType)
  {
    LOG_ERROR("Cannot build ACR from JSON type %d", contents.GetType());
    return;
  }

  // Fill in the dynamic fields
  for (rapidjson::Value::ConstMemberIterator it = contents.MemberBegin();
       it != contents.MemberEnd();
       ++it)
  {
    try
    {
      switch (it->value.GetType())
      {
      case rapidjson::kFalseType:
      case rapidjson::kTrueType:
      case rapidjson::kNullType:
        LOG_ERROR("Invalid format (true/false) in JSON block, ignoring");
        continue;
      case rapidjson::kStringType:
      case rapidjson::kNumberType:
      case rapidjson::kObjectType:
        {
          Diameter::Dictionary::AVP new_dict(VENDORS, it->name.GetString());
          Diameter::AVP avp(new_dict);
          add(avp.val_json(VENDORS, new_dict, it->value));
        }
        break;
      case rapidjson::kArrayType:
        for (rapidjson::Value::ConstValueIterator array_iter = it->value.Begin();
             array_iter !=  it->value.End();
             ++array_iter)
        {
          Diameter::Dictionary::AVP new_dict(VENDORS, it->name.GetString());
          Diameter::AVP avp(new_dict);
          add(avp.val_json(VENDORS, new_dict, *array_iter));
        }
        break;
      }
    }
    catch (Diameter::Stack::Exception e)
    {
      LOG_WARNING("AVP %s not recognised, ignoring", it->name.GetString());
    }
  }
}
Exemplo n.º 23
0
void CMetadata::_objJsonToJson(rapidjson::Value& desjson, rapidjson::Value& srcjson)
{
	for (rapidjson::Value::MemberIterator it = srcjson.MemberBegin(); it != srcjson.MemberEnd(); ++it) {
		this->_fieldJsonToJson(desjson, it->name.GetString(), srcjson);
	}
}
Exemplo n.º 24
0
void SettingRegistry::_addSettingsToCategory(SettingCategory* category, const rapidjson::Value& json_object, SettingConfig* parent, bool add_to_settings)
{
    for (rapidjson::Value::ConstMemberIterator setting_iterator = json_object.MemberBegin(); setting_iterator != json_object.MemberEnd(); ++setting_iterator)
    {
        const rapidjson::Value& data = setting_iterator->value;
        
        std::string label;
        if (!setting_iterator->value.HasMember("label") || !data["label"].IsString())
        {
            label = "N/A";
        }
        else
        {
            label = data["label"].GetString();
        }

        /// Create the new setting config object.
        SettingConfig* config;
        if (parent)
            config = parent->addChild(setting_iterator->name.GetString(), label);
        else
            config = category->addChild(setting_iterator->name.GetString(), label);
        
        
        /// Fill the setting config object with data we have in the json file.
        if (data.HasMember("type") && data["type"].IsString())
        {
            config->setType(data["type"].GetString());
        }
        if (data.HasMember("default"))
        {
            const rapidjson::Value& dflt = data["default"];
            if (dflt.IsString())
            {
                config->setDefault(dflt.GetString());
            }
            else if (dflt.IsTrue())
            {
                config->setDefault("true");
            }
            else if (dflt.IsFalse())
            {
                config->setDefault("false");
            }
            else if (dflt.IsNumber())
            {
                std::ostringstream ss;
                ss << dflt.GetDouble();
                config->setDefault(ss.str());
            } // arrays are ignored because machine_extruder_trains needs to be handled separately
            else 
            {
                logError("Unrecognized data type in JSON: %i\n", int(dflt.GetType()));
            }
        }
        if (data.HasMember("unit") && data["unit"].IsString())
        {
            config->setUnit(data["unit"].GetString());
        }
        
        /// Register the setting in the settings map lookup.
        if (settingExists(config->getKey()))
        {
            cura::logError("Duplicate definition of setting: %s\n", config->getKey().c_str());
        }
        
        if (add_to_settings)
        {
            settings[config->getKey()] = config;
        }

        /// When this setting has children, add those children to this setting.
        if (data.HasMember("children") && data["children"].IsObject())
        {
            _addSettingsToCategory(category, data["children"], config);
        }
    }
}
Exemplo n.º 25
0
 bool clone_value(rapidjson::Value & output, const rapidjson::Value & input, rapidjson::Value::AllocatorType & allocator)
 {
     if(&output == &input)
     {
         return false;
     }
     
     if(input.IsNull())
     {
         output.SetNull();
     }
     else if(input.IsInt64())
     {
         output.SetInt(input.GetInt64());
     }
     else if(input.IsInt())
     {
         output.SetInt(input.GetInt());
     }
     else if(input.IsDouble())
     {
         output.SetDouble(input.GetDouble());
     }
     else if(input.IsBool())
     {
         output.SetBool(input.GetBool());
     }
     else if(input.IsString())
     {
         output.SetString(input.GetString(), input.GetStringLength(), allocator);
     }
     else if(input.IsArray())
     {
         rapidjson::Value temp;
         output.SetArray();
         output.Reserve(input.Size(), allocator);
         for(rapidjson::SizeType i = 0; i < input.Size(); ++i)
         {
             clone_value(temp, input[i], allocator);
             output.PushBack(temp, allocator);
         }
     }
     else if(input.IsObject())
     {
         output.SetObject();
         
         rapidjson::Value key, val;
         for(rapidjson::Value::ConstMemberIterator it = input.MemberBegin();
             it != input.MemberEnd(); ++it)
         {
             clone_value(key, it->name, allocator);
             clone_value(val, it->value, allocator);
             
             output.AddMember(key, val, allocator);
         }
     }
     else
     {
         assert(false && "shuldn't execute to here.");
         return false;
     }
     return true;
 }