ArgParse Class Reference

#include <argparse.h>

List of all members.

Public Member Functions

 ArgParse (int argc=0, const char **argv=NULL)
int options (const char *intro,...)
int parse (int argc, const char **argv)
std::string geterror () const
std::string error_message () const
void usage () const
std::string command_line () const

Detailed Description

Argument Parsing

The parse function takes a list of options and variables or functions for storing option values and return <0 on failure:

    static int
    parse_files (int argc, const char *argv[])
    {
        for (int i = 0;  i < argc;  i++)
            filenames.push_back (argv[i]);
        return 0;
    }
 
    ...

    ArgParse ap;

    ap.options ("Usage: myapp [options] filename...",
            "%*", parse_objects, "",
            "-camera %f %f %f", &camera[0], &camera[1], &camera[2],
                  "set the camera position",
            "-lookat %f %f %f", &lx, &ly, &lz,
                  "set the position of interest",
            "-oversampling %d", &oversampling,  "oversamping rate",
            "-passes %d", &passes, "number of passes",
            "-lens %f %f %f", &aperture, &focalDistance, &focalLength,
                   "set aperture, focal distance, focal length",
            "-format %d %d %f", &width, &height, &aspect,
                   "set width, height, aspect ratio",
            "-v", &flag, "verbose output",
            NULL);

    if (ap.parse (argc, argv) < 0) {
        std::cerr << ap.geterror() << std::endl;
        ap.usage ();
        return EXIT_FAILURE;
    }

The available argument types are:

There are several special format tokens:

Notes:


Member Function Documentation

std::string ArgParse::command_line (  )  const

Return the entire command-line as one string.

std::string ArgParse::error_message (  )  const [inline]

Deprecated

std::string ArgParse::geterror (  )  const [inline]

Return any error messages generated during the course of parse() (and clear any error flags). If no error has occurred since the last time geterror() was called, it will return an empty string.

int ArgParse::options ( const char *  intro,
  ... 
)

Declare the command line options. After the introductory message, parameters are a set of format strings and variable pointers. Each string contains an option name and a scanf-like format string to enumerate the arguments of that option (eg. "-option %d %f %s"). The format string is followed by a list of pointers to the argument variables, just like scanf. A NULL terminates the list.

int ArgParse::parse ( int  argc,
const char **  argv 
)

With the options already set up, parse the command line. Return 0 if ok, -1 if it's a malformed command line.

void ArgParse::usage (  )  const

Print the usage message to stdout. The usage message is generated and formatted automatically based on the command and description arguments passed to parse().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Tue Oct 27 06:30:40 2009 for OpenImageIO by  doxygen 1.6.1