Exemplo n.º 1
0
	bool dto_complex::parse( const rapidjson::Value& json )
	{
		if( json.IsObject() && json.HasMember( key() ) && json[key()].IsObject() )
		{
			for( auto& child : get_children() )
			{
				child->set_client( client() );
				if( !child->parse( json[key()] ) && !optional() )
				{
					return false;
				}
			}
			
			return true;
		}
		else if( json.IsObject() )
		{
			for( auto& child : get_children() )
			{
				child->set_client( client() );
				if( !child->parse( json ) && !optional()  )
				{
					return false;
				}
			}
			
			return true;
		}

		set_present( false );
		return optional();
	}
Exemplo n.º 2
0
void Client::parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error)
{
    if (error.IsObject()) {
        const char *message = error["message"].GetString();

        auto it = m_results.find(id);
        if (it != m_results.end()) {
            it->second.done();
            m_listener->onResultAccepted(this, it->second, message);
            m_results.erase(it);
        }
        else if (!m_quiet) {
            LOG_ERR("[%s:%u] error: \"%s\", code: %d", m_url.host(), m_url.port(), message, error["code"].GetInt());
        }

        if (id == 1 || isCriticalError(message)) {
            close();
        }

        return;
    }

    if (!result.IsObject()) {
        return;
    }

    if (id == 1) {
        int code = -1;
        if (!parseLogin(result, &code)) {
            if (!m_quiet) {
                LOG_ERR("[%s:%u] login error code: %d", m_url.host(), m_url.port(), code);
            }

            close();
            return;
        }

        m_failures = 0;
        m_listener->onLoginSuccess(this);
        m_listener->onJobReceived(this, m_job);
        return;
    }

    auto it = m_results.find(id);
    if (it != m_results.end()) {
        it->second.done();
        m_listener->onResultAccepted(this, it->second, nullptr);
        m_results.erase(it);
    }
}
Exemplo n.º 3
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.º 4
0
tws::geoarray::spatial_extent_t
tws::geoarray::read_spatial_extent(const rapidjson::Value& jspatial_extent)
{
  if(!jspatial_extent.IsObject() || jspatial_extent.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing spatial extent in metadata.");

  spatial_extent_t sp_extent;

  const rapidjson::Value& jextent = jspatial_extent["extent"];

  sp_extent.extent = read_extent(jextent);

  const rapidjson::Value& jres = jspatial_extent["resolution"];

  sp_extent.resolution = read_spatial_resolution(jres);

  //const rapidjson::Value& jcrs = jspatial_extent["crs"];

  //if(!jcrs.IsString() || jcrs.IsNull())
    //throw tws::parse_error() << tws::error_description("error in CRS in metadata.");

  //std::string crs = jcrs.GetString();

  //std::pair<std::string,unsigned int> crs_id = te::srs::SpatialReferenceSystemManager::getInstance().getIdFromP4Txt(crs);

  const rapidjson::Value& jsrid = jspatial_extent["srid"];

  if(!jsrid.IsInt() || jsrid.IsNull())
    throw tws::parse_error() << tws::error_description("error reading geoarray srid.");

  sp_extent.crs_code = jsrid.GetUint();

  return sp_extent;
}
Exemplo n.º 5
0
Post processRawPost(const rapidjson::Value& raw_post) {
  const char* ITEM_ID = "id";
  const char* ITEM_USER_ID = "userId";
  const char* ITEM_TITLE = "title";
  const char* ITEM_BODY = "body";

  Post post;

  if (raw_post.IsObject()) {  // could also be an Array
    assert("No item: id" && raw_post.HasMember(ITEM_ID));
    assert("Not an integer: id" && raw_post[ITEM_ID].IsInt());
    post.id = raw_post[ITEM_ID].GetInt();

    assert("No item: user_id" && raw_post.HasMember(ITEM_USER_ID));
    assert("Not an integer: user_id" && raw_post[ITEM_USER_ID].IsInt());
    post.user_id = raw_post[ITEM_USER_ID].GetInt();

    assert("No item: title" && raw_post.HasMember(ITEM_TITLE));
    assert("Not a string: title" && raw_post[ITEM_TITLE].IsString());
    post.title = std::string(raw_post[ITEM_TITLE].GetString());

    assert("No item: body" && raw_post.HasMember(ITEM_BODY));
    assert("Not a string: body" && raw_post[ITEM_BODY].IsString());
    post.body = std::string(raw_post[ITEM_BODY].GetString());
  } else {
    ERR("Invalid json object");
  }

  return post;
}
Exemplo n.º 6
0
std::shared_ptr<VolumeIntegrator> VolumeIntegrator::Load(const rapidjson::Value& value) {
    std::shared_ptr<VolumeIntegrator> integrator;
    
    std::string type;
    
    if (value.IsString()) {
        type = value.GetString();
    } else if (value.IsObject() && value.HasMember("type")) {
        type = value["type"].GetString();
    } else {
        std::cerr << "VolumeIntegrator error: no type given" << std::endl;
        return integrator;
    }
    
    std::transform(type.begin(), type.end(), type.begin(), ::tolower);
    
    if (type == "singlescattering") {
        integrator = SingleScatteringIntegrator::Load(value);
    } else {
        std::cerr << "VolumeIntegrator error: unknown type \"" << type << "\"" << std::endl;
        return integrator;
    }
    
    return integrator;
}
Exemplo n.º 7
0
bool
Element::loadFromJsonValue(rapidjson::Value& json_value)
{
  if (!json_value.IsObject()) {
    return false;
  }
  // parse the data and set the Elements
  if (json_value.HasMember("id")) {
    const rapidjson::Value& idVal = json_value["id"];
    id_.fromStr(idVal.GetString());
  }

  tag_ids_.clear();
  if (json_value.HasMember("tag_ids")) {
    const rapidjson::Value& tag_ids = json_value["tag_ids"];
    if (!tag_ids.IsArray()) {
      LOG_ERROR("tag_ids field is not an array, wrong format?");
      return false;
    }
    for (unsigned int i = 0; i < tag_ids.Size(); ++i) {
      if (!tag_ids[i].IsString()) {
        LOG_ERROR("Wrong format, expected string but it is not");
        return false;
      }
      tag_ids_.insert(core::UID(tag_ids[i].GetString()));
    }
  }

  return true;
}
Exemplo n.º 8
0
void counter::configure(const rapidjson::Value& config) {
	if (!config.IsObject()) {
		return;
	}

	this->values.configure(config);
}
Exemplo n.º 9
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.º 10
0
void configure(counter& obj, const rapidjson::Value& config) {
	if (!config.IsObject()) {
		return;
	}

	configure(obj.values, config);
}
Exemplo n.º 11
0
    //-----------------------------------------------------------------------------------
    void HlmsJsonCompute::loadBasedOnTextureOrUav( const rapidjson::Value &objValue,
                                                   const String &jobName, HlmsComputeJob *job,
                                                   int _threadGroupsBasedOn )
    {
        HlmsComputeJob::ThreadGroupsBasedOn threadGroupsBasedOn =
                static_cast<HlmsComputeJob::ThreadGroupsBasedOn>( _threadGroupsBasedOn );

        if( objValue.IsUint() )
        {
            job->setNumThreadGroupsBasedOn( threadGroupsBasedOn,
                                            static_cast<uint8>( objValue.GetUint() ),
                                            1u, 1u, 1u );
        }
        else if( objValue.IsObject() )
        {
            uint8 slot = 0;
            uint8 divisors[3] = { 1u, 1u, 1u };

            bool hasError = false;

            const rapidjson::Value &subobj = objValue;
            rapidjson::Value::ConstMemberIterator itor = subobj.FindMember( "slot" );

            if( itor != subobj.MemberEnd() && itor->value.IsUint() )
                slot = static_cast<uint8>( itor->value.GetUint() );
            else
                hasError = true;

            itor = subobj.FindMember( "divisor" );

            if( itor != subobj.MemberEnd() && itor->value.IsArray() )
            {
                const rapidjson::Value &divArray = itor->value;
                const rapidjson::SizeType arraySize = std::min( 3u, divArray.Size() );
                for( rapidjson::SizeType i=0; i<arraySize; ++i )
                {
                    if( divArray[i].IsUint() )
                    {
                        divisors[i] = divArray[i].GetUint();
                    }
                    else
                    {
                        hasError = true;
                        LogManager::getSingleton().logMessage(
                                    "Array with 3 integers expected in " + jobName + ". "
                                    "Syntax is thread_groups_based_on_texture : { \"slot\" "
                                    ": 0, \"divisor\" : [1, 1, 1] } or the short form: "
                                    "thread_groups_based_on_texture : 0 (with no divisors)" );
                    }
                }
            }

            if( !hasError )
            {
                job->setNumThreadGroupsBasedOn( threadGroupsBasedOn,
                                                slot, divisors[0], divisors[1], divisors[2] );
            }
        }
    }
Exemplo n.º 12
0
bool Globals::gameFromJson(SGame &game, const rapidjson::Value &jsonData)
{
    game = {0};

    // Parse json and validate
    if (!jsonData.IsObject())
    {
        return false;
    }
    const auto &jsonGame = jsonData["game"];
    const auto &jsonUsers = jsonData["users"];
    if (!jsonGame.IsObject())
    {
        return false;
    }
    if (!jsonUsers.IsArray())
    {
        return false;
    }

    // Parse game
    const auto &jsonGameId = jsonGame["id"];
    if (!jsonGameId.IsInt64())
    {
        return false;
    }
    game.id = jsonGameId.GetInt64();

    const auto &jsonGameSeed = jsonGame["seed"];
    if (!jsonGameSeed.IsUint())
    {
        return false;
    }
    game.seed = jsonGameSeed.GetUint();

    const auto &jsonGameStatus = jsonGame["status"];
    if (!jsonGameStatus.IsString())
    {
        return false;
    }
    game.status = jsonGameStatus.GetString();

    // Parse users
    for (decltype(jsonUsers.Size()) i = 0; i < jsonUsers.Size(); ++i)
    {
        const auto &jsonUser = jsonUsers[i];
        SUser user;
        if (!userFromJson(user, jsonUser))
        {
            return false;
        }
        game.users.push_back(user);
    }

    return true;
}
Exemplo n.º 13
0
bool Client::parseJob(const rapidjson::Value &params, int *code)
{
    if (!params.IsObject()) {
        *code = 2;
        return false;
    }

#   ifdef XMRIG_PROXY_PROJECT
    Job job(m_id, m_url.variant());
    job.setClientId(m_rpcId);
    job.setCoin(m_url.coin());
#   else
    Job job(m_id, m_nicehash, m_url.algo(), m_url.variant());
#   endif

    if (!job.setId(params["job_id"].GetString())) {
        *code = 3;
        return false;
    }

    if (!job.setBlob(params["blob"].GetString())) {
        *code = 4;
        return false;
    }

    if (!job.setTarget(params["target"].GetString())) {
        *code = 5;
        return false;
    }

    if (params.HasMember("coin")) {
        job.setCoin(params["coin"].GetString());
    }

    if (params.HasMember("variant")) {
        job.setVariant(params["variant"].GetInt());
    }

    if (m_job != job) {
        m_jobs++;
        m_job = std::move(job);
        return true;
    }

    if (m_jobs == 0) { // https://github.com/xmrig/xmrig/issues/459
        return false;
    }

    if (!m_quiet) {
        LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port());
    }

    close();
    return false;
}
Exemplo n.º 14
0
void JsonToObject<>(const rapidjson::Value& json, VideoAttachment* video) {
  if (!json.IsObject()) {
    THROW_AT(json::NotAnObjectException);
  }
  bool res = vk_api::FirstFieldToObject(
      json, {"photo_640", "photo_320", "photo_130"}, &video->preview_url);
  if (!res) {
    THROW_AT(json::NoFieldException, "photo_*");
  }
  JsonMembers(json)("title", &video->title)("description", &video->description);
}
Exemplo n.º 15
0
void metrics_dump::configure(const rapidjson::Value& config) {
	if (!config.IsObject()) {
		return;
	}

	if (config.HasMember("interval")) {
		const rapidjson::Value& interval = config["interval"];
		if (interval.IsUint64()) {
			this->interval = chrono::duration(interval.GetUint64(), chrono::time_unit::MSEC);
		}
	}
}
Exemplo n.º 16
0
Status deserializeRow(const rj::Value& doc, Row& r) {
  if (!doc.IsObject()) {
    return Status(1);
  }

  for (const auto& i : doc.GetObject()) {
    std::string name(i.name.GetString());
    if (!name.empty() && i.value.IsString()) {
      r[name] = i.value.GetString();
    }
  }
  return Status();
}
Exemplo n.º 17
0
std::string get_value_as_string(const rapidjson::Value& object, const char* key) {
    assert(object.IsObject());

    const auto it = object.FindMember(key);
    if (it == object.MemberEnd()) {
        return "";
    }

    if (it->value.IsString()) {
        return it->value.GetString();
    }

    throw config_error{std::string{"Value for name '"} + key + "' must be a string."};
}
Exemplo n.º 18
0
void Scenario::LoadDataFromJSON( const rapidjson::Value& object )
{
	assertion( object.IsObject(), "Could not load data from JSON because the JSON value specified is not an object!" );

	// Load Scenario fields.
	SetName( GetJSONStringValue( object, "name", "" ) );
	SetDefaultTerrainTypeName( GetJSONStringValue( object, "defaultTerrainType", "" ) );

	// Load all game data.
	TerrainTypes.LoadRecordsFromJSON( object );
	UnitTypes.LoadRecordsFromJSON( object );
	MovementTypes.LoadRecordsFromJSON( object );

	//DebugPrintData();
}
Exemplo n.º 19
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.º 20
0
void JointSensor::loadJSONObject(const rapidjson::Value & sensorJSON)
{
	if (sensorJSON.IsObject())
	{
		if (sensorJSON["type"].IsNumber())
			type = (Type)sensorJSON["type"].GetInt();
		if (sensorJSON["signal"].IsNumber())
			portSignal = (Signal)sensorJSON["signal"].GetInt();
		if (sensorJSON["portA"].IsNumber())
			portA = sensorJSON["portA"].GetInt();
		if (sensorJSON["portB"].IsNumber())
			portB = sensorJSON["portB"].GetInt();
		if (sensorJSON["conversionFactor"].IsNumber())
			conversionFactor = sensorJSON["conversionFactor"].GetDouble();
	}
}
Exemplo n.º 21
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.º 22
0
tws::geoarray::attribute_t
tws::geoarray::read_array_attribute(const rapidjson::Value& jattribute)
{
  if(!jattribute.IsObject() || jattribute.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing array attribute in metadata.");

  attribute_t attr;

  const rapidjson::Value& jname = jattribute["name"];

  if(!jname.IsString() || jname.IsNull())
    throw tws::parse_error() << tws::error_description("error in attribute name entry in metadata.");

  attr.name = jname.GetString();

  const rapidjson::Value& jdescription = jattribute["description"];

  if(jdescription.IsString() || !jdescription.IsNull())
    attr.description = jdescription.GetString();

  const rapidjson::Value& jdatatype = jattribute["datatype"];

  if(!jdatatype.IsString() || jdatatype.IsNull())
    throw tws::parse_error() << tws::error_description("error in attribute datatype entry in metadata.");

  attr.datatype = datatype_t::from_string(jdatatype.GetString());

  const rapidjson::Value& jvalid_range = jattribute["valid_range"];

  attr.valid_range = read_numeric_range(jvalid_range);

  const rapidjson::Value& jscale_factor = jattribute["scale_factor"];

  if(!jscale_factor.IsNumber() || jscale_factor.IsNull())
    throw tws::parse_error() << tws::error_description("error in attribute scale_factor entry in metadata.");

  attr.scale_factor = jscale_factor.GetDouble();

  const rapidjson::Value& jmissing_value = jattribute["missing_value"];

  if(!jmissing_value.IsNumber() || jmissing_value.IsNull())
    throw tws::parse_error() << tws::error_description("error in attribute missing_value entry in metadata.");

  attr.missing_value = jmissing_value.GetDouble();

  return attr;
}
Exemplo n.º 23
0
void
tws::geoarray::write(const dimension_t& dim,
                     rapidjson::Value& jdim,
                     rapidjson::Document::AllocatorType& allocator)
{
  if(!jdim.IsObject())
    throw tws::conversion_error() << tws::error_description("dimension metadata must be a JSON object!");

  rapidjson::Value jdim_name(dim.name.c_str(), dim.name.length(), allocator);
  jdim.AddMember("name", jdim_name, allocator);

  rapidjson::Value jdim_dsc(dim.description.c_str(), dim.description.length(), allocator);
  jdim.AddMember("description", jdim_dsc, allocator);

  jdim.AddMember("min_idx", dim.min_idx, allocator);
  jdim.AddMember("max_idx", dim.max_idx, allocator);
}
Exemplo n.º 24
0
tws::geoarray::geo_extent_t
tws::geoarray::read_geo_extent(const rapidjson::Value& jgeo_extent)
{
  if(!jgeo_extent.IsObject() || jgeo_extent.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing geographical extent in metadata.");

  geo_extent_t geo_extent;

  const rapidjson::Value& jspatial = jgeo_extent["spatial"];

  geo_extent.spatial = read_spatial_extent(jspatial);

  const rapidjson::Value& jtemporal = jgeo_extent["temporal"];

  geo_extent.temporal = read_temporal_extent(jtemporal);

  return geo_extent;
}
Exemplo n.º 25
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.º 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");
        }
    }
}
Exemplo n.º 27
0
tws::geoarray::dimension_t
tws::geoarray::read_dimension(const rapidjson::Value& jdim)
{
  if(!jdim.IsObject() || jdim.IsNull())
    throw tws::parse_error() << tws::error_description("error parsing array dimension in metadata.");

  dimension_t dim;

  const rapidjson::Value& jname = jdim["name"];

  if(!jname.IsString() || jname.IsNull())
    throw tws::parse_error() << tws::error_description("error in dimension name entry in metadata.");

  dim.name = jname.GetString();

  const rapidjson::Value& jdescription = jdim["description"];

  if(jdescription.IsString() || !jdescription.IsNull())
    dim.description = jdescription.GetString();

  const rapidjson::Value& jdim_min = jdim["min_idx"];

  if(!jdim_min.IsNumber() || jdim_min.IsNull())
    throw tws::parse_error() << tws::error_description("error in dimension min_idx entry in metadata.");

  dim.min_idx = jdim_min.GetInt64();

  const rapidjson::Value& jdim_max = jdim["max_idx"];

  if(!jdim_max.IsNumber() || jdim_max.IsNull())
    throw tws::parse_error() << tws::error_description("error in dimension max_idx entry in metadata.");

  dim.max_idx = jdim_max.GetInt64();

  const rapidjson::Value& jdim_pos = jdim["pos"];

  if(!jdim_pos.IsNumber() || jdim_pos.IsNull())
    throw tws::parse_error() << tws::error_description("error in dimension position entry in metadata.");

  dim.pos = jdim_pos.GetUint();

  return dim;
}
Exemplo n.º 28
0
tws::geoarray::geoarray_t
tws::geoarray::read_array_metadata(const rapidjson::Value& jmetadata)
{
  if(!jmetadata.IsObject())
    throw tws::parse_error() << tws::error_description("error parsing array metadata.");

  geoarray_t ameta;

  const rapidjson::Value& jarray_name = jmetadata["name"];

  if(!jarray_name.IsString() || jarray_name.IsNull())
    throw tws::parse_error() << tws::error_description("error in array entry name in metadata.");

  ameta.name = jarray_name.GetString();

  if(ameta.name.empty())
    throw tws::parse_error() << tws::error_description("array name can not be empty in metadata.");

  const rapidjson::Value& jarray_dsc = jmetadata["description"];

  if(jarray_dsc.IsString() && !jarray_dsc.IsNull())
    ameta.description = jarray_dsc.GetString();
  
  const rapidjson::Value& jarray_detail = jmetadata["detail"];
  
  if(jarray_detail.IsString() && !jarray_detail.IsNull())
    ameta.detail = jarray_detail.GetString();

  const rapidjson::Value& jarray_dimensions = jmetadata["dimensions"];

  ameta.dimensions = read_dimensions(jarray_dimensions);

  const rapidjson::Value& jarray_attributes = jmetadata["attributes"];

  ameta.attributes = read_array_attributes(jarray_attributes);

  const rapidjson::Value& jarray_geo_extent = jmetadata["geo_extent"];

  ameta.geo_extent = read_geo_extent(jarray_geo_extent);

  return ameta;
}
Exemplo n.º 29
0
int JsonValidator::getType(rapidjson::Value& jsonValue) {
	if (jsonValue.IsNull()) {
		return kJsonTypeNull;
	} else if (jsonValue.IsBool()) {
		return kJsonTypeBoolean;
	} else if (jsonValue.IsObject()) {
		return kJsonTypeObject;
	} else if (jsonValue.IsArray()) {
		return kJsonTypeArray;
	} else if (jsonValue.IsString()) {
		return kJsonTypeString;
	} else if (jsonValue.IsInt() || jsonValue.IsInt64() ||
	           jsonValue.IsUint() || jsonValue.IsUint64()) {
		return kJsonTypeInteger;
	} else if (jsonValue.IsDouble()) {
		return kJsonTypeDouble;
	} else {
		return kJsonTypeUnknown;
	}
}
Exemplo n.º 30
0
Status deserializeDiffResults(const rj::Value& doc, DiffResults& dr) {
  if (!doc.IsObject()) {
    return Status(1);
  }

  if (doc.HasMember("removed")) {
    auto status = deserializeQueryData(doc["removed"], dr.removed);
    if (!status.ok()) {
      return status;
    }
  }

  if (doc.HasMember("added")) {
    auto status = deserializeQueryData(doc["added"], dr.added);
    if (!status.ok()) {
      return status;
    }
  }
  return Status();
}