Geoscience Reference
In-Depth Information
Alternatively, you can use the type std::string from the standard template
library (STL), which comes with the built in operator == to check for string equality.
This is illustrated in the next snippet, which is copied from the code implementing
the utility addct (see Sect. 14.3.6 ). 19
#include <string>
using namespace std;
int main( int argc, char **argv) {
string stlsCtFilename;//ASCII color table filename
try {
//define error stream in case wrong arguments
ostringstream stlosError;
stlosError <<"usage: "<< argv[0] <<" -ct <asciiFilename>
<
inputFilename>";
//loop over all command line options
for ( int i=1;i<argc;i++){
string stlsOption=argv[i];//convert to std::string
if (stlsOption=="-h"||stlsOption=="--help") //user requires help
throw (stlosError.str());
else if (stlsOption=="-ct"||stlsOption=="--ct")
stlsCtFilename=argv[++i];//retrieve the name of the file
//check for other options
}
}
catch (string stlsError){
//handle exception and show help info here...
exit(1);
}
...
}
As a third alternative to parsing command line options, you can use the class
Optionpk from the API provided with pktools. It makes use of a template class
that is derived from the STL vector class.
14.3.6 Add Color Tables via the GDAL API
In Chap. 6 we have shown different methods to add a color table to a raster file. Here
we will write a simple utility in C++ for that. It reads a predefined color table from
a text file containing five columns, id, red, green, blue and alpha .The id represents
19 In principle, the use of argv[++i] needs to be checked against the number of arguments (argc).
To keep the code clear, we omitted this check.
 
 
Search WWH ::




Custom Search