The Options module provides a comprehensive system for defining, parsing, and managing command-line options in MiniSat. It supports various option types including integers, doubles, strings, and booleans, with built-in range validation and help text generation.
Top-level functions
parseOptions
void parseOptions(int& argc, char** argv, bool strict = false)
Parses command-line arguments and updates registered options.
Reference to argument count, will be modified to reflect unparsed arguments
Array of argument strings
If true, exits on unrecognized options
printUsageAndExit
void printUsageAndExit(int argc, char** argv, bool verbose = false)
Prints usage information for all registered options and exits the program.
Array of argument strings
If true, includes detailed descriptions for each option
setUsageHelp
void setUsageHelp(const char* str)
Sets the usage help string displayed in help messages.
setHelpPrefixStr
void setHelpPrefixStr(const char* str)
Sets the prefix string displayed before option help.
Option base class
Option
Abstract base class for all option types. Provides the interface for parsing and displaying help.
Option name (used on command line)
Human-readable description
Category for grouping options in help
Type name displayed in help (e.g., "<int32>", "<double>")
Virtual methods
virtual bool parse(const char* str) = 0
virtual void help(bool verbose = false) = 0
Range types
IntRange
struct IntRange {
int begin;
int end;
IntRange(int b, int e);
}
Defines a valid range for integer options.
Int64Range
struct Int64Range {
int64_t begin;
int64_t end;
Int64Range(int64_t b, int64_t e);
}
Defines a valid range for 64-bit integer options.
DoubleRange
struct DoubleRange {
double begin;
double end;
bool begin_inclusive;
bool end_inclusive;
DoubleRange(double b, bool binc, double e, bool einc);
}
Defines a valid range for double options with inclusive/exclusive bounds.
Whether the lower bound is inclusive
Whether the upper bound is inclusive
IntOption
32-bit integer option with range validation.
Constructor
IntOption(const char* c, const char* n, const char* d,
int32_t def = int32_t(),
IntRange r = IntRange(INT32_MIN, INT32_MAX))
Category name for grouping
Option name (used on command line)
r
IntRange
default:"IntRange(INT32_MIN, INT32_MAX)"
Valid range for the option
Usage
// Define an option
IntOption opt_restarts("CORE", "restarts", "Number of restarts", 100, IntRange(0, INT32_MAX));
// Use as int
int restarts = opt_restarts;
// Assign new value
opt_restarts = 200;
The option automatically validates that values are within the specified range. Out-of-range values will cause the program to exit with an error message.
Operators
operator int32_t() const
operator int32_t&()
IntOption& operator=(int32_t x)
Int64Option
64-bit integer option with range validation. Not available on MSVC.
Constructor
Int64Option(const char* c, const char* n, const char* d,
int64_t def = int64_t(),
Int64Range r = Int64Range(INT64_MIN, INT64_MAX))
r
Int64Range
default:"Int64Range(INT64_MIN, INT64_MAX)"
Valid range
This class is disabled when compiling with Microsoft Visual C++ (_MSC_VER) due to lack of C99 support for strtoll.
Operators
operator int64_t() const
operator int64_t&()
Int64Option& operator=(int64_t x)
DoubleOption
Floating-point option with range validation and inclusive/exclusive bounds.
Constructor
DoubleOption(const char* c, const char* n, const char* d,
double def = double(),
DoubleRange r = DoubleRange(-HUGE_VAL, false, HUGE_VAL, false))
r
DoubleRange
default:"DoubleRange(-HUGE_VAL, false, HUGE_VAL, false)"
Valid range with inclusive/exclusive bounds
Usage
// Define option with exclusive range (0, 1)
DoubleOption opt_decay("CORE", "var-decay", "Variable decay factor",
0.95, DoubleRange(0, false, 1, false));
// Use as double
double decay = opt_decay;
// Assign new value
opt_decay = 0.99;
Operators
operator double() const
operator double&()
DoubleOption& operator=(double x)
StringOption
String option for command-line string arguments.
Constructor
StringOption(const char* c, const char* n, const char* d, const char* def = NULL)
def
const char*
default:"NULL"
Default value
Usage
// Define option
StringOption opt_output("OUTPUT", "output", "Output file name", "result.txt");
// Use as string
const char* filename = opt_output;
// Assign new value
opt_output = "new_output.txt";
Operators
operator const char*() const
operator const char*&()
StringOption& operator=(const char* x)
BoolOption
Boolean option with -name and -no-name syntax.
Constructor
BoolOption(const char* c, const char* n, const char* d, bool v)
Usage
// Define option
BoolOption opt_verbose("HELP", "verbose", "Verbose output", false);
// Use as bool
if (opt_verbose) {
printf("Verbose mode enabled\n");
}
// Assign new value
opt_verbose = true;
Boolean options use special command-line syntax:
-name sets the option to true
-no-name sets the option to false
Operators
operator bool() const
operator bool&()
BoolOption& operator=(bool b)
Example usage
#include "minisat/utils/Options.h"
using namespace Minisat;
// Define options
IntOption opt_verbosity("MAIN", "verb", "Verbosity level", 1, IntRange(0, 2));
DoubleOption opt_timeout("MAIN", "timeout", "Time limit in seconds", 0.0,
DoubleRange(0, true, HUGE_VAL, false));
BoolOption opt_help("HELP", "help", "Print help message", false);
StringOption opt_input("IO", "input", "Input file", NULL);
int main(int argc, char** argv) {
setUsageHelp("USAGE: %s [options] <input-file>\n");
parseOptions(argc, argv, true);
if (opt_help || argc < 2) {
printUsageAndExit(argc, argv, true);
}
// Use options
int verbosity = opt_verbosity;
double timeout = opt_timeout;
bool help = opt_help;
const char* input = opt_input;
return 0;
}