-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grid.h
24 lines (23 loc) · 903 Bytes
/
Grid.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
#pragma once
#include <unordered_map>
#include "Item.h"
class Grid {
uint32_t width;
uint32_t height;
void rangeCheck(uint32_t row, uint32_t col) const;
std::pair<uint64_t, Item> undoHistory[100];
int undoOperations{0};
int redoOperations{0};
public:
//Using map with uint64_t key as an efficient 2d array with a large number of elements
std::unordered_map<uint64_t, Item> gridMap;
explicit Grid(uint32_t width = 100, uint32_t height = 100, std::unordered_map<uint64_t,Item> gridMap = {});
//Using get-set instead of operator[][], because maps would create an empty item with [][] for a new key
Item get(uint32_t row, uint32_t col) const;
void set(uint32_t row, uint32_t col, const Item& item);
uint32_t getWidth() const;
uint32_t getHeight() const;
void doOperation(std::pair<uint64_t, Item>& operation);
bool undo();
bool redo();
};