Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * This file is part of the cvc5 project. 3 : : * 4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS 5 : : * in the top-level source directory and their institutional affiliations. 6 : : * All rights reserved. See the file COPYING in the top-level source 7 : : * directory for licensing information. 8 : : * **************************************************************************** 9 : : * 10 : : * Implements a basic options API intended to be used by the external API: 11 : : * - list option names (`getNames()`) 12 : : * - get option value by name (`get()`) 13 : : * - set option value by name (`set()`) 14 : : * - get more detailed option information (`getInfo()`) 15 : : */ 16 : : 17 : : #include "cvc5_public.h" 18 : : 19 : : #ifndef CVC5__OPTIONS__OPTIONS_PUBLIC_H 20 : : #define CVC5__OPTIONS__OPTIONS_PUBLIC_H 21 : : 22 : : #include <cvc5/cvc5_export.h> 23 : : 24 : : #include <iosfwd> 25 : : #include <optional> 26 : : #include <sstream> 27 : : #include <string> 28 : : #include <variant> 29 : : #include <vector> 30 : : 31 : : #include "options/options.h" 32 : : 33 : : namespace cvc5::internal::options { 34 : : 35 : : /** 36 : : * Get a (sorted) list of all option names that are available. 37 : : */ 38 : : std::vector<std::string> getNames() CVC5_EXPORT; 39 : : 40 : : /** 41 : : * Retrieve an option value by name (as given in key) from the Options object 42 : : * opts as a string. 43 : : */ 44 : : std::string get(const Options& opts, const std::string& name) CVC5_EXPORT; 45 : : 46 : : /** 47 : : * Update the Options object opts, set the value of the option specified by key 48 : : * to the value parsed from optionarg. 49 : : */ 50 : : void set(Options& opts, 51 : : const std::string& name, 52 : : const std::string& optionarg) CVC5_EXPORT; 53 : : 54 : : /** 55 : : * Represents information we can provide about a particular option. It contains 56 : : * its name and aliases, the current value and the default value as well as 57 : : * type-specific information like its range (if it is a number) or the choices 58 : : * (if it is a mode option). 59 : : */ 60 : : struct CVC5_EXPORT OptionInfo 61 : : { 62 : : enum class Category 63 : : { 64 : : COMMON, 65 : : EXPERT, 66 : : REGULAR, 67 : : UNDOCUMENTED 68 : : }; 69 : : 70 : : std::string name; 71 : : std::vector<std::string> aliases; 72 : : std::vector<std::string> noSupports; 73 : : bool setByUser; 74 : : Category category; 75 : : 76 : : /** No information about the options value */ 77 : : struct VoidInfo 78 : : { 79 : : }; 80 : : /** Default value and current value */ 81 : : template <typename T> 82 : : struct ValueInfo 83 : : { 84 : : T defaultValue; 85 : : T currentValue; 86 : : }; 87 : : /** Default value, current value, minimum and maximum of a numeric value */ 88 : : template <typename T> 89 : : struct NumberInfo 90 : : { 91 : : T defaultValue; 92 : : T currentValue; 93 : : std::optional<T> minimum; 94 : : std::optional<T> maximum; 95 : : }; 96 : : /** Default value, current value and choices of a mode option */ 97 : : struct ModeInfo 98 : : { 99 : : std::string defaultValue; 100 : : std::string currentValue; 101 : : std::vector<std::string> modes; 102 : : 103 : : template <typename T> 104 : 4805 : ModeInfo(const std::string& def, T cur, const std::vector<std::string>& m) 105 : 4805 : : defaultValue(def), modes(m) 106 : : { 107 : 4805 : std::stringstream ss; 108 : 4805 : ss << cur; 109 : 4805 : currentValue = ss.str(); 110 : 4805 : } 111 : : }; 112 : : 113 : : /** A variant over all possible option value information */ 114 : : std::variant<VoidInfo, 115 : : ValueInfo<bool>, 116 : : ValueInfo<std::string>, 117 : : NumberInfo<int64_t>, 118 : : NumberInfo<uint64_t>, 119 : : NumberInfo<double>, 120 : : ModeInfo> 121 : : valueInfo; 122 : : }; 123 : : 124 : : /** 125 : : * Retrieves information about an option specified by its name from an options 126 : : * object. Note that `opts` is only used to retrieve the current value. 127 : : */ 128 : : OptionInfo getInfo(const Options& opts, const std::string& name) CVC5_EXPORT; 129 : : 130 : : } // namespace cvc5::internal::options 131 : : 132 : : #endif