本文整理汇总了C++中CPLStringList::AddNameValue方法的典型用法代码示例。如果您正苦于以下问题:C++ CPLStringList::AddNameValue方法的具体用法?C++ CPLStringList::AddNameValue怎么用?C++ CPLStringList::AddNameValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPLStringList
的用法示例。
在下文中一共展示了CPLStringList::AddNameValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ensure
void object::test<9>()
{
// Test some name=value handling stuff *with* sorting active.
CPLStringList oNVL;
oNVL.Sort();
oNVL.AddNameValue( "KEY1", "VALUE1" );
oNVL.AddNameValue( "2KEY", "VALUE2" );
ensure_equals( "91", oNVL.Count(), 2 );
ensure( "92", EQUAL(oNVL.FetchNameValue("KEY1"),"VALUE1") );
ensure( "93", EQUAL(oNVL.FetchNameValue("2KEY"),"VALUE2") );
ensure( "94", oNVL.FetchNameValue("MISSING") == NULL );
oNVL.AddNameValue( "KEY1", "VALUE3" );
ensure_equals( "95", oNVL.Count(), 3 );
ensure( "96", EQUAL(oNVL.FetchNameValue("KEY1"),"VALUE1") );
ensure( "97", EQUAL(oNVL.FetchNameValueDef("MISSING","X"),"X") );
oNVL.SetNameValue( "2KEY", "VALUE4" );
ensure( "98", EQUAL(oNVL.FetchNameValue("2KEY"),"VALUE4") );
ensure_equals( "99", oNVL.Count(), 3 );
// make sure deletion works.
oNVL.SetNameValue( "2KEY", NULL );
ensure( "9a", oNVL.FetchNameValue("2KEY") == NULL );
ensure_equals( "9b", oNVL.Count(), 2 );
// Test insertion logic pretty carefully.
oNVL.Clear();
ensure( "9c", oNVL.IsSorted() == TRUE );
oNVL.SetNameValue( "B", "BB" );
oNVL.SetNameValue( "A", "AA" );
oNVL.SetNameValue( "D", "DD" );
oNVL.SetNameValue( "C", "CC" );
// items should be in sorted order.
ensure( "9c1", EQUAL(oNVL[0],"A=AA") );
ensure( "9c2", EQUAL(oNVL[1],"B=BB") );
ensure( "9c3", EQUAL(oNVL[2],"C=CC") );
ensure( "9c4", EQUAL(oNVL[3],"D=DD") );
ensure( "9d", EQUAL(oNVL.FetchNameValue("A"),"AA") );
ensure( "9e", EQUAL(oNVL.FetchNameValue("B"),"BB") );
ensure( "9f", EQUAL(oNVL.FetchNameValue("C"),"CC") );
ensure( "9g", EQUAL(oNVL.FetchNameValue("D"),"DD") );
}
示例2: 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);
}
}