summaryrefslogtreecommitdiff
path: root/src/api/java/cvc5/OptionInfo.java
blob: 7690a1bc12322aa284dcb62f7414adc5ca9a8182 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/******************************************************************************
 * Top contributors (to current version):
 *   Gereon Kremer, Mudathir Mohamed
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
 * in the top-level source directory and their institutional affiliations.
 * All rights reserved.  See the file COPYING in the top-level source
 * directory for licensing information.
 * ****************************************************************************
 *
 * The cvc5 java API.
 */

package cvc5;

import java.math.BigInteger;

/**
 * Holds some description about a particular option, including its name, its
 * aliases, whether the option was explicitly set by the user, and information
 * concerning its value. The `valueInfo` member holds any of the following
 * alternatives:
 * - VoidInfo if the option holds no value (or the value has no native type)
 * - ValueInfo if the option is of type boolean or String, holds the
 *   current value and the default value.
 * - NumberInfo if the option is of type BigInteger or double, holds
 *   the current and default value, as well as the minimum and maximum.
 * - ModeInfo if the option is a mode option, holds the current and default
 *   values, as well as a list of valid modes.
 * Additionally, this class provides convenience functions to obtain the
 * current value of an option in a type-safe manner using boolValue(),
 * stringValue(), intValue(), and doubleValue(). They assert that
 * the option has the respective type and return the current value.
 */
public class OptionInfo extends AbstractPointer
{
  // region construction and destruction
  OptionInfo(Solver solver, long pointer)
  {
    super(solver, pointer);
    this.name = getName(pointer);
    this.aliases = getAliases(pointer);
    this.setByUser = getSetByUser(pointer);
    this.baseInfo = getBaseInfo(pointer);
  }

  protected static native void deletePointer(long pointer);

  public long getPointer()
  {
    return pointer;
  }

  @Override public void finalize()
  {
    deletePointer(pointer);
  }

  /**
   * @return a string representation of this optionInfo.
   */
  protected native String toString(long pointer);

  // endregion

  /** Abstract class for OptionInfo values */
  abstract class BaseInfo
  {
  }

  /** Has the current and the default value */
  public abstract class ValueInfo<T> extends BaseInfo
  {
    private final T defaultValue;
    private final T currentValue;
    public ValueInfo(T defaultValue, T currentValue)
    {
      this.defaultValue = defaultValue;
      this.currentValue = currentValue;
    }
    public T getDefaultValue()
    {
      return defaultValue;
    }
    public T getCurrentValue()
    {
      return currentValue;
    }
  }

  public class ModeInfo extends ValueInfo<String>
  {
    private final String[] modes;

    public ModeInfo(String defaultValue, String currentValue, String[] modes)
    {
      super(defaultValue, currentValue);
      this.modes = modes;
    }
    public String[] getModes()
    {
      return modes;
    }
  }

  /** Has no value information */
  public class VoidInfo extends BaseInfo
  {
  }

  /** Default value, current value, minimum and maximum of a numeric value */
  public class NumberInfo<T> extends ValueInfo<T>
  {
    private final T minimum;
    private final T maximum;
    public NumberInfo(T defaultValue, T currentValue, T minimum, T maximum)
    {
      super(defaultValue, currentValue);
      this.minimum = minimum;
      this.maximum = maximum;
    }
    public T getMinimum()
    {
      return minimum;
    }
    public T getMaximum()
    {
      return maximum;
    }
  }

  private native String getName(long pointer);

  private native String[] getAliases(long pointer);

  private native boolean getSetByUser(long pointer);

  private native BaseInfo getBaseInfo(long pointer);

  /** The option name */
  private final String name;
  public String getName()
  {
    return name;
  }
  /** The option name aliases */
  private final String[] aliases;
  public String[] getAliases()
  {
    return aliases;
  }
  /** Whether the option was explicitly set by the user */
  private final boolean setByUser;
  public boolean getSetByUser()
  {
    return setByUser;
  }

  /** The option variant information */
  private final BaseInfo baseInfo;
  public BaseInfo getBaseInfo()
  {
    return baseInfo;
  }

  /**
   * Obtain the current value as a boolean. Asserts that valueInfo holds a boolean.
   */
  public boolean booleanValue()
  {
    return booleanValue(pointer);
  }

  private native boolean booleanValue(long pointer);

  /**
   * Obtain the current value as a string. Asserts that valueInfo holds a
   * string.
   */
  public String stringValue()
  {
    return stringValue(pointer);
  }

  private native String stringValue(long pointer);

  /**
   * Obtain the current value as as int. Asserts that valueInfo holds an int.
   */
  public BigInteger intValue()
  {
    return intValue(pointer);
  }

  private native BigInteger intValue(long pointer);

  /**
   * Obtain the current value as a double. Asserts that valueInfo holds a
   * double.
   */
  public double doubleValue()
  {
    return doubleValue(pointer);
  }

  private native double doubleValue(long pointer);
};
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback