|
template<typename InputIterator , typename UnaryOperator > |
static string | str_join_trans (const string &sep, InputIterator begin, InputIterator end, UnaryOperator op) |
|
template<class InputIterator > |
static string | str_join (const string &sep, InputIterator begin, InputIterator end) |
|
static string & | str_replace (string &s, const string &patt, const string &repl) |
|
static string | str_replace (const string &s, const string &patt, const string &repl) |
|
static string | str_format (const string &s, size_t pre, size_t len, bool indent_first=true) |
|
static string | str_inc (const string &s) |
|
static unsigned int | cols () |
|
static string | basename (const string &s) |
|
Copyright (C) 2010 Johannes Weißl jargo.nosp@m.n@mo.nosp@m.lb.or.nosp@m.g License: your favourite BSD-style license
git clone http://github.com/weisslj/cpp-optparse.git
This is yet another option parser for C++. It is modelled after the excellent Python optparse API. Although incomplete, anyone familiar to optparse should feel at home: http://docs.python.org/library/optparse.html
Design decisions:
- elegant and easy usage more important than speed / flexibility
- shortness more important than feature completeness
- no unicode
- no checking for user programming errors
Why not use getopt/getopt_long?
- not C++ / not completely POSIX
- too cumbersome to use, would need lot of additional code
Why not use Boost.Program_options?
- boost not installed on all target platforms (esp. cluster, HPC, ...)
- too big to include just for option handling: 322 *.h (44750 lines) + 7 *.cpp (2078 lines)
Why not use tclap/Opag/Options/CmdLine/Anyoption/Argument_helper/...?
- no reason, writing one is faster than code inspection :-)
- similarity to Python desired for faster learning curve
Future work:
Python only features:
- conflict handlers
- adding new actions
Example:
using optparse::OptionParser;
OptionParser parser = OptionParser() .description("just an example");
parser.add_option("-f", "--file") .dest("filename") .help("write report to FILE") .metavar("FILE"); parser.add_option("-q", "--quiet") .action("store_false") .dest("verbose") .set_default("1") .help("don't print status messages to stdout");
optparse::Values options = parser.parse_args(argc, argv); vector<string> args = parser.args();
if (options.get("verbose")) cout << options["filename"] << endl;