-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Petr Laštovička
committed
May 18, 2022
1 parent
d092350
commit aa9daad
Showing
11 changed files
with
596 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,105 @@ | ||
#ifndef H_CELL | ||
#define H_CELL | ||
#include <string> | ||
|
||
#include "../expr/nodes/terms.hpp" | ||
using namespace std; | ||
|
||
namespace cz::lastaapps::vimxel::table { | ||
|
||
using STerm = shared_ptr<expr::Term>; | ||
using SSingleTerm = shared_ptr<expr::SingleTerm>; | ||
|
||
/** | ||
* @brief Represents a cell of a table | ||
* | ||
*/ | ||
class Cell { | ||
public: | ||
virtual ~Cell() {} | ||
// real content | ||
/** | ||
* @brief Gets real content, what user has written | ||
* | ||
* @return cell content | ||
*/ | ||
virtual const string& getContent() const = 0; | ||
// value in table | ||
/** | ||
* @brief Get calculated value of the cell, but in string form | ||
* | ||
* @return cell value string | ||
*/ | ||
virtual string getValue() const = 0; | ||
// value for calculations | ||
/** | ||
* @brief Get calculated value of the cell | ||
* | ||
* @return cell value term | ||
*/ | ||
virtual SSingleTerm getTerm() const = 0; | ||
// cell in in a cycle | ||
/** | ||
* @brief Checks if the cell is in or depends on a cycle | ||
* | ||
* @return true if the cell is in a cycle | ||
*/ | ||
virtual bool isInCycle() const = 0; | ||
|
||
/** | ||
* @brief Creates new copy of cell object | ||
* | ||
* @return new copy | ||
*/ | ||
virtual Cell* clone() const = 0; | ||
|
||
protected: | ||
}; | ||
|
||
// just to save memory | ||
const static auto EMPTY_TERM = make_shared<expr::DoubleTerm>(0.0L); | ||
|
||
/** | ||
* @brief Normal cell with content in it of any type | ||
*/ | ||
class TextCell final : public Cell { | ||
private: | ||
private: | ||
// user entered content | ||
string mContent; | ||
// value | ||
SSingleTerm mTerm; | ||
// if the cell is in a cycle | ||
bool mInCycle; | ||
|
||
public: | ||
TextCell(string, SSingleTerm term, bool inCycle); | ||
~TextCell() = default; | ||
/** | ||
* @brief Construct a new Text Cell object | ||
* | ||
* @param content cell content | ||
* @param term cell term | ||
* @param inCycle is cell in cycle | ||
*/ | ||
TextCell(string content, SSingleTerm term, bool inCycle); | ||
~TextCell() = default; | ||
|
||
const string& getContent() const override; | ||
string getValue() const override; | ||
SSingleTerm getTerm() const override; | ||
bool isInCycle() const override; | ||
virtual Cell* clone() const override; | ||
}; | ||
|
||
/** | ||
* @brief Represents an empty cell | ||
* This one shouldn't be saved into data storage (no item in preffered) | ||
*/ | ||
class EmptyCell final : public Cell { | ||
private: | ||
private: | ||
const string emptyString = ""; | ||
|
||
public: | ||
~EmptyCell() = default; | ||
~EmptyCell() = default; | ||
|
||
const string& getContent() const override; | ||
string getValue() const override; | ||
SSingleTerm getTerm() const override; | ||
bool isInCycle() const override; | ||
virtual Cell* clone() const override; | ||
}; | ||
|
||
} // namespace cz::lastaapps::vimexel::table | ||
} // namespace cz::lastaapps::vimxel::table | ||
#endif |
9 changes: 4 additions & 5 deletions
9
Semestralni_prace/src/cz/lastaapps/vimxel/table/cellContract.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
#include "cellContract.hpp" | ||
|
||
|
||
namespace cz::lastaapps::vimxel::table { | ||
void CellContract::dataUpdatedAt(const Coordinates & coord) { | ||
void CellContract::dataUpdatedAt(const Coordinates& coord) { | ||
mCallback(coord); | ||
} | ||
void CellContract::registerCallback(Callback c) { | ||
mCallback = c; | ||
mCallback = c; | ||
} | ||
void CellContract::unregisterCallback() { | ||
mCallback = Callback(); | ||
mCallback = Callback(); | ||
} | ||
} | ||
} // namespace cz::lastaapps::vimxel::table |
41 changes: 33 additions & 8 deletions
41
Semestralni_prace/src/cz/lastaapps/vimxel/table/cellContract.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,45 @@ | ||
#ifndef H_CELL_CONTRACT | ||
#define H_CELL_CONTRACT | ||
#include "coordinate.hpp" | ||
#include <functional> | ||
#include <list> | ||
|
||
#include "coordinate.hpp" | ||
|
||
using namespace std; | ||
namespace cz::lastaapps::vimxel::table { | ||
|
||
/** | ||
* @brief Contract providing data from table to other app modules | ||
*/ | ||
class CellContract { | ||
using Callback = function<void(const Coordinates&)>; | ||
// callback to call | ||
Callback mCallback; | ||
public: | ||
virtual ~CellContract() {}; | ||
virtual string getDataAt(const Coordinates & coord) const = 0; | ||
void dataUpdatedAt(const Coordinates & coord); | ||
void registerCallback(Callback); | ||
void unregisterCallback(); | ||
|
||
public: | ||
virtual ~CellContract() = default; | ||
|
||
/** | ||
* @brief Gets the content of the cell at coord from data source | ||
* | ||
* @param coord the position of the cell | ||
* @return cell content | ||
*/ | ||
virtual string getDataAt(const Coordinates& coord) const = 0; | ||
/** | ||
* @brief called by data provider, notifies observers | ||
* | ||
* @param coord cell position | ||
*/ | ||
void dataUpdatedAt(const Coordinates& coord); | ||
/** | ||
* @brief Register a callback, the old one is overwritten | ||
*/ | ||
void registerCallback(Callback); | ||
/** | ||
* @brief unregisters callback | ||
*/ | ||
void unregisterCallback(); | ||
}; | ||
} | ||
} // namespace cz::lastaapps::vimxel::table | ||
#endif |
Oops, something went wrong.