Public Member Functions

graphlab::command_line_options Class Reference
[GraphLab Utility Classes and Functions]

#include <command_line_options.hpp>

Inheritance diagram for graphlab::command_line_options:
graphlab::engine_options

List of all members.

Public Member Functions

 command_line_options (const std::string &desc_str="GraphLab program.", size_t default_ncpus=2, const std::string &default_engine="async", const std::string &default_scope="edge", const std::string &default_scheduler="fifo")
 command_line_options (const std::string &desc_str, bool surpress_graphlab_options)
void print_description () const
 Print the same message that is printed when the --help command /// line argument is provided.
bool parse (int argc, char **argv)
 This function should be called AFTER all the options have been seen (including positionals). The parse function reads the standard command line arguments and fills in the attached variables. If there is an error in the syntax or parsing fails the parse routine will print the error and return false.
bool is_set (const std::string &option)
template<typename T >
void attach_option (const std::string &option, T *ret_cont, const std::string &description)
 attach a user defined option to the command line options parser.
template<typename T >
void attach_option (const std::string &option, T *ret_cont, const T &default_value, const std::string &description)
 attach a user defined option to the command line options parser.
void add_positional (const std::string &str)

Detailed Description

Because of the many engine options GraphLab has relatively sophisticated command line parsing tools. However we have found that many of our ML applications had poorly written command line parsing support so we tried to generalize the GraphLab command line tools to enable user applications to benefit from sophisticated and still easy to use command line parsing.

The command_line_options data-structure extends (wrapping) the boost::program_options library. We have tried to retain much of the functionality of the boost::program_options library while hiding some of the less "friendly" template meta-programming "features".

Here is an example of how the library is used:

  int main(int argc, char** argv) {
  
    std::string filename;
    size_t dimensions = 20;
    double bound = 1E-5;
    bool use_x = false;
    std::vector<size_t> nsamples(1,10000);
  
    // Parse command line options
    graphlab::command_line_options clopts("Welcome to a the HelloWorld");
    clopts.attach_option("file", &filename, 
                         "The input filename (required)");
    clopts.add_positional("file");
    clopts.attach_option("dim",
                         &dimensions, dimensions,
                         "the dimension of the grid");
    clopts.attach_option("bound",
                         &bound, bound,
                         "The termination bound");
    clopts.attach_option("usex",
                         &use_x, use_x,
                         "Use algorithm x");
    clopts.attach_option("nsamples",
                         &nsamples, nsamples,
                         "A vector of the number of samples"); 
    clopts.set_scheduler_type("fifo");
    clopts.set_scope_type("edge");
  
    if(!clopts.parse(argc, argv)) return EXIT_FAILURE;
  
    if(!clopts.is_set("file")) {
      std::cout << "Input file not provided" << std::endl;
  
      clopts.print_description();
      return EXIT_FAILURE;
    }
  }

Definition at line 148 of file command_line_options.hpp.


Member Function Documentation

void graphlab::command_line_options::add_positional ( const std::string &  str  ) 

This function adds the option as a positional argument. A positional argument does not require --option and instead is read based on its location. Each add_positional call adds to the next position.

template<typename T >
void graphlab::command_line_options::attach_option ( const std::string &  option,
T *  ret_cont,
const T &  default_value,
const std::string &  description 
) [inline]

attach a user defined option to the command line options parser.

The attach option command is used to attach a user defined option to the command line options parser.

Parameters:
option The name of the command line flag for that option.
ret_cont A pointer to an "arbitrary" type which can be any of the basic types (char, int, size_t, float, double, bool, string...) or an std::vector of basic types. It is important that the ret_cont point to a memory block that will exist when parse is invoked.
default_value The default value of the parameter if the user does not provide this parameter on the command line.
description Used to describe the option when --help is called or when print_description is invoked.

Definition at line 265 of file command_line_options.hpp.

template<typename T >
void graphlab::command_line_options::attach_option ( const std::string &  option,
T *  ret_cont,
const std::string &  description 
) [inline]

attach a user defined option to the command line options parser.

The attach option command is used to attach a user defined option to the command line options parser.

Parameters:
option The name of the command line flag for that option.
ret_cont A pointer to an "arbitrary" type which can be any of the basic types (char, int, size_t, float, double, bool, string...) or an std::vector of basic types. It is important that the ret_cont point to a memory block that will exist when parse is invoked.
description Used to describe the option when --help is called or when print_description is invoked.

Definition at line 229 of file command_line_options.hpp.

bool graphlab::command_line_options::is_set ( const std::string &  option  ) 

The is set function is used to test if the user provided the option. The option string should match one of the attached options.


The documentation for this class was generated from the following file: