本文整理汇总了C++中CPLStringList::AddString方法的典型用法代码示例。如果您正苦于以下问题:C++ CPLStringList::AddString方法的具体用法?C++ CPLStringList::AddString怎么用?C++ CPLStringList::AddString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPLStringList
的用法示例。
在下文中一共展示了CPLStringList::AddString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: oCopy
void object::test<7>()
{
CPLStringList oCSL;
ensure( "7nil", oCSL.List() == NULL );
oCSL.AddString( "def" );
oCSL.AddString( "abc" );
ensure_equals( "7", oCSL.Count(), 2 );
ensure( "70", EQUAL(oCSL[0], "def") );
ensure( "71", EQUAL(oCSL[1], "abc") );
ensure( "72", oCSL[17] == NULL );
ensure( "73", oCSL[-1] == NULL );
ensure_equals( "74", oCSL.FindString("abc"), 1 );
CSLDestroy( oCSL.StealList() );
ensure_equals( "75", oCSL.Count(), 0 );
ensure( "76", oCSL.List() == NULL );
// Test that the list will make an internal copy when needed to
// modify a read-only list.
oCSL.AddString( "def" );
oCSL.AddString( "abc" );
CPLStringList oCopy( oCSL.List(), FALSE );
ensure_equals( "77", oCSL.List(), oCopy.List() );
ensure_equals( "78", oCSL.Count(), oCopy.Count() );
oCopy.AddString( "xyz" );
ensure( "79", oCSL.List() != oCopy.List() );
ensure_equals( "7a", oCopy.Count(), 3 );
ensure_equals( "7b", oCSL.Count(), 2 );
ensure( "7c", EQUAL(oCopy[2], "xyz") );
}
示例2: CPLStrdup
char *GOA2GetAccessToken( const char *pszRefreshToken,
CPL_UNUSED const char *pszScope )
{
/* -------------------------------------------------------------------- */
/* Prepare request. */
/* -------------------------------------------------------------------- */
CPLString osItem;
CPLStringList oOptions;
oOptions.AddString(
"HEADERS=Content-Type: application/x-www-form-urlencoded" );
osItem.Printf(
"POSTFIELDS="
"refresh_token=%s"
"&client_id=%s"
"&client_secret=%s"
"&grant_type=refresh_token",
pszRefreshToken,
CPLGetConfigOption("GOA2_CLIENT_ID", GDAL_CLIENT_ID),
CPLGetConfigOption("GOA2_CLIENT_SECRET", GDAL_CLIENT_SECRET));
oOptions.AddString(osItem);
/* -------------------------------------------------------------------- */
/* Submit request by HTTP. */
/* -------------------------------------------------------------------- */
CPLHTTPResult *psResult = CPLHTTPFetch(GOOGLE_AUTH_URL "/token", oOptions);
if (psResult == NULL)
return NULL;
if (psResult->pabyData == NULL ||
psResult->pszErrBuf != NULL)
{
if( psResult->pszErrBuf != NULL )
CPLDebug( "GFT", "%s", psResult->pszErrBuf );
if( psResult->pabyData != NULL )
CPLDebug( "GFT", "%s", psResult->pabyData );
CPLError( CE_Failure, CPLE_AppDefined,
"Fetching OAuth2 access code from auth code failed.");
CPLHTTPDestroyResult(psResult);
return NULL;
}
CPLDebug( "GOA2", "Refresh Token Response:\n%s",
(const char *) psResult->pabyData );
/* -------------------------------------------------------------------- */
/* This response is in JSON and will look something like: */
/* -------------------------------------------------------------------- */
/*
{
"access_token":"1/fFBGRNJru1FQd44AzqT3Zg",
"expires_in":3920,
"token_type":"Bearer"
}
*/
CPLStringList oResponse = ParseSimpleJson(
(const char *) psResult->pabyData );
CPLHTTPDestroyResult(psResult);
CPLString osAccessToken = oResponse.FetchNameValueDef( "access_token", "" );
CPLDebug("GOA2", "Access Token : '%s'", osAccessToken.c_str());
if (osAccessToken.size() == 0)
{
CPLError( CE_Failure, CPLE_AppDefined,
"Unable to identify an access token in the OAuth2 response.");
return NULL;
}
else
return CPLStrdup(osAccessToken);
}
示例3: XMLInit
CPLErr VRTRasterBand::XMLInit( CPLXMLNode * psTree,
const char *pszVRTPath )
{
/* -------------------------------------------------------------------- */
/* Validate a bit. */
/* -------------------------------------------------------------------- */
if( psTree == NULL || psTree->eType != CXT_Element
|| !EQUAL(psTree->pszValue,"VRTRasterBand") )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Invalid node passed to VRTRasterBand::XMLInit()." );
return CE_Failure;
}
/* -------------------------------------------------------------------- */
/* Set the band if provided as an attribute. */
/* -------------------------------------------------------------------- */
const char* pszBand = CPLGetXMLValue( psTree, "band", NULL);
if( pszBand != NULL )
{
nBand = atoi(pszBand);
}
/* -------------------------------------------------------------------- */
/* Set the band if provided as an attribute. */
/* -------------------------------------------------------------------- */
const char *pszDataType = CPLGetXMLValue( psTree, "dataType", NULL);
if( pszDataType != NULL )
{
eDataType = GDALGetDataTypeByName(pszDataType);
}
/* -------------------------------------------------------------------- */
/* Apply any band level metadata. */
/* -------------------------------------------------------------------- */
oMDMD.XMLInit( psTree, TRUE );
/* -------------------------------------------------------------------- */
/* Collect various other items of metadata. */
/* -------------------------------------------------------------------- */
SetDescription( CPLGetXMLValue( psTree, "Description", "" ) );
if( CPLGetXMLValue( psTree, "NoDataValue", NULL ) != NULL )
SetNoDataValue( CPLAtofM(CPLGetXMLValue( psTree, "NoDataValue", "0" )) );
if( CPLGetXMLValue( psTree, "HideNoDataValue", NULL ) != NULL )
bHideNoDataValue = CSLTestBoolean( CPLGetXMLValue( psTree, "HideNoDataValue", "0" ) );
SetUnitType( CPLGetXMLValue( psTree, "UnitType", NULL ) );
SetOffset( atof(CPLGetXMLValue( psTree, "Offset", "0.0" )) );
SetScale( atof(CPLGetXMLValue( psTree, "Scale", "1.0" )) );
if( CPLGetXMLValue( psTree, "ColorInterp", NULL ) != NULL )
{
const char *pszInterp = CPLGetXMLValue( psTree, "ColorInterp", NULL );
SetColorInterpretation(GDALGetColorInterpretationByName(pszInterp));
}
/* -------------------------------------------------------------------- */
/* Category names. */
/* -------------------------------------------------------------------- */
if( CPLGetXMLNode( psTree, "CategoryNames" ) != NULL )
{
CPLXMLNode *psEntry;
CSLDestroy( papszCategoryNames );
papszCategoryNames = NULL;
CPLStringList oCategoryNames;
for( psEntry = CPLGetXMLNode( psTree, "CategoryNames" )->psChild;
psEntry != NULL; psEntry = psEntry->psNext )
{
if( psEntry->eType != CXT_Element
|| !EQUAL(psEntry->pszValue,"Category")
|| (psEntry->psChild != NULL && psEntry->psChild->eType != CXT_Text) )
continue;
oCategoryNames.AddString(
(psEntry->psChild) ? psEntry->psChild->pszValue : "");
}
papszCategoryNames = oCategoryNames.StealList();
}
/* -------------------------------------------------------------------- */
/* Collect a color table. */
/* -------------------------------------------------------------------- */
if( CPLGetXMLNode( psTree, "ColorTable" ) != NULL )
{
CPLXMLNode *psEntry;
GDALColorTable oTable;
int iEntry = 0;
for( psEntry = CPLGetXMLNode( psTree, "ColorTable" )->psChild;
psEntry != NULL; psEntry = psEntry->psNext )
{
GDALColorEntry sCEntry;
//.........这里部分代码省略.........
示例4: XMLInit
CPLErr GDALPamRasterBand::XMLInit( CPLXMLNode *psTree, const char *pszUnused )
{
PamInitialize();
/* -------------------------------------------------------------------- */
/* Apply any dataset level metadata. */
/* -------------------------------------------------------------------- */
oMDMD.XMLInit( psTree, TRUE );
/* -------------------------------------------------------------------- */
/* Collect various other items of metadata. */
/* -------------------------------------------------------------------- */
GDALMajorObject::SetDescription( CPLGetXMLValue( psTree, "Description", "" ) );
if( CPLGetXMLValue( psTree, "NoDataValue", NULL ) != NULL )
{
const char *pszLEHex =
CPLGetXMLValue( psTree, "NoDataValue.le_hex_equiv", NULL );
if( pszLEHex != NULL )
{
int nBytes;
GByte *pabyBin = CPLHexToBinary( pszLEHex, &nBytes );
if( nBytes == 8 )
{
CPL_LSBPTR64( pabyBin );
GDALPamRasterBand::SetNoDataValue( *((double *) pabyBin) );
}
else
{
GDALPamRasterBand::SetNoDataValue(
atof(CPLGetXMLValue( psTree, "NoDataValue", "0" )) );
}
CPLFree( pabyBin );
}
else
{
GDALPamRasterBand::SetNoDataValue(
atof(CPLGetXMLValue( psTree, "NoDataValue", "0" )) );
}
}
GDALPamRasterBand::SetOffset(
atof(CPLGetXMLValue( psTree, "Offset", "0.0" )) );
GDALPamRasterBand::SetScale(
atof(CPLGetXMLValue( psTree, "Scale", "1.0" )) );
GDALPamRasterBand::SetUnitType( CPLGetXMLValue( psTree, "UnitType", NULL));
if( CPLGetXMLValue( psTree, "ColorInterp", NULL ) != NULL )
{
const char *pszInterp = CPLGetXMLValue( psTree, "ColorInterp", NULL );
GDALPamRasterBand::SetColorInterpretation(
GDALGetColorInterpretationByName(pszInterp));
}
/* -------------------------------------------------------------------- */
/* Category names. */
/* -------------------------------------------------------------------- */
if( CPLGetXMLNode( psTree, "CategoryNames" ) != NULL )
{
CPLXMLNode *psEntry;
CPLStringList oCategoryNames;
for( psEntry = CPLGetXMLNode( psTree, "CategoryNames" )->psChild;
psEntry != NULL; psEntry = psEntry->psNext )
{
/* Don't skeep <Category> tag with empty content */
if( psEntry->eType != CXT_Element
|| !EQUAL(psEntry->pszValue,"Category")
|| (psEntry->psChild != NULL && psEntry->psChild->eType != CXT_Text) )
continue;
oCategoryNames.AddString(
(psEntry->psChild) ? psEntry->psChild->pszValue : "" );
}
GDALPamRasterBand::SetCategoryNames( oCategoryNames.List() );
}
/* -------------------------------------------------------------------- */
/* Collect a color table. */
/* -------------------------------------------------------------------- */
if( CPLGetXMLNode( psTree, "ColorTable" ) != NULL )
{
CPLXMLNode *psEntry;
GDALColorTable oTable;
int iEntry = 0;
for( psEntry = CPLGetXMLNode( psTree, "ColorTable" )->psChild;
psEntry != NULL; psEntry = psEntry->psNext )
{
GDALColorEntry sCEntry;
sCEntry.c1 = (short) atoi(CPLGetXMLValue( psEntry, "c1", "0" ));
sCEntry.c2 = (short) atoi(CPLGetXMLValue( psEntry, "c2", "0" ));
sCEntry.c3 = (short) atoi(CPLGetXMLValue( psEntry, "c3", "0" ));
sCEntry.c4 = (short) atoi(CPLGetXMLValue( psEntry, "c4", "255" ));
//.........这里部分代码省略.........
示例5: if
//.........这里部分代码省略.........
}
else if( EQUAL(argv[i],"-ct") )
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
const char *pszCT = argv[++i];
aosTO.SetNameValue("COORDINATE_OPERATION", pszCT );
}
else if( EQUAL(argv[i],"-order") )
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
nOrder = atoi(argv[++i]);
aosTO.SetNameValue("MAX_GCP_ORDER", argv[i] );
}
else if( EQUAL(argv[i],"-tps") )
{
aosTO.SetNameValue("METHOD", "GCP_TPS" );
nOrder = -1;
}
else if( EQUAL(argv[i],"-rpc") )
{
aosTO.SetNameValue("METHOD", "RPC" );
}
else if( EQUAL(argv[i],"-geoloc") )
{
aosTO.SetNameValue("METHOD", "GEOLOC_ARRAY" );
}
else if( EQUAL(argv[i],"-i") )
{
bInverse = TRUE;
}
else if( EQUAL(argv[i],"-to") )
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(1);
aosTO.AddString( argv[++i] );
}
else if( EQUAL(argv[i],"-gcp") )
{
CHECK_HAS_ENOUGH_ADDITIONAL_ARGS(4);
char* endptr = nullptr;
/* -gcp pixel line easting northing [elev] */
nGCPCount++;
pasGCPs = static_cast<GDAL_GCP *>(
CPLRealloc(pasGCPs, sizeof(GDAL_GCP) * nGCPCount));
GDALInitGCPs( 1, pasGCPs + nGCPCount - 1 );
pasGCPs[nGCPCount-1].dfGCPPixel = CPLAtof(argv[++i]);
pasGCPs[nGCPCount-1].dfGCPLine = CPLAtof(argv[++i]);
pasGCPs[nGCPCount-1].dfGCPX = CPLAtof(argv[++i]);
pasGCPs[nGCPCount-1].dfGCPY = CPLAtof(argv[++i]);
if( argv[i+1] != nullptr &&
(CPLStrtod(argv[i+1], &endptr) != 0.0 || argv[i+1][0] == '0') )
{
// Check that last argument is really a number and not a
// filename looking like a number (see ticket #863).
if (endptr && *endptr == 0)
pasGCPs[nGCPCount-1].dfGCPZ = CPLAtof(argv[++i]);
}
/* should set id and info? */
}
else if( EQUAL(argv[i],"-output_xy") )
{
bOutputXY = TRUE;
}
else if( EQUAL(argv[i],"-coord") && i + 2 < argc)
示例6: 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") );
//.........这里部分代码省略.........
示例7: GDALOpenVerticalShiftGrid
/** Load proj.4 geoidgrids as GDAL dataset
*
* @param pszProj4Geoidgrids Value of proj.4 geoidgrids parameter.
* @param pbError If not NULL, the pointed value will be set to TRUE if an
* error occurred.
*
* @return a dataset. If not NULL, it must be closed with GDALClose().
*
* @since GDAL 2.2
*/
GDALDatasetH GDALOpenVerticalShiftGrid( const char* pszProj4Geoidgrids,
int* pbError )
{
char** papszGrids = CSLTokenizeString2( pszProj4Geoidgrids, ",", 0);
const int nGridCount = CSLCount(papszGrids);
if( nGridCount == 1 )
{
CSLDestroy(papszGrids);
bool bMissingOk = false;
if( *pszProj4Geoidgrids == '@' )
{
pszProj4Geoidgrids ++;
bMissingOk = true;
}
const CPLString osFilename(GetProj4Filename(pszProj4Geoidgrids));
const char* const papszOpenOptions[] =
{ "@SHIFT_ORIGIN_IN_MINUS_180_PLUS_180=YES", nullptr };
GDALDatasetH hDS = GDALOpenEx(osFilename, 0, nullptr, papszOpenOptions, nullptr);
if( hDS == nullptr )
{
CPLDebug("GDAL", "Cannot find file corresponding to %s",
pszProj4Geoidgrids);
}
if( pbError )
*pbError = (!bMissingOk && hDS == nullptr);
return hDS;
}
CPLStringList aosFilenames;
for( int i = nGridCount - 1; i >= 0; i-- )
{
const char* pszName = papszGrids[i];
bool bMissingOk = false;
if( *pszName == '@' )
{
pszName ++;
bMissingOk = true;
}
const CPLString osFilename(GetProj4Filename(pszName));
VSIStatBufL sStat;
if( osFilename.empty() || VSIStatL(osFilename, &sStat) != 0 )
{
CPLDebug("GDAL", "Cannot find file corresponding to %s",
pszName);
if( !bMissingOk )
{
if( pbError )
*pbError = true;
CSLDestroy(papszGrids);
return nullptr;
}
}
else
{
aosFilenames.AddString(osFilename);
}
}
CSLDestroy(papszGrids);
if( aosFilenames.empty() )
{
if( pbError )
*pbError = false;
return nullptr;
}
char** papszArgv = nullptr;
papszArgv = CSLAddString(papszArgv, "-resolution");
papszArgv = CSLAddString(papszArgv, "highest");
papszArgv = CSLAddString(papszArgv, "-vrtnodata");
papszArgv = CSLAddString(papszArgv, "-inf");
papszArgv = CSLAddString(papszArgv, "-oo");
papszArgv = CSLAddString(papszArgv, "@SHIFT_ORIGIN_IN_MINUS_180_PLUS_180=YES");
GDALBuildVRTOptions* psOptions = GDALBuildVRTOptionsNew(papszArgv, nullptr);
CSLDestroy(papszArgv);
GDALDatasetH hDS =
GDALBuildVRT( "", aosFilenames.size(), nullptr, aosFilenames.List(),
psOptions, nullptr );
GDALBuildVRTOptionsFree( psOptions );
if( pbError )
*pbError = hDS != nullptr;
return hDS;
}