cxWidgets 1.0
helpers.h
Go to the documentation of this file.
1#ifndef __HELPERS_H__
2#define __HELPERS_H__
3
4
5#include <cxGrid.h>
6
7#include <string>
8#include <vector>
9
10
11// -------------------------------------------------------------------
12// Cell reference parsing helpers
13// -------------------------------------------------------------------
14
15// Convert column letter(s) to 0-based index: "A"->0, "B"->1, "Z"->25, "AA"->26
16int colLetterToIndex(const std::string& pCol);
17
18// Convert 0-based column index to letter(s): 0->"A", 25->"Z", 26->"AA"
19std::string colIndexToLetter(int pCol);
20
21// Parse a cell reference like "A1", "B3", "AA10" into row/col (0-based)
22// Returns true if valid
23bool parseCellRef(const std::string& pRef, int& pRow, int& pCol);
24
25// -------------------------------------------------------------------
26// Formula evaluation
27// -------------------------------------------------------------------
28
29// Try to parse a string as a double. Returns true if successful.
30bool tryParseDouble(const std::string& pStr, double& pVal);
31
32// Get the numeric value of a cell. Returns false if the cell is not numeric.
33bool getCellNumericValue(cx::cxGrid& pGrid, int pRow, int pCol, double& pVal);
34
35// Parse a range like "A1:B3" into start/end row/col
36bool parseRange(const std::string& pRange, int& pStartRow, int& pStartCol,
37 int& pEndRow, int& pEndCol);
38
39// Collect numeric values from a range or list of arguments.
40// Arguments can be: cell references (A1), ranges (A1:B3), or literal numbers.
41// Returns false and sets errorMsg if a non-numeric cell is encountered.
42bool collectValues(cx::cxGrid& pGrid, const std::string& pArgs,
43 std::vector<double>& pValues, std::string& pErrorMsg);
44
45// Evaluate a formula string. The formula starts with '='.
46// Returns the result as a string, or sets errorMsg on failure.
47bool evaluateFormula(cx::cxGrid& pGrid, const std::string& pFormula,
48 std::string& pResult, std::string& pErrorMsg);
49
50// -------------------------------------------------------------------
51// File I/O (simple CSV format)
52// -------------------------------------------------------------------
53
54bool saveToFile(cx::cxGrid& pGrid, const std::string& pFilePath, std::string& pErrorMsg);
55
56bool loadFromFile(cx::cxGrid& pGrid, const std::string& pFilePath, std::string& pErrorMsg);
57
58#endif
This is a class representing a grid of data, similar to a spreadsheet, with rows & columns of cells w...
Definition cxGrid.h:31
bool evaluateFormula(cx::cxGrid &pGrid, const std::string &pFormula, std::string &pResult, std::string &pErrorMsg)
bool collectValues(cx::cxGrid &pGrid, const std::string &pArgs, std::vector< double > &pValues, std::string &pErrorMsg)
bool parseCellRef(const std::string &pRef, int &pRow, int &pCol)
int colLetterToIndex(const std::string &pCol)
bool parseRange(const std::string &pRange, int &pStartRow, int &pStartCol, int &pEndRow, int &pEndCol)
std::string colIndexToLetter(int pCol)
Definition helpers.cpp:36
bool loadFromFile(cx::cxGrid &pGrid, const std::string &pFilePath, std::string &pErrorMsg)
bool saveToFile(cx::cxGrid &pGrid, const std::string &pFilePath, std::string &pErrorMsg)
bool getCellNumericValue(cx::cxGrid &pGrid, int pRow, int pCol, double &pVal)
Definition helpers.cpp:96
bool tryParseDouble(const std::string &pStr, double &pVal)