matrix
Defined in header: <ixion/matrix.hpp>
-
class matrix
2-dimensional matrix consisting of elements of variable types. Each element can be numeric, boolean, string, error, or empty. This class is used to represent range values or in-line matrices.
Public Types
Public Functions
-
matrix()
Construct an empty matrix with no rows and no columns.
-
matrix(size_t rows, size_t cols)
Construct a matrix of the given size, with all elements empty.
-
matrix(size_t rows, size_t cols, double numeric)
Construct a matrix of the given size, with all elements set to a number.
-
matrix(size_t rows, size_t cols, bool boolean)
Construct a matrix of the given size, with all elements set to a boolean.
-
matrix(size_t rows, size_t cols, std::string str)
Construct a matrix of the given size, with all elements set to a string.
-
matrix(size_t rows, size_t cols, formula_error_t error)
Construct a matrix of the given size, with all elements set to an error.
-
matrix(const numeric_matrix &other)
Construct a matrix with the values of a numeric matrix.
-
~matrix()
-
bool is_numeric() const
Determine if the entire matrix consists only of numeric value elements.
- Returns:
true if the entire matrix consits only of numeric value elements, false otherwise.
-
bool get_boolean(size_t row, size_t col) const
Get the value of an element as a boolean. A numeric element is true when it is not zero, and a string or empty element is false.
- Parameters:
row – Row position of the element.
col – Column position of the element.
- Returns:
Boolean value of the element.
-
bool is_numeric(size_t row, size_t col) const
Determine if an element holds a numeric or boolean value.
- Parameters:
row – Row position of the element.
col – Column position of the element.
- Returns:
True if the element is numeric or boolean, false otherwise.
-
double get_numeric(size_t row, size_t col) const
Get the value of an element as a number. A boolean element yields 1 or 0, and a string or empty element yields 0.
- Parameters:
row – Row position of the element.
col – Column position of the element.
- Returns:
Numeric value of the element.
-
void set(size_t row, size_t col, double val)
Set a numeric value to an element, replacing its current value.
- Parameters:
row – Row position of the element.
col – Column position of the element.
val – Value to set.
-
void set(size_t row, size_t col, bool val)
Set a numeric value to an element, replacing its current value.
- Parameters:
row – Row position of the element.
col – Column position of the element.
val – Value to set.
-
void set(size_t row, size_t col, std::string str)
Set a string value to an element, replacing its current value.
- Parameters:
row – Row position of the element.
col – Column position of the element.
str – Value to set.
-
void set(size_t row, size_t col, formula_error_t val)
Set a numeric value to an element, replacing its current value.
- Parameters:
row – Row position of the element.
col – Column position of the element.
val – Value to set.
-
element get(size_t row, size_t col) const
Get the type and value of an element.
- Parameters:
row – Row position of the element.
col – Column position of the element.
- Returns:
Type and value of the element.
-
size_t row_size() const
Get the number of rows.
-
size_t col_size() const
Get the number of columns.
-
numeric_matrix as_numeric() const
Convert the matrix to a numeric matrix of the same size. A boolean element becomes 1 or 0, an error element becomes 0, and a string or empty element becomes NaN.
- Returns:
Numeric matrix with the converted values.
-
struct element
Type and value of one matrix element, as returned by get().
Public Types
-
using value_type = std::variant<double, bool, std::string_view, formula_error_t>
Type of the stored value. An empty element stores no value.
Public Members
-
element_type type
Type of the element.
-
value_type value
Value of the element. A string value is a view into the matrix, valid as long as the matrix is alive and the element is not overwritten.
-
using value_type = std::variant<double, bool, std::string_view, formula_error_t>
-
matrix()