-
Notifications
You must be signed in to change notification settings - Fork 0
/
cell.h
108 lines (76 loc) · 2.21 KB
/
cell.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#pragma once
#include "common.h"
#include "formula.h"
#include <functional>
#include <unordered_set>
using namespace std::string_literals;
class Sheet;
class Impl;
class EmptyImpl;
class Cell : public CellInterface {
public:
explicit Cell(SheetInterface& sheet);
~Cell();
Sheet& GetSheet();
void Set(std::string text);
void Clear();
bool IsEmpty();
Value GetValue() const override;
void ClearCache();
std::string GetText() const override;
std::vector<Position> GetReferencedCells() const override;
const std::vector<Position> GetDependentCells() const;
void AddDependentCell(Position pos);
private:
SheetInterface& sheet_;
std::unique_ptr<Impl> impl_ = nullptr;
std::vector<Position> dependent_cells_;
};
class Impl {
public:
virtual ~Impl() {}
virtual CellInterface::Value GetValue() = 0;
virtual std::string GetText() const = 0;
virtual std::vector<Position> GetReferencedCells() const = 0;
virtual void ClearCache() = 0;
};
class EmptyImpl : public Impl {
public:
EmptyImpl() {}
std::string GetText() const override {
return {};
}
CellInterface::Value GetValue() override {
return 0.0;
}
std::vector<Position> GetReferencedCells() const override {
return {};
}
void ClearCache() override {}
};
class TextImpl : public Impl {
public:
TextImpl(std::string text);
CellInterface::Value GetValue() override;
std::string GetText() const override;
std::vector<Position> GetReferencedCells() const override {
return {};
}
void ClearCache() override {}
private:
std::string text_;
};
class FormulaImpl : public Impl {
public:
FormulaImpl(const SheetInterface& sheet, std::string text);
CellInterface::Value CalculateFormula() const;
CellInterface::Value GetValue() override;
std::string GetText() const override;
std::vector<Position> GetReferencedCells() const override;
void ClearCache() override;
private:
const SheetInterface& sheet_;
std::unique_ptr<FormulaInterface> parsed_obj_ptr_;
std::optional<CellInterface::Value> cached_value_;
};
std::ostream& operator<<(std::ostream& output, const CellInterface::Value& val);