List of all members | Public Member Functions
program_options Class Reference

Class for program options on top of the Boost.Program_Options library. More...

Inheritance diagram for program_options:

Public Member Functions

 program_options (unsigned line_length=m_default_line_length)
 Default constructor. More...
 
 program_options (const std::string &caption, unsigned line_length=m_default_line_length)
 Constructor with setting a caption for usage output. More...
 
virtual ~program_options ()
 Default deconstructor.
 
bool good () const
 Is help needed? Are all properties set properly? More...
 
void parse (int argc, char **argv)
 Parses the command line. More...
 
bool is_set (const std::string &option) const
 Checks whether a parameter was set or not. More...
 
program_optionsadd_read_realization_option ()
 Adds an option for an input as RevLib realization. More...
 
program_optionsadd_read_specification_option ()
 Adds an option for an input as RevLib specification. More...
 
program_optionsadd_write_realization_option ()
 Adds an option for an output as RevLib realization. More...
 
program_optionsadd_costs_option ()
 Adds an option for selecting a cost function. More...
 
const std::string & read_realization_filename () const
 Returns the RevLib realization input if it was set. More...
 
const std::string & read_specification_filename () const
 Returns the RevLib specification input if it was set. More...
 
const std::string & write_realization_filename () const
 Returns the RevLib realization output if it was set. More...
 
bool is_write_realization_filename_set () const
 Checks whether a filename for RevLib realization output was set. More...
 
cost_function costs () const
 Returns a cost function. More...
 

Detailed Description

Class for program options on top of the Boost.Program_Options library.

This class can be used when writing programs for accessing algorithms. It parses from C argc and argv variables and has some functions for adding program options for common used parameters like input realization or specification filename and output realization filename.

Note
It can be useful to check the Boost.Program_Options documentation for further information.

sec_example_program_options

This could be used for a synthesis algorithm to read a specification and write the result to a realization.

...
revkit::program_options opts; // Automatically adds a --help option for displaying help
opts.add_read_specification_option(); // Adds a --filename ... option for reading specification
opts.add_write_realization_option(); // Adds a --realname ... option for writing realization
opts.parse( argc, argv ); // Parses the command line
if ( !opts.good() ) { // good means that it was not asked for --help and --filename is set
std::cout << opts << std::endl; // print usage
return 1;
}
revkit::reversible_truth_table spec;
revkit::read_specification( spec, opts.read_specification_filename() );
some_synthesis_approach( spec, circ );
revkit::write_realization( circ, opts.write_realization_filename() );

Constructor & Destructor Documentation

program_options ( unsigned  line_length = m_default_line_length)
explicit

Default constructor.

Calls the constructor of the boost::program_options::options_description base class and adds a –help option.

Parameters
line_lengthLength of the terminal where to output
Author
RevKit
Since
1.0
program_options ( const std::string &  caption,
unsigned  line_length = m_default_line_length 
)
explicit

Constructor with setting a caption for usage output.

Calls the constructor of the boost::program_options::options_description base class and adds a –help option.

Parameters
captionA caption is primarily useful for output
line_lengthLength of the terminal where to output
Author
RevKit
Since
1.0

Member Function Documentation

program_options& add_costs_option ( )

Adds an option for selecting a cost function.

This method adds an option called –costs which takes an integer value as argument representing a cost function, whereby 0 is gate costs, 1 is line costs, 2 is quantum costs, and 3 is transistor costs, respectively.

Returns
The program_options object itself for repeatedly function calls
Author
RevKit
Since
1.0
program_options& add_read_realization_option ( )

Adds an option for an input as RevLib realization.

This method adds an option called –filename which takes a RevLib realization (*.real) file as argument.

After calling this function, add_read_specification_option() cannot be called anymore.

Returns
The program_options object itself for repeatedly function calls
Author
RevKit
Since
1.0
program_options& add_read_specification_option ( )

Adds an option for an input as RevLib specification.

This method adds an option called –filename which takes a RevLib specification (*.spec) file as argument.

After calling this function, add_read_realization_option() cannot be called anymore.

Returns
The program_options object itself for repeatedly function calls
Author
RevKit
Since
1.0
program_options& add_write_realization_option ( )

Adds an option for an output as RevLib realization.

This method adds an option called –realname which takes a RevLib realization (*.real) file as argument.

To check whether this option was set or not, use is_write_realization_filename_set().

Returns
The program_options object itself for repeatedly function calls
Author
RevKit
Since
1.0
cost_function costs ( ) const

Returns a cost function.

Use this method together with add_costs_option() only. When adding that method, costs are ensured to be selected (e.g. the default ones). Then this method can create a corresponding cost function.

Returns
A cost function depending on the costs option
Author
RevKit
Since
1.0
bool good ( ) const

Is help needed? Are all properties set properly?

This method returns true when the –help option is not set and when the –filename option is set, as far as either add_read_realization_option() or add_read_specification_option() was called before.

Returns
true, when all properties are set properly. Otherwise false.
Author
RevKit
Since
1.0
bool is_set ( const std::string &  option) const

Checks whether a parameter was set or not.

This method calls Boost's variable_map::count method and checks if the parameter was set at least once.

This class should be simple in general so there is no distinction between one or more options of the same name.

Parameters
optionName of the option
Returns
true when option was set, false otherwise.
Author
RevKit
Since
1.0
bool is_write_realization_filename_set ( ) const

Checks whether a filename for RevLib realization output was set.

This method evaluates to true, when add_write_realization_option was called before and –realname was set via the command line.

Returns
True, if a realname was specified, otherwise false.
Author
RevKit
Since
1.0
void parse ( int  argc,
char **  argv 
)

Parses the command line.

Parameters
argcC argc argument of the main function
argvC argv argument of the main function
Author
RevKit
Since
1.0
const std::string& read_realization_filename ( ) const

Returns the RevLib realization input if it was set.

This method can just be called after the option was added with add_read_realization_option() and good() evaluated to true.

Returns
The filename set via the command line
Author
RevKit
Since
1.0
const std::string& read_specification_filename ( ) const

Returns the RevLib specification input if it was set.

This method can just be called after the option was added with add_read_specification_option() and good() evaluated to true.

Returns
The filename set via the command line
Author
RevKit
Since
1.0
const std::string& write_realization_filename ( ) const

Returns the RevLib realization output if it was set.

This method can just be called after the option was added with add_write_realization_option() and is_write_realization_filename_set() evaluated to true.

Returns
The filename set via the command line
Author
RevKit
Since
1.0

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

Generated on Tue Apr 16 2013 08:12:02 for RevKit by doxygen 1.8.3.1