GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/options/options_public.h Lines: 10 10 100.0 %
Date: 2021-09-29 Branches: 4 512 0.8 %

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