-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsheet.h
53 lines (36 loc) · 1.43 KB
/
sheet.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
#pragma once
#include "cell.h"
#include "common.h"
#include <set>
#include <unordered_map>
class Row {
public:
void SetCell(size_t col, std::string text, Sheet &sheet);
CellInterface* operator[](size_t col);
const CellInterface* operator[](size_t col) const;
void Clear(size_t col);
void PrintValues(std::ostream& output, size_t total_cells) const;
void PrintTexts(std::ostream& output, size_t total_cells) const;
static void PrintEmptyRow(std::ostream& output, size_t total_cells);
size_t Size() const;
private:
std::unordered_map<size_t, std::unique_ptr<Cell>> data_;
std::set<size_t> non_empty_cells_;
};
class Sheet : public SheetInterface {
public:
~Sheet() = default;
void SetCell(Position pos, std::string text) override;
const CellInterface* GetCell(Position pos) const override;
CellInterface* GetCell(Position pos) override;
void ClearCell(Position pos) override;
Size GetPrintableSize() const override;
void PrintValues(std::ostream& output) const override;
void PrintTexts(std::ostream& output) const override;
// возвращает указатель на ячейку. Если такой ячейки нет - создает пустую и возвращает указатель
Cell* GetCellOrCreate(Position pos);
private:
std::unordered_map<size_t, Row> rows_;
std::set<size_t> non_empty_rows_;
static void TestPosition(Position pos);
};