This project is a Command Line Interface (CLI) table editor created as a final work for the "Programming and Algorithmization 2" course at CTU (Czech Technical University).
This table editor allows users to create and edit tables. The cells in the tables can contain strings, numeric data, cell coordinates, formulas with parentheses and basic arithmetic operations. The table supports dynamic evaluation of the formulas as the table is edited.
- C++17
- g++ (7.3 or later for full C++17 support)
- graphviz (for generating class diagrams)
- Doxygen (for generating documentation)
make all
- Build the project and create documentationmake compile
- Compile the projectmake run
- Run the projectmake clean
- Clean the projectmake doc
- Generate documentation (requires Doxygen)
- Clone the repository
- Ensure you have all the dependencies installed.
- Build the project using
make all
. - Run the project using
make run
.
Cells can contain different data types, including strings, integers, and doubles. The type is determined dynamically using std::variant.
Formulas are dynamically evaluated and can contain basic arithmetic operations (+, -, *, /) as well as functions like sin, cos, and abs. They can also include references to other cells in the form of coordinates.
The table editor supports JSON import and export functionality through the json
and import
commands respectively.
There are various commands available for interacting with the table. To view the list of commands, type help
in the CLI or refer to the help file.
The code makes extensive use of polymorphism:
-
Cell:
FormulaCell
andValueCell
classes are derived from theCell
class. They can both be evaluated which is the primary reason for inheritance. -
Formula and FormulaToken:
FormulaCell
contains aFormula
, which is a vector ofFormulaTokens
.FormulaToken
can be a number, a cell reference, an operator, or a parenthesis. -
Basic Data Types and Operations: The code can perform operations on different data types (string, double, and integer) polymorphically. Various patterns were considered (RTTI via dynamic_cast, Double dispatch, Double dispatch with visitor, Visitor via std::variant and std::visit), with the last one being selected for implementation due to its type safety, speed, and extensibility.
-
Operation Class: An
Operation
class is derived fromFormulaToken
to execute operations. It holds a unary or binarystd::function
, which can be executed onAbstractDataType
(std::variant of string, double, and int). Operations are created and passed inOperation
viaOperationFactory
. -
OperationFactory: This utilizes Visitor classes to create operations. Currently, it is implemented as a static class but is planned to be converted into a singleton.
For more in-depth details, please refer to why_visitor.txt
in the static folder.
Efforts have been made to select the most elegant and efficient solutions for the problems faced during the development of this project. While perfection is subjective, this project surely serves as a learning curve. It is hoped that you enjoy going through the codebase as much as the development process was relished.