formula_result
Defined in header: <ixion/formula_result.hpp>
-
class formula_result
Store formula result which may be either boolean, numeric, textural, error, or matrix. In case the result is textural, it owns the instance of the string.
Public Types
Public Functions
-
formula_result()
Construct a numeric result with a value of 0.
-
formula_result(const formula_result &r)
Copy constructor.
-
formula_result(formula_result &&r)
Move constructor.
-
formula_result(bool b)
Construct a boolean result.
-
formula_result(double v)
Construct a numeric result.
-
formula_result(std::string str)
Construct a string result.
-
formula_result(formula_error_t e)
Construct an error result.
-
~formula_result()
-
void reset()
Reset the result to a numeric value of 0.
-
void set_boolean(bool b)
Set a boolean value, replacing the current value and type.
-
void set_value(double v)
Set a numeric value, replacing the current value and type.
-
void set_string_value(std::string str)
Set a string value, replacing the current value and type.
-
void set_error(formula_error_t e)
Set an error value, replacing the current value and type.
-
bool get_boolean() const
Get a boolean result value. The caller must make sure the result is of boolean type, else the behavior is undefined.
- Returns:
boolean result value.
-
double get_value() const
Get a numeric result value. The caller must make sure the result is of numeric type, else the behavior is undefined.
- Returns:
numeric result value.
-
const std::string &get_string() const
Get a string value for textural result. The caller must make sure the result is of textural type, else the behavior is undefined.
- Returns:
string value.
-
formula_error_t get_error() const
Get an error value of the result. The caller must make sure that the result is of error type, else the behavior is undefined.
See also
ixion::get_formula_error_name
- Returns:
enum value representing the error.
-
const matrix &get_matrix() const
Get a matrix value of the result. The caller must make sure that the result is of matrix type, else the behavior is undefined.
- Returns:
matrix result value.
-
matrix &get_matrix()
Get a matrix value of the result. The caller must make sure that the result is of matrix type, else the behavior is undefined.
- Returns:
matrix result value.
-
result_type get_type() const
Get the type of result.
- Returns:
enum value representing the result type.
-
std::string str(const model_context &cxt) const
Get a string representation of the result value no matter what the result type is.
- Parameters:
cxt – model context object.
- Returns:
string representation of the result value.
-
void parse(std::string_view s)
Parse a textural representation of a formula result, and set result value of appropriate type. A string starting with ‘#’ is an error name such as “#DIV/0!”, a string enclosed in double quotes is a string value, “true” and “false” are boolean values, and anything else is a number. An empty string leaves the result unchanged. A matrix cannot be parsed.
- Parameters:
s – formula result as a string.
- Throws:
general_error – If the string is a malformed error name or a string value without a closing quote.
-
formula_result &operator=(formula_result r)
Assignment.
-
bool operator==(const formula_result &r) const
Compare two results. They are equal when they have the same type and the same value.
- Parameters:
r – Result to compare with.
- Returns:
True if the two results are equal, false otherwise.
-
formula_result()