SMTStabilizer API
Public API documentation for SMTStabilizer
Loading...
Searching...
No Matches
value.h
Go to the documentation of this file.
1/* -*- Header -*-
2 *
3 * The Value Class
4 *
5 * Author: Fuqi Jia <jiafq@ios.ac.cn>
6 *
7 * Copyright (C) 2025 Fuqi Jia
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 */
27
28// Modified by Xiang Zhang, 2026
29// Additional changes licensed under the MIT License
30#ifndef VALUE_HEADER
31#define VALUE_HEADER
32#include <memory>
33
34#include "interval.h"
35#include "number.h"
36
37namespace stabilizer::parser {
38// This class is used to store the value of a variable
39// It can be any kind of value, including a number, an interval, a string, a
40// boolean, etc.
49
50class Value {
51 public:
52 Value();
53 Value(const Value &other);
54 Value &operator=(const Value &other);
55 ~Value();
56
57 // constructor
58 Value(const std::string &string_value);
61 Value(const bool &boolean_value);
62 Value(const ValueType &value_type); // empty value
63
64 void setValue(const std::string &string_value);
65 void setValue(const Number &number_value);
66 void setValue(const Interval &interval_value);
67 void setValue(const bool &boolean_value);
68
69 ValueType getType() const;
70 std::string getStringValue() const;
71 Number getNumberValue() const;
73 bool getBooleanValue() const;
74
75 // Assignment operators for different types
76 Value &operator=(const std::string &string_value);
79 Value &operator=(const bool &boolean_value);
80
81 // all the operators are defined in the number, interval, string, bool, bv,
82 // fp, array
83
84 // all the comparison operators
85 bool operator==(const Value &other) const;
86 bool operator!=(const Value &other) const;
87 bool operator<(const Value &other) const;
88 bool operator<=(const Value &other) const;
89 bool operator>(const Value &other) const;
90 bool operator>=(const Value &other) const;
91
92 // all the assignment operators
93 Value &operator+=(const Value &other);
94 Value &operator-=(const Value &other);
95 Value &operator*=(const Value &other);
96 Value &operator/=(const Value &other);
97 Value &operator%=(const Value &other);
98 Value &operator^=(const Value &other);
99 Value &operator&=(const Value &other);
100 Value &operator|=(const Value &other);
101 Value &operator<<=(const Value &other);
102 Value &operator>>=(const Value &other);
103 Value &operator++();
104 Value &operator--();
105 Value operator++(int);
106 Value operator--(int);
107
108 // all the logical operators are defined in the bool
109 bool operator&&(const Value &other) const;
110 bool operator||(const Value &other) const;
111 bool operator!() const;
112
113 // all arithmetic operators are defined in the number
114 Value operator+(const Value &other) const;
115 Value operator-(const Value &other) const;
116 Value operator*(const Value &other) const;
117 Value operator/(const Value &other) const;
118 Value operator%(const Value &other) const;
119 Value operator^(const Value &other) const;
120 Value operator&(const Value &other) const;
121 Value operator|(const Value &other) const;
122 Value operator~() const;
123 Value operator<<(const Value &other) const;
124 Value operator>>(const Value &other) const;
125
126 // all arithmetic operators are defined in the number
127 Value neg() const;
128 Value abs() const;
129 Value sqrt() const;
130 Value safeSqrt() const;
131 Value pow(const Value &other) const;
132 Value exp() const;
133 Value ln() const;
134 Value lg() const;
135 Value lb() const;
136 Value log(const Value &other) const;
137 Value ceil() const;
138 Value floor() const;
139 Value round() const;
140 Value sin() const;
141 Value cos() const;
142 Value tan() const;
143 Value cot() const;
144 Value sec() const;
145 Value csc() const;
146 Value asin() const;
147 Value acos() const;
148 Value atan() const;
149 Value acot() const;
150 Value asec() const;
151 Value acsc() const;
152 Value atan2(const Value &other) const;
153 Value sinh() const;
154 Value cosh() const;
155 Value tanh() const;
156 Value coth() const;
157 Value sech() const;
158 Value csch() const;
159 Value asinh() const;
160 Value acosh() const;
161 Value atanh() const;
162 Value acoth() const;
163 Value asech() const;
164 Value acsch() const;
165
166 // all the string operators are defined in the string
167 Value concatStr(const Value &other) const; // renamed from 'concat'
168 Value substr(const Value &start, const Value &end) const;
169 Value repeatStr(const Value &other) const; // renamed from 'repeat'
170 Value replace(const Value &old, const Value &newVal)
171 const; // renamed parameter 'new' as it's a C++ keyword
172 Value split(const Value &delimiter) const; // array is also a value
173 Value join(const Value &delimiter) const;
174 Value reverse() const;
175 Value sortStr() const; // renamed from 'sort' to avoid conflict with STL
176 Value unique() const;
177 Value trim() const;
178 Value ltrim() const;
179 Value rtrim() const;
180 Value toLower() const;
181 Value toUpper() const;
182 Value toNumber() const;
183 Value toBoolean() const;
184 Value toBV() const;
185 Value toFP() const;
186 Value toArray() const;
187
188 // print
189 std::string toString() const;
190
191 private:
192 std::string string_value;
196
198};
199
200std::shared_ptr<Value> newValue(const std::string &string_value);
201std::shared_ptr<Value> newValue(const Number &number_value);
202std::shared_ptr<Value> newValue(const Interval &interval_value);
203std::shared_ptr<Value> newValue(const bool &boolean_value);
204std::shared_ptr<Value> newValue(const ValueType &value_type);
205std::shared_ptr<Value> newValue(const int &integer_value);
206std::shared_ptr<Value> newValue(const double &double_value);
207std::shared_ptr<Value> newValue(const float &float_value);
208std::shared_ptr<Value> newValue(const long &long_value);
209std::shared_ptr<Value> newValue(const short &short_value);
210std::shared_ptr<Value> newValue(const char &char_value);
211
212} // namespace stabilizer::parser
213#endif
Value round() const
Definition value.cpp:646
Value operator*(const Value &other) const
Definition value.cpp:291
Value & operator<<=(const Value &other)
Definition value.cpp:1159
Value toNumber() const
Definition value.cpp:1080
void setValue(const std::string &string_value)
Definition value.cpp:75
Value acosh() const
Definition value.cpp:849
Value asech() const
Definition value.cpp:885
Value pow(const Value &other) const
Definition value.cpp:408
bool operator==(const Value &other) const
Definition value.cpp:213
Interval getIntervalValue() const
Definition value.cpp:112
Value log(const Value &other) const
Definition value.cpp:612
Value toLower() const
Definition value.cpp:1057
Value split(const Value &delimiter) const
Definition value.cpp:979
std::string string_value
Definition value.h:192
Value operator-(const Value &other) const
Definition value.cpp:278
Value operator&(const Value &other) const
Definition value.cpp:481
Value substr(const Value &start, const Value &end) const
Definition value.cpp:945
Value join(const Value &delimiter) const
Definition value.cpp:984
Value acoth() const
Definition value.cpp:873
bool operator>(const Value &other) const
Definition value.cpp:257
bool operator<(const Value &other) const
Definition value.cpp:234
Value operator/(const Value &other) const
Definition value.cpp:304
Value & operator-=(const Value &other)
Definition value.cpp:452
ValueType getType() const
Definition value.cpp:96
std::string toString() const
Definition value.cpp:152
Value atan2(const Value &other) const
Definition value.cpp:759
bool getBooleanValue() const
Definition value.cpp:119
Value & operator+=(const Value &other)
Definition value.cpp:447
std::string getStringValue() const
Definition value.cpp:98
Value operator<<(const Value &other) const
Definition value.cpp:497
Value reverse() const
Definition value.cpp:989
Value asinh() const
Definition value.cpp:837
Value & operator|=(const Value &other)
Definition value.cpp:1150
Value & operator>>=(const Value &other)
Definition value.cpp:1168
Value & operator=(const Value &other)
Definition value.cpp:45
Number getNumberValue() const
Definition value.cpp:105
bool operator<=(const Value &other) const
Definition value.cpp:253
Value floor() const
Definition value.cpp:634
bool operator||(const Value &other) const
Definition value.cpp:432
Value concatStr(const Value &other) const
Definition value.cpp:910
Value & operator*=(const Value &other)
Definition value.cpp:457
Value atanh() const
Definition value.cpp:861
Value repeatStr(const Value &other) const
Definition value.cpp:919
bool operator!() const
Definition value.cpp:439
Value operator>>(const Value &other) const
Definition value.cpp:505
Value operator%(const Value &other) const
Definition value.cpp:317
Value operator+(const Value &other) const
Definition value.cpp:262
bool operator>=(const Value &other) const
Definition value.cpp:259
Value & operator&=(const Value &other)
Definition value.cpp:1141
Value operator^(const Value &other) const
Definition value.cpp:473
Value acsch() const
Definition value.cpp:897
Value sortStr() const
Definition value.cpp:933
Value safeSqrt() const
Definition value.cpp:579
Value & operator^=(const Value &other)
Definition value.cpp:1132
Value & operator%=(const Value &other)
Definition value.cpp:467
Value toBoolean() const
Definition value.cpp:1101
Value & operator/=(const Value &other)
Definition value.cpp:462
Value operator|(const Value &other) const
Definition value.cpp:489
bool operator&&(const Value &other) const
Definition value.cpp:425
bool operator!=(const Value &other) const
Definition value.cpp:232
Value replace(const Value &old, const Value &newVal) const
Definition value.cpp:963
Value operator~() const
Definition value.cpp:553
Value toArray() const
Definition value.cpp:1124
Value toUpper() const
Definition value.cpp:1068
std::shared_ptr< Value > newValue(const std::string &string_value)
Definition value.cpp:168