31#define OPTION(N, V, L, H, O, P, R, D) \
32 {#N, (int) V, (int) L, (int) H, (int) O, (bool) P, D},
43 size_t l = 0, r = number_of_options;
45 size_t m = l + (r - l) / 2;
61 if (arg[0] !=
'-' || arg[1] !=
'-')
63 const bool has_no_prefix =
64 (arg[2] ==
'n' && arg[3] ==
'o' && arg[4] ==
'-');
65 const size_t offset = has_no_prefix ? 5 : 2;
67 const size_t pos =
name.find_first_of (
'=');
68 if (
pos != string::npos)
72 if (
pos == string::npos)
75 const char *val_str =
name.c_str () +
pos + 1;
84void Options::initialize_from_environment (
int &val,
const char *
name,
85 const int L,
const int H) {
89 for (
p =
"CADICAL_", q =
key; *
p;
p++)
113 const char *prev =
"";
115#define OPTION(N, V, L, H, O, P, R, D) \
118 FATAL ("'" #N "' default '" #V "' " \
119 "lower minimum '" #L "' in 'options.hpp'"); \
121 FATAL ("'" #N "' default '" #V "' " \
122 "larger maximum '" #H "' in 'options.hpp'"); \
123 if (strcmp (prev, #N) > 0) \
124 FATAL ("'%s' ordered before '" #N "' in 'options.hpp'", prev); \
126 CADICAL_assert (&val (i) == &N); \
131 CADICAL_assert (!table[i].name || !strcmp (table[i].name, #N)); \
132 table[i] = {#N, (int) (V), (int) (L), (int) (H), \
133 (int) (O), (bool) (P), D}; \
142#ifndef CADICAL_NDEBUG
151#define OPTION(N, V, L, H, O, P, R, D) \
152 initialize_from_environment (N, #N, L, H);
159void Options::set (
Option *o,
int new_val) {
162 if (old_val == new_val) {
163 LOG (
"keeping value '%d' of option '%s'", old_val, o->
name);
166 if (new_val < o->lo) {
167 LOG (
"bounding '%d' to lower limit '%d' for option '%s'", new_val,
171 if (new_val > o->
hi) {
172 LOG (
"bounding '%d' to upper limit '%d' for option '%s'", new_val,
177 LOG (
"set option 'set (\"%s\", %d)' from '%d'", o->
name, new_val,
183bool Options::set (
const char *
name,
int val) {
193 return o ? o->
val (
this) : 0;
199 unsigned different = 0;
201 const bool verbose =
false;
205#define OPTION(N, V, L, H, O, P, R, D) \
208 if (verbose || N != (V)) { \
209 if ((L) == 0 && (H) == 1) { \
210 snprintf (buffer, sizeof buffer, "--" #N "=%s", \
211 (N ? "true" : "false")); \
212 MSG (" %s%-30s%s (%s default %s'%s'%s)", \
213 ((N == (V)) ? "" : tout.bright_yellow_code ()), buffer, \
214 ((N == (V)) ? "" : tout.normal_code ()), \
215 ((N == (V)) ? "same as" : "different from"), \
216 ((N == (V)) ? tout.green_code () : tout.yellow_code ()), \
217 (bool) (V) ? "true" : "false", tout.normal_code ()); \
219 snprintf (buffer, sizeof buffer, "--" #N "=%d", N); \
220 MSG (" %s%-30s%s (%s default %s'" #V "'%s)", \
221 ((N == (V)) ? "" : tout.bright_yellow_code ()), buffer, \
222 ((N == (V)) ? "" : tout.normal_code ()), \
223 ((N == (V)) ? "same as" : "different from"), \
224 ((N == (V)) ? tout.green_code () : tout.yellow_code ()), \
225 tout.normal_code ()); \
231 MSG (
"all options are set to their default value");
238#define OPTION(N, V, L, H, O, P, R, D) \
239 if ((L) == 0 && (H) == 1) \
240 printf (" %-26s " D " [%s]\n", "--" #N "=bool", \
241 (bool) (V) ? "true" : "false"); \
243 printf (" %-26s " D " [" #V "]\n", "--" #N "=" #L ".." #H);
253 LOG (
"ignoring negative optimization mode '%d'",
val);
257 const int max_val = 31;
259 LOG (
"optimization argument '%d' reduced to '%d'",
val, max_val);
264 for (
int i = 0; i <
val && factor2 <= INT_MAX; i++)
267 int64_t factor10 = 1;
268 for (
int i = 0; i <
val && factor10 <= INT_MAX; i++)
271 unsigned increased = 0;
272#define OPTION(N, V, L, H, O, P, R, D) \
276 const int64_t factor1 = ((O) == 1 ? factor2 : factor10); \
277 int64_t new_val = factor1 * (int64_t) (V); \
280 if (new_val == (int) (V)) \
282 LOG ("optimization mode '%d' for '%s' " \
283 "gives '%" PRId64 "' instead of '%d", \
284 val, #N, new_val, (int) (V)); \
285 CADICAL_assert (new_val <= INT_MAX); \
292 MSG (
"optimization mode '-O%d' increased %u limits",
val, increased);
297void Options::disable_preprocessing () {
299#define OPTION(N, V, L, H, O, P, R, D) \
305 LOG ("plain mode disables '%s'", #N); \
306 CADICAL_assert ((L) == 0); \
307 CADICAL_assert ((H) == 1); \
313 LOG (
"forced plain mode disabled %zd preprocessing options", count);
326void Options::reset_default_values () {
328#define OPTION(N, V, L, H, O, P, R, D) \
334 LOG ("resetting option '%s' to default %s", #N, #V); \
340 LOG (
"reset %zd options to their default values", count);
350 Internal *internal = other.internal;
352#define OPTION(N, V, L, H, O, P, R, D) \
353 if ((N) == (int) (V)) \
354 LOG ("keeping non default option '--%s=%s'", #N, #V); \
355 else if ((N) != (int) (V)) { \
356 LOG ("overwriting default option by '--%s=%d'", #N, N); \
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define CADICAL_assert(ignore)
void copy(Options &other) const
int get(const char *name)
static Option * has(const char *name)
OPTIONS int & val(size_t idx)
static bool is_preprocessing_option(const char *name)
static bool parse_long_option(const char *, string &, int &)
bool parse_int_str(const char *val_str, int &val)