00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef CLASP_CLI_CLASP_OPTIONS_H_INCLUDED
00021 #define CLASP_CLI_CLASP_OPTIONS_H_INCLUDED
00022
00023 #ifdef _MSC_VER
00024 #pragma warning (disable : 4200) // nonstandard extension used : zero-sized array
00025 #pragma once
00026 #endif
00027
00028 #include <clasp/clasp_facade.h>
00029 #include <string>
00030 #include <iosfwd>
00031 namespace ProgramOptions {
00032 class OptionContext;
00033 class OptionGroup;
00034 class ParsedOptions;
00035 }
00036 namespace Clasp { namespace Cli {
00037
00039 enum ConfigKey {
00040 #define CONFIG(k,g,c) config_##k,
00041 #define CLASP_CLI_DEFAULT_CONFIGS config_default = 0,
00042 #define CLASP_CLI_AUX_CONFIGS config_default_max_value,
00043 #include <clasp/cli/clasp_cli_configs.inl>
00044 config_aux_max_value,
00045 config_many,
00046 config_usr,
00047 config_usr_max_value = 127,
00048 config_asp_default = config_tweety,
00049 config_sat_default = config_trendy,
00050 config_tester_default= config_frumpy,
00051 };
00052
00054 enum OptionKey {
00055 #define OPTION(n,k,...) opt_##k,
00056 #define GROUP_BEGIN(X) X
00057 #define CLASP_SOLVER_BASIC_OPTIONS option_category_solver,
00058 #define CLASP_SOLVER_LOOKBACK_OPTIONS
00059 #define CLASP_SEARCH_BASIC_OPTIONS option_category_search,
00060 #define CLASP_SEARCH_RESTART_OPTIONS
00061 #define CLASP_SEARCH_REDUCE_OPTIONS
00062 #define CLASP_CONTEXT_OPTIONS option_category_context,
00063 #define CLASP_ASP_OPTIONS option_category_generator,
00064 #define CLASP_ENUM_OPTIONS
00065 #define CLASP_SOLVE_OPTIONS
00066 #include <clasp/cli/clasp_cli_options.inl>
00067 option_category_end
00068 };
00069 class ClaspCliConfig;
00070 class ConfigIter {
00071 public:
00072 const char* name() const;
00073 const char* args() const;
00074 bool valid()const;
00075 bool next();
00076 private:
00077 friend class ClaspCliConfig;
00078 ConfigIter(const char* x);
00079 const char* base_;
00080 };
00081 class ClaspCliConfig : public ClaspConfig {
00082 public:
00084 static ConfigKey allocConfig();
00086
00092 static void appendConfig(ConfigKey k, const char* name, const char* cmd);
00094 static ConfigKey loadConfig(const char* fileName);
00096 static ConfigIter getConfig(ConfigKey key);
00098 static bool releaseConfig(ConfigKey key);
00100 static const char* getDefaults(ProblemType f);
00101
00102 ClaspCliConfig();
00103 ~ClaspCliConfig();
00104
00109
00110 void init(uint32 solverId, ConfigKey config = config_asp_default);
00112 void initTester(uint32 solverId, ConfigKey config = config_default);
00114 bool set(OptionKey o, const char* value);
00116 bool set(uint32 solverId, OptionKey o, const char* value);
00118 bool setTester(uint32 solverId, OptionKey o, const char* value);
00120 bool finalize();
00122
00127
00128
00132 void addOptions(ProgramOptions::OptionContext& root);
00134 void addDisabled(ProgramOptions::ParsedOptions& parsed);
00136 bool finalize(const ProgramOptions::ParsedOptions& parsed, ProblemType type, bool applyDefaults);
00137
00139
00142 template <class IT>
00143 bool setConfig(IT first, IT last, ProblemType t) {
00144 RawConfig config("setConfig");
00145 while (first != last) { config.addArg(*first++); }
00146 return setConfig(config, t);
00147 }
00149 private:
00150 enum ConfigOption { opt_configuration = -1, opt_tester = -2 };
00151 static const uint8 mode_solver = 1u;
00152 static const uint8 mode_tester = 2u;
00153 static const uint8 mode_relaxed= 4u;
00154 static const uint8 opt_applied = 0x80u;
00155 struct ParseContext;
00156 typedef ProgramOptions::OptionContext OptionContext;
00157 typedef SingleOwnerPtr<ParseContext> CtxPtr;
00158 typedef SingleOwnerPtr<OptionContext> RootPtr;
00159 typedef PodVector<std::string>::type ConfigVec;
00160 typedef ProgramOptions::ParsedOptions ParsedOpts;
00161 struct ScopedSet {
00162 ScopedSet(ClaspCliConfig& s, uint8 mode, uint32 sId = 0);
00163 ~ScopedSet();
00164 ClaspCliConfig* operator->()const { return self; }
00165 ClaspCliConfig* self;
00166 };
00167 struct RawConfig {
00168 std::string raw;
00169 explicit RawConfig(const char* name);
00170 void addArg(const char* arg);
00171 void addArg(const std::string& arg);
00172 ConfigIter iterator() const { return ConfigIter(raw.data()); }
00173 };
00174 class ProgOption;
00175 void init(OptionContext* ctx, bool owned);
00176 int get(OptionKey o, CtxOpts*& ctx, SolverParams*& solver, SolveParams*& solve);
00177 bool set(ConfigOption o, const char* value);
00178 bool set(const ConfigIter& it, bool allowConfig, const ParsedOpts& exclude, ParsedOpts* out);
00179 bool setDefaults(UserConfig* active, uint32 sId, const ParsedOpts& exclude, ProblemType t);
00180 bool setConfig(const RawConfig& c, ProblemType t);
00181 void error(int opt) const;
00182 bool isGenerator() const { return (cliMode & mode_tester) == 0; }
00183 const UserConfig*active()const { return isGenerator() ? this : testerConfig(); }
00184 UserConfig* active() { return isGenerator() ? this : testerConfig(); }
00185 ProgOption* createOption(int o);
00186 bool finalizeTester(bool defs);
00187 bool finalizeSolvers(UserConfig* active, const ParsedOpts& exclude, ProblemType t, bool defs);
00188 const ParsedOpts&finalizeParsed(UserConfig* active, const ParsedOpts& parsed, ParsedOpts& exclude) const;
00189
00190 static ConfigVec configs_g;
00191 CtxPtr opts_;
00192 };
00193 void validate(const char* ctx, const SolverParams& solver, const SolveParams& search);
00194
00195 }}
00196 #endif