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

enum class element_type

Type of a matrix element.

Values:

enumerator numeric
enumerator string
enumerator boolean
enumerator error
enumerator empty

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 matrix &other)

Copy constructor.

matrix(matrix &&other)

Move constructor.

matrix(const numeric_matrix &other)

Construct a matrix with the values of a numeric matrix.

~matrix()
matrix &operator=(matrix other)

Assignment.

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.

void swap(matrix &r)

Swap the content with another matrix.

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.

bool operator==(const matrix &r) const

Compare two matrices. They are equal when they have the same size and all their elements have the same type and value.

Parameters:

r – Matrix to compare with.

Returns:

True if the two matrices are equal, false otherwise.

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.