Skip to content

Commit

Permalink
Add missing copyright headers and small overview comments to the opti…
Browse files Browse the repository at this point in the history
…on*.{cc,hh} files.
  • Loading branch information
Timothy Brownawell committed Mar 13, 2008
1 parent ee97869 commit b3813d2
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 1 deletion.
2 changes: 2 additions & 0 deletions option.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2006 Timothy Brownawell <tbrownaw@gmail.com>
// This is made available under the GNU GPL v2 or later.

#include "base.hh"
#include "file_io.hh"
Expand Down
12 changes: 12 additions & 0 deletions option.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
// Copyright 2006 Timothy Brownawell <tbrownaw@gmail.com>
// This is made available under the GNU GPL v2 or later.

#ifndef __OPTION_HH__
#define __OPTION_HH__

/*
* Infrastructure for parsing options.
*
* This can be used on its own with concrete_option_set::operator()(), or
* used with something like options.{cc,hh} and option_set. The former is
* very simple to do, while the latter should allow slightly better code
* structure for more involved uses.
*/

#include <stdexcept>
#include <map>
#include <set>
Expand Down
2 changes: 2 additions & 0 deletions options.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2006 Timothy Brownawell <tbrownaw@gmail.com>
// This is made available under the GNU GPL v2 or later.

#include "base.hh"
#include <algorithm>
Expand Down
10 changes: 10 additions & 0 deletions options.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
// Copyright 2006 Timothy Brownawell <tbrownaw@gmail.com>
// This is made available under the GNU GPL v2 or later.

#ifndef __OPTIONS_HH__
#define __OPTIONS_HH__

/*
* This defines 'struct options', which includes the variables and options
* defined in options_list.hh as members. Options and optsets are available
* statically as options::opts::<name>, and option variables are available
* as options::<name>.
*/

#include <list>

#include "option.hh"
Expand Down
49 changes: 48 additions & 1 deletion options_list.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,54 @@
#define OPT(name, string, type, default_, description) \
// Copyright 2006 Timothy Brownawell <tbrownaw@gmail.com>
// This is made available under the GNU GPL v2 or later.

/*
* This is a list of all options that monotone can take, what variables
* they get put into, and how they get there. There are 4 important macros
* available here (and only here):
*
* OPTSET(name)
* Defines a set of related options, which can easily be allowed for
* a particular command or reset together. It is named
* 'options::opts::name'.
*
* OPTSET_REL(parent, child)
* Declare a relationship between to optsets, so that if the parent
* is reset or allowed for a command the child will also be.
*
* OPTVAR(optset, type, name, default)
* Defines a variable 'type options::name' which is initialized to
* 'type (default)' and belongs to the named optset. When the optset
* is reset, this variable will be reset to 'type (default)'.
*
* OPTION(optset, name, hasarg, optstring, description)
* Declare an option named 'options::opts::name', which belongs to the
* given optset. 'optstring' can look like "foo", in which case it is
* specified as "--foo", or it can look like "foo,f", in which case it
* is specified as either "--foo" or "-f". The description is a
* translatable help text. 'hasarg' is a bool indicating whether this
* option takes an argument.
*
* Some expansions of this macro expect a function body, which looks
* like 'void (std::string const & arg)'. This is the 'setter' function
* for this option, and is called when the option is parsed. If the
* option was declared to not take an argument, 'arg' is empty.
* Otherwise, it is the given argument. In any case this function
* should set the option variables for this option and throw a
* 'bad_arg_internal' if this fails. The variables that are set must be
* part of the same optset as the option, or they won't get reset
* properly. When the function body is needed, 'option_bodies' will
* be defined.
*/

// This is a shortcut for an option which has its own variable and optset.
// It will take an argument unless 'type' is 'bool'.
#define OPT(name, string, type, default_, description) \
OPTVAR(name, type, name, default_) \
OPTION(name, name, has_arg<type >(), string, description)

// This is the same, except that the option and variable belong to the
// 'globals' optset. These are global options, not specific to a particular
// command.
#define GOPT(name, string, type, default_, description) \
OPTVAR(globals, type, name, default_) \
OPTION(globals, name, has_arg<type >(), string, description)
Expand Down

0 comments on commit b3813d2

Please sign in to comment.