formula_cell
Defined in header: <ixion/cell.hpp>
-
class formula_cell
A formula cell. It holds its formula tokens, which may be shared with other formula cells, and its cached result. A formula cell may belong to a formula group, in which case all cells of the group share one set of tokens and one result as a matrix, and each cell reads its own element of that matrix.
Public Functions
-
formula_cell(const formula_cell&) = delete
-
formula_cell &operator=(formula_cell) = delete
-
formula_cell()
Construct a formula cell with no tokens.
-
formula_cell(const formula_tokens_store_ptr_t &tokens)
Construct a formula cell that shares the specified token store.
-
formula_cell(row_t group_row, col_t group_col, const calc_status_ptr_t &cs, const formula_tokens_store_ptr_t &tokens)
Construct a member of a formula group. This constructor is used by model_context::set_grouped_formula_cells().
- Parameters:
group_row – Row position of the cell within its group.
group_col – Column position of the cell within its group.
cs – Calculation status shared by all cells of the group.
tokens – Token store shared by all cells of the group.
-
~formula_cell()
-
const formula_tokens_store_ptr_t &get_tokens() const
Get the store of the formula tokens of this cell.
- Returns:
Pointer to the token store, which may be shared with other formula cells.
-
double get_value(formula_result_wait_policy_t policy) const
Get the cached result as a numeric value.
Note
When the result is a matrix, the value of one element is returned: the element at the cell’s position within its group for a grouped formula cell, or the top-left element for a non-grouped formula cell.
- Parameters:
policy – Action to take in case the result is not yet available.
- Throws:
formula_error – If the result is not convertible to a numeric value.
- Returns:
Numeric value of the result.
-
std::string_view get_string(formula_result_wait_policy_t policy) const
Get the cached result as a string value.
Note
When the result is a matrix, the value of one element is returned: the element at the cell’s position within its group for a grouped formula cell, or the top-left element for a non-grouped formula cell.
- Parameters:
policy – Action to take in case the result is not yet available.
- Throws:
formula_error – If the result is not a string value.
- Returns:
String value of the result.
-
void interpret(model_context &context, const abs_address_t &pos)
Interpret the formula tokens and store the result in the cell. For a member of a formula group other than its top-left cell, this does nothing, as the top-left cell calculates the result of the whole group.
- Parameters:
context – Model context the cell belongs to.
pos – Position of the cell.
-
void check_circular(const model_context &cxt, const abs_address_t &pos)
Determine if this cell contains circular reference by walking through all its reference tokens.
-
void reset()
Reset cell’s internal state.
-
std::vector<const formula_token*> get_ref_tokens(const model_context &cxt, const abs_address_t &pos) const
Get a series of all reference tokens included in the formula expression stored in this cell.
- Parameters:
cxt – model context instance.
pos – position of the cell.
- Returns:
an array of reference formula tokens. Each element is a pointer to the actual token instance stored in the cell object. Be aware that the pointer is valid only as long as the actual token instance is alive.
-
const formula_result &get_raw_result_cache(formula_result_wait_policy_t policy) const
Get the cached result without post-processing in case of a grouped formula cell.
- Parameters:
policy – action to take in case the result is not yet available.
- Returns:
formula result.
-
formula_result get_result_cache(formula_result_wait_policy_t policy) const
Get the cached result as a single cell. For a non-grouped formula cell, it should be identical to the value from the get_raw_result_cache() call. For a grouped formula cell, you’ll get a single value assigned to the position of the cell in case the original result is a matrix value.
Note
A non-grouped formula cell whose result is a matrix gets the matrix back as is.
- Parameters:
policy – action to take in case the result is not yet available.
- Returns:
formula result.
-
void set_result_cache(formula_result result)
Set a cached result to this formula cell instance.
- Parameters:
result – cached result.
-
formula_group_t get_group_properties() const
Get the group properties of this cell: whether it is grouped, and if so, the size and the identity of its group.
- Returns:
Group properties of the cell.
-
abs_address_t get_parent_position(const abs_address_t &pos) const
Get the absolute parent position of a grouped formula cell. If the cell is not grouped, it simply returns the original position passed to this method.
- Parameters:
pos – original position from which to calculate the parent position.
- Returns:
parent position of the grouped formula cell.
Friends
- friend class detail::model_context_impl
-
class cloner
Function object that clones formula cell instances such that the cloned cells whose source cells belong to the same group share the same cloned calc status instance. Use one cloner instance per batch of cells being cloned together, such as cells stored in the same column.
A cloned cell shares the formula token store with its source cell, and inherits the source cell’s position within a group in case the source cell is grouped.
Public Functions
-
cloner()
-
~cloner()
-
std::unique_ptr<formula_cell> operator()(const formula_cell &src)
Create a new instance that is a clone of the source instance.
- Parameters:
src – Source instance to clone.
- Returns:
Cloned instance.
-
cloner()
-
formula_cell(const formula_cell&) = delete