本文整理汇总了C++中CPLStringList::FetchBoolean方法的典型用法代码示例。如果您正苦于以下问题:C++ CPLStringList::FetchBoolean方法的具体用法?C++ CPLStringList::FetchBoolean怎么用?C++ CPLStringList::FetchBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPLStringList
的用法示例。
在下文中一共展示了CPLStringList::FetchBoolean方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ensure
void object::test<8>()
{
// Test some name=value handling stuff.
CPLStringList oNVL;
oNVL.AddNameValue( "KEY1", "VALUE1" );
oNVL.AddNameValue( "2KEY", "VALUE2" );
ensure_equals( oNVL.Count(), 2 );
ensure( EQUAL(oNVL.FetchNameValue("2KEY"),"VALUE2") );
ensure( oNVL.FetchNameValue("MISSING") == NULL );
oNVL.AddNameValue( "KEY1", "VALUE3" );
ensure( EQUAL(oNVL.FetchNameValue("KEY1"),"VALUE1") );
ensure( EQUAL(oNVL[2],"KEY1=VALUE3") );
ensure( EQUAL(oNVL.FetchNameValueDef("MISSING","X"),"X") );
oNVL.SetNameValue( "2KEY", "VALUE4" );
ensure( EQUAL(oNVL.FetchNameValue("2KEY"),"VALUE4") );
ensure_equals( oNVL.Count(), 3 );
// make sure deletion works.
oNVL.SetNameValue( "2KEY", NULL );
ensure( oNVL.FetchNameValue("2KEY") == NULL );
ensure_equals( oNVL.Count(), 2 );
// Test boolean support.
ensure_equals( "b1", oNVL.FetchBoolean( "BOOL", TRUE ), TRUE );
ensure_equals( "b2", oNVL.FetchBoolean( "BOOL", FALSE ), FALSE );
oNVL.SetNameValue( "BOOL", "YES" );
ensure_equals( "b3", oNVL.FetchBoolean( "BOOL", TRUE ), TRUE );
ensure_equals( "b4", oNVL.FetchBoolean( "BOOL", FALSE ), TRUE );
oNVL.SetNameValue( "BOOL", "1" );
ensure_equals( "b5", oNVL.FetchBoolean( "BOOL", FALSE ), TRUE );
oNVL.SetNameValue( "BOOL", "0" );
ensure_equals( "b6", oNVL.FetchBoolean( "BOOL", TRUE ), FALSE );
oNVL.SetNameValue( "BOOL", "FALSE" );
ensure_equals( "b7", oNVL.FetchBoolean( "BOOL", TRUE ), FALSE );
oNVL.SetNameValue( "BOOL", "ON" );
ensure_equals( "b8", oNVL.FetchBoolean( "BOOL", FALSE ), TRUE );
// Test assignmenet operator.
CPLStringList oCopy;
{
CPLStringList oTemp;
oTemp.AddString("test");
oCopy = oTemp;
}
ensure( "c1", EQUAL(oCopy[0],"test") );
oCopy = oCopy;
ensure( "c2", EQUAL(oCopy[0],"test") );
// Test copy constructor.
CPLStringList oCopy2(oCopy);
oCopy.Clear();
ensure( "c3", EQUAL(oCopy2[0],"test") );
// Test sorting
CPLStringList oTestSort;
oTestSort.AddNameValue("Z", "1");
oTestSort.AddNameValue("L", "2");
oTestSort.AddNameValue("T", "3");
oTestSort.AddNameValue("A", "4");
oTestSort.Sort();
ensure( "c4", EQUAL(oTestSort[0],"A=4") );
ensure( "c5", EQUAL(oTestSort[1],"L=2") );
ensure( "c6", EQUAL(oTestSort[2],"T=3") );
ensure( "c7", EQUAL(oTestSort[3],"Z=1") );
ensure_equals( "c8", oTestSort[4], (const char*)NULL );
// Test FetchNameValue() in a sorted list
ensure( "c9", EQUAL(oTestSort.FetchNameValue("A"),"4") );
ensure( "c10", EQUAL(oTestSort.FetchNameValue("L"),"2") );
ensure( "c11", EQUAL(oTestSort.FetchNameValue("T"),"3") );
ensure( "c12", EQUAL(oTestSort.FetchNameValue("Z"),"1") );
// Test AddNameValue() in a sorted list
oTestSort.AddNameValue("B", "5");
ensure( "c13", EQUAL(oTestSort[0],"A=4") );
ensure( "c14", EQUAL(oTestSort[1],"B=5") );
ensure( "c15", EQUAL(oTestSort[2],"L=2") );
ensure( "c16", EQUAL(oTestSort[3],"T=3") );
ensure( "c17", EQUAL(oTestSort[4],"Z=1") );
ensure_equals( "c18", oTestSort[5], (const char*)NULL );
// Test SetNameValue() of an existing item in a sorted list
oTestSort.SetNameValue("Z", "6");
ensure( "c19", EQUAL(oTestSort[4],"Z=6") );
// Test SetNameValue() of a non-existing item in a sorted list
oTestSort.SetNameValue("W", "7");
ensure( "c20", EQUAL(oTestSort[0],"A=4") );
ensure( "c21", EQUAL(oTestSort[1],"B=5") );
ensure( "c22", EQUAL(oTestSort[2],"L=2") );
//.........这里部分代码省略.........