bool ApplicationConfig::load(picojson::object& obj)
{
    auto poProcessName = obj.find("processName");
    auto poDefaultEndpointId = obj.find("defaultEndpointId");

    if (poProcessName == obj.end() || poDefaultEndpointId == obj.end()) {
        return false;
    }

    if (!poProcessName->second.is<std::string>() ||
        !poDefaultEndpointId->second.is<std::string>()) {
        return false;
    }

    processName = poProcessName->second.get<std::string>();
    defaultEndpointId = poDefaultEndpointId->second.get<std::string>();
    return true;
}
T getValueFromJson( const picojson::object & o, const char * key ) {
    picojson::object::const_iterator it = o.find( key );
    if( it == o.end() ) {
        std::string err = keyNotFoundErrorMessage( key );
        LOG( ERROR ) << err;
        throw err;
    }
    return it->second.get<T>();
}
Exemple #3
0
//追加
void SqliteManager::addPicoJsonObject(const std::string &table_name, picojson::object &object)
{
    std::string cols = "";
    std::string values = "";

    picojson::object::iterator it = object.begin();
    while (it != object.end()) {
        cols.append('\''+(*it).first+'\'');
        cols.append(",");

        std::string value;
        if(object[it->first].is<double>()) {
            auto val = cocos2d::Value(object[it->first].get<double>());
            value = std::to_string(val.asInt());
        } else if(object[it->first].is<std::string>()) {
            value = object[it->first].get<std::string>();
        }

        values.append('\''+value+'\'');
        values.append(",");
        it++;
    }

    std::string create_at = "created_at";
    std::string updated_at = "updated_at";
    std::string now_time = "datetime('now', 'localtime')";

    //作成時間
    cols.append('\''+create_at+'\'');
    cols.append(",");
    values.append(now_time);
    values.append(",");

    //更新時間
    cols.append('\''+create_at+'\'');
    cols.append(",");
    values.append(now_time);
    values.append(",");

    cols.pop_back();
    values.pop_back();

    std::string sql = "INSERT INTO "+ table_name +" (" + cols + ") VALUES (" + values + ")";
    CCLOG("sql:%s", sql.c_str());

    _result = this->executeQuery(sql);
    if (_result != SQLITE_OK)
    {
        CCLOG("エラー%d:%s", _result, _error_msg);
    }

}
void DriverConfig::load(picojson::object& obj)
{
    auto poDriverClsid = obj.find("driverClsid");
    auto poEndpoints = obj.find("endpoints");
    auto poApplications = obj.find("applications");

    if (poDriverClsid != obj.end() &&
        poDriverClsid->second.is<std::string>()) {

        driverClsid = poDriverClsid->second.get<std::string>();
    }

    if (poEndpoints != obj.end() && poEndpoints->second.is<picojson::array>()) {
        for (auto& item : poEndpoints->second.get<picojson::array>()) {
            if (!item.is<picojson::object>()) {
                continue;
            }

            EndpointConfig endpoint;

            endpoint.load(item.get<picojson::object>());
            endpoints.emplace_back(endpoint);
        }
    }

    if (poApplications != obj.end() &&
        poApplications->second.is<picojson::array>()) {
        for (auto& item : poApplications->second.get<picojson::array>()) {
            if (!item.is<picojson::object>()) {
                continue;
            }

            ApplicationConfig application;

            application.load(item.get<picojson::object>());
            applications.emplace_back(application);
        }
    }
}
Exemple #5
0
//更新
void SqliteManager::savePicoJsonObject(const std::string &table_name, picojson::object &object)
{
    std::string values = "";
    std::string update_id = "";

    picojson::object::iterator it = object.begin();
    while (it != object.end()) {
        values.append('\''+(*it).first+'\'');
        values.append("=");


        std::string value;
        if(object[it->first].is<double>()) {
            auto val = cocos2d::Value(object[it->first].get<double>());
            value = std::to_string(val.asInt());
        } else if(object[it->first].is<std::string>()) {
            value = object[it->first].get<std::string>();
        }

        if ((*it).first == "id") {
            update_id = value;
        }

        values.append('\''+value+'\'');
        values.append(",");
        it++;
    }
    std::string updated_at = "updated_at";
    std::string now_time = "datetime('now', 'localtime')";

    //更新時間
    values.append('\''+updated_at+'\'');
    values.append("=");
    values.append(now_time);

    std::string sql = "UPDATE "+ table_name +" SET " + values + " WHERE id = " + update_id;
    CCLOG("sql:%s", sql.c_str());

    _result = this->executeQuery(sql);
    if (_result != SQLITE_OK)
    {
        CCLOG("エラー%d:%s", _result, _error_msg);
    }

}
bool ListingsRepository::validateJsonObject(const picojson::object& obj) const
{
  return obj.find("title") != obj.end() && obj.find("manufacturer") != obj.end() 
    && obj.find("currency") != obj.end() && obj.find("price") != obj.end();
}
  EarthViewer(const Vec2<int>& size, const float scale, const bool oblong, Touch& touch, Keyinp& keyinp, const std::string& path, const std::string& lang) :
    touch_(touch),
    keyinp_(keyinp),
    size_(size.x / scale, size.y / scale),
    params_(path + "devdata/params.json"),
    scale_(scale),
    aspect_((float)size.x / (float)size.y),
    camera_(Camera::PERSPECTIVE),
    cockpit_(Camera::ORTHOGONAL),
    localize_(lang, path),
    earth_(params_.value().get<picojson::object>()["earth"].get<picojson::object>(), path, camera_),
    rotate_mix_(),
    place_index_()
  {
    DOUT << "EarthViewer()" << std::endl;

    picojson::object& params = params_.value().get<picojson::object>();

    camera_.oblong(oblong);
    SetupCamera(camera_, params["camera"].get<picojson::object>(), aspect_);
    cockpit_.setSize(size.x / scale, size.y / scale);

    {
      picojson::array& array = params["lights"].get<picojson::array>();
      for (picojson::array::iterator it = array.begin(); it != array.end(); ++it)
      {
        Light light;
        SetupLight(light, it->get<picojson::object>());
        lights_.push_back(light);
      }
      earth_.light(lights_);
    }

    env_.touch       = &touch_;
    env_.keyinp      = &keyinp_;
    env_.path        = &path;
    env_.savePath    = &path;
    env_.size        = &size_;
    env_.scale       = scale_;
    env_.params      = &params_;
    env_.task        = &task_;
    env_.camera      = &camera_;
    env_.cockpit     = &cockpit_;
    env_.earth       = &earth_;
    env_.earthLight  = &lights_[0];
    env_.fonts       = &fonts_;
    env_.texMng      = &texMng_;
    env_.localize    = &localize_;

    env_.earth_texture = 0;
    earth_.texture(env_.earth_texture);
    earth_.setRotSpeed(0);

    {
      const std::string& file = params["game"].get<picojson::object>()["places"].get<std::string>();
      Json places = Json(path + file);
      places_ = places.value().get<picojson::object>();
      for (picojson::object::iterator it = places_.begin(); it != places_.end(); ++it)
      {
        place_names_.push_back(&it->first);
      }
    }

    task_.add<Control>(TASK_PRIO_SYS, env_);
    task_.add<Game2DSetup>(TASK_PRIO_2D_TOPPRIO, env_);
    task_.add<GameWorld>(TASK_PRIO_3D_TOPPRIO, env_);
    env_.task->add<PlaceDisp>(TASK_PRIO_2D, env_);
    // task_.add<Equator>(TASK_PRIO_3D, env_);
    task_.add<TouchEft>(TASK_PRIO_3D, env_);
  }