当前位置: 首页>>代码示例>>C++>>正文


C++ CPLJSONObject::IsValid方法代码示例

本文整理汇总了C++中CPLJSONObject::IsValid方法的典型用法代码示例。如果您正苦于以下问题:C++ CPLJSONObject::IsValid方法的具体用法?C++ CPLJSONObject::IsValid怎么用?C++ CPLJSONObject::IsValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CPLJSONObject的用法示例。


在下文中一共展示了CPLJSONObject::IsValid方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: updateSupportInfo

bool Account::updateSupportInfo()
{
    std::string apiEndpoint(API_ENDPOINT);
    CPLJSONObject root = http::fetchJson(apiEndpoint + "/support_info/");
    if(!root.IsValid()) {
        return false;
    }

    bool supported = root.GetBool("supported");

    Settings &settings = Settings::instance();
    settings.set("account/supported", supported);

    if(supported) {
        settings.set("account/sign", root.GetString("sign"));
        settings.set("account/start_date", root.GetString("start_date"));
        settings.set("account/end_date", root.GetString("end_date"));

        // Get key file
        const char *settingsPath = CPLGetConfigOption("NGS_SETTINGS_PATH", nullptr);
        std::string keyFilePath = File::formFileName(settingsPath, KEY_FILE, "");
        return http::getFile(apiEndpoint + "/rsa_public_key/", keyFilePath);
    }

    m_supported = checkSupported();

    return true;
}
开发者ID:nextgis,项目名称:nextgis_datastore,代码行数:28,代码来源:account.cpp

示例2: Delete

/**
 * Delete json object by key.
 * @param  osName Key name.
 *
 * @since GDAL 2.3
 */
void CPLJSONObject::Delete(const std::string &osName)
{
    std::string objectName;
    CPLJSONObject object = GetObjectByPath( osName, objectName );
    if( object.IsValid() )
    {
        json_object_object_del( TO_JSONOBJ(object.GetInternalHandle()),
                                objectName.c_str() );
    }
}
开发者ID:ksshannon,项目名称:gdal,代码行数:16,代码来源:cpl_json.cpp

示例3: AddNull

/**
 * Add new key - null pair to json object.
 * @param osName  Key name.
 *
 * @since GDAL 2.3
 */
void CPLJSONObject::AddNull(const std::string &osName)
{
    std::string objectName;
    CPLJSONObject object = GetObjectByPath( osName, objectName );
    if( object.IsValid() &&
        json_object_get_type(TO_JSONOBJ(object.m_poJsonObject)) ==
            json_type_object )
    {
        json_object_object_add( TO_JSONOBJ(object.GetInternalHandle()),
                                           objectName.c_str(), nullptr );
    }
}
开发者ID:ksshannon,项目名称:gdal,代码行数:18,代码来源:cpl_json.cpp

示例4: FillCapabilities

/*
 * FillCapabilities()
 */
void OGRNGWDataset::FillCapabilities( char **papszOptions )
{
    CPLJSONDocument oRouteReq;
    if( oRouteReq.LoadUrl( NGWAPI::GetRoute(osUrl), papszOptions ) )
    {
        CPLJSONObject oRoot = oRouteReq.GetRoot();

        if( oRoot.IsValid() )
        {
            // TODO: check bHasFeaturePaging
        }
    }
}
开发者ID:,项目名称:,代码行数:16,代码来源:

示例5: Add

/**
 * Add new key - value pair to json object.
 * @param osName  Key name.
 * @param bValue   Boolean value.
 *
 * @since GDAL 2.3
 */
void CPLJSONObject::Add(const std::string &osName, bool bValue)
{
    std::string objectName;
    CPLJSONObject object = GetObjectByPath( osName, objectName );
    if( object.IsValid() &&
        json_object_get_type(TO_JSONOBJ(object.m_poJsonObject)) ==
            json_type_object )
    {
        json_object *poVal = json_object_new_boolean( bValue );
        json_object_object_add( TO_JSONOBJ(object.GetInternalHandle()),
                                           objectName.c_str(), poVal );
    }
}
开发者ID:ksshannon,项目名称:gdal,代码行数:20,代码来源:cpl_json.cpp

示例6: GetObj

/**
 * Get value by key.
 * @param  osName Key name.
 * @return         Json object.
 *
 * @since GDAL 2.3
 */
CPLJSONObject CPLJSONObject::GetObj(const std::string &osName) const
{
    std::string objectName;
    CPLJSONObject object = GetObjectByPath( osName, objectName );
    if( object.IsValid() )
    {
        json_object* poVal = nullptr;
        if(json_object_object_get_ex( TO_JSONOBJ(object.GetInternalHandle()),
                                      objectName.c_str(), &poVal ) )
        {
            return CPLJSONObject( objectName, poVal );
        }
    }
    return CPLJSONObject( "", nullptr );
}
开发者ID:ksshannon,项目名称:gdal,代码行数:22,代码来源:cpl_json.cpp

示例7: updateUserInfo

bool Account::updateUserInfo()
{
    std::string apiEndpoint(API_ENDPOINT);
    CPLJSONObject root = http::fetchJson(apiEndpoint + "/user_info/");
    if(!root.IsValid()) {
        m_authorized = false;
        return false;
    }

    Settings &settings = Settings::instance();
    settings.set("account/user_id", root.GetString("nextgis_guid"));
    m_firstName = root.GetString("first_name");
    settings.set("account/first_name", m_firstName);
    m_lastName = root.GetString("last_name");
    settings.set("account/last_name", m_lastName);
    m_email = root.GetString("email");
    settings.set("account/email", m_email);

    m_authorized = true;
    // Get avatar
    std::string emailHash = md5(root.GetString("email"));
    return http::getFile(CPLSPrintf("https://www.gravatar.com/avatar/%s?s=64&r=pg&d=robohash",
                             emailHash.c_str()), m_avatarPath);
}
开发者ID:nextgis,项目名称:nextgis_datastore,代码行数:24,代码来源:account.cpp

示例8: Init

/*
 * Init()
 */
bool OGRNGWDataset::Init(int nOpenFlagsIn)
{
    // NOTE: Skip check API version at that moment. We expected API v3.

    // Get resource details.
    CPLJSONDocument oResourceDetailsReq;
    char **papszHTTPOptions = GetHeaders();
    bool bResult = oResourceDetailsReq.LoadUrl( NGWAPI::GetResource( osUrl,
        osResourceId ), papszHTTPOptions );

    CPLDebug("NGW", "Get resource %s details %s", osResourceId.c_str(),
        bResult ? "success" : "failed");

    if( bResult )
    {
        CPLJSONObject oRoot = oResourceDetailsReq.GetRoot();

        if( oRoot.IsValid() )
        {
            std::string osResourceType = oRoot.GetString("resource/cls");
            FillMetadata( oRoot );

            if( osResourceType == "resource_group" )
            {
                // Check feature paging.
                FillCapabilities( papszHTTPOptions );
                if( oRoot.GetBool( "resource/children", false ) ) {
                    // Get child resources.
                    bResult = FillResources( papszHTTPOptions, nOpenFlagsIn );
                }
            }
            else if( (osResourceType == "vector_layer" ||
                osResourceType == "postgis_layer") )
            {
                // Cehck feature paging.
                FillCapabilities( papszHTTPOptions );
                // Add vector layer.
                AddLayer( oRoot, papszHTTPOptions, nOpenFlagsIn );
            }
            else if( osResourceType == "mapserver_style" ||
                osResourceType == "qgis_vector_style" ||
                osResourceType == "raster_style" ||
                osResourceType == "wmsclient_layer" )
            {
                // GetExtent from parent.
                OGREnvelope stExtent;
                std::string osParentId = oRoot.GetString("resource/parent/id");
                bool bExtentResult = NGWAPI::GetExtent(osUrl, osParentId,
                    papszHTTPOptions, 3857, stExtent);

                if( !bExtentResult )
                {
                    // Set full extent for EPSG:3857.
                    stExtent.MinX = -20037508.34;
                    stExtent.MaxX = 20037508.34;
                    stExtent.MinY = -20037508.34;
                    stExtent.MaxY = 20037508.34;
                }

                CPLDebug("NGW", "Raster extent is: %f, %f, %f, %f",
                    stExtent.MinX, stExtent.MinY,
                    stExtent.MaxX, stExtent.MaxY);

                int nEPSG = 3857;
                // Get parent details. We can skip this as default SRS in NGW is 3857.
                if( osResourceType == "wmsclient_layer" )
                {
                    nEPSG = oRoot.GetInteger("wmsclient_layer/srs/id", nEPSG);
                }
                else
                {
                    CPLJSONDocument oResourceReq;
                    bResult = oResourceReq.LoadUrl( NGWAPI::GetResource( osUrl,
                        osResourceId ), papszHTTPOptions );

                    if( bResult )
                    {
                        CPLJSONObject oParentRoot = oResourceReq.GetRoot();
                        if( osResourceType == "mapserver_style" ||
                            osResourceType == "qgis_vector_style" )
                        {
                            nEPSG = oParentRoot.GetInteger("vector_layer/srs/id", nEPSG);
                        }
                        else if( osResourceType == "raster_style")
                        {
                            nEPSG = oParentRoot.GetInteger("raster_layer/srs/id", nEPSG);
                        }
                    }
                }

                // Create raster dataset.
                std::string osRasterUrl = NGWAPI::GetTMS(osUrl, osResourceId);
                char* pszRasterUrl = CPLEscapeString(osRasterUrl.c_str(), -1, CPLES_XML);
                const char *pszConnStr = CPLSPrintf("<GDAL_WMS><Service name=\"TMS\">"
            "<ServerUrl>%s</ServerUrl></Service><DataWindow>"
            "<UpperLeftX>-20037508.34</UpperLeftX><UpperLeftY>20037508.34</UpperLeftY>"
            "<LowerRightX>20037508.34</LowerRightX><LowerRightY>-20037508.34</LowerRightY>"
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例9: checkRemoteConnection

bool ConnectionFactory::checkRemoteConnection(const enum ngsCatalogObjectType type,
                                              const Options &options)
{
    resetError();
    switch(type) {
    case CAT_CONTAINER_NGW:
    {
        std::string url = options.asString(KEY_URL);
        if(url.empty()) {
            return errorMessage(_("Missing required option 'url'"));
        }

        std::string login = options.asString(KEY_LOGIN);
        if(login.empty()) {
            login = "guest";
        }
        else {
            std::string oldLogin(login);
            login = CPLString(login).Trim();
            if(!compare(oldLogin, login, true)) {
                warningMessage("Login was trimmed!");
            }
        }
        std::string password = options.asString(KEY_PASSWORD);

        CPLStringList requestOptions;
        std::string headers = "Accept: */*";
        Options authOptions;
        authOptions.add(KEY_TYPE, "basic");
        authOptions.add(KEY_LOGIN, login);
        authOptions.add(KEY_PASSWORD, password);
        AuthStore::authAdd(url, authOptions);
        std::string auth = AuthStore::authHeader(url);
        AuthStore::authRemove(url);
        if(!auth.empty()) {
            headers += "\r\n";
            headers += auth;
        }
        requestOptions.AddNameValue("HEADERS", headers.c_str());

        CPLJSONDocument checkReq;
        if(!checkReq.LoadUrl(ngw::getCurrentUserUrl(url), requestOptions)) {
            return errorMessage(CPLGetLastErrorMsg());
        }

        CPLJSONObject root = checkReq.GetRoot();
        if(!root.IsValid()) {
            return errorMessage(_("Response is invalid"));
        }

        if(root.GetString("keyname") == login) {
            return true;
        }

        return errorMessage(_("User '%s' failed to connect to %s."),
                            login.c_str(), url.c_str());
    }
    default:
        return errorMessage(_("Unsupported connection type %d"), type);
    }
}
开发者ID:nextgis,项目名称:nextgis_datastore,代码行数:61,代码来源:connectionfactory.cpp


注:本文中的CPLJSONObject::IsValid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。