Maze Builder Docs 8.8.13
Loading...
Searching...
No Matches
cell.h
Go to the documentation of this file.
1#ifndef CELL_H
2#define CELL_H
3
4#include <cstdint>
5#include <memory>
6#include <shared_mutex>
7#include <unordered_map>
8
10
13namespace mazes
14{
17 class cell final
18 {
19 public:
22 explicit cell(std::int32_t index = 0);
23
26
29 cell(const cell &other);
30
34 cell &operator=(const cell &other);
35
38 cell(cell &&other) noexcept;
39
43 cell &operator=(cell &&other) noexcept;
44
47 void add_link(const std::shared_ptr<cell> &other);
48
51 void remove_link(const std::shared_ptr<cell> &other);
52
56 bool is_linked(const std::shared_ptr<cell> &c);
57
60 int32_t get_index() const noexcept;
61
64 void set_index(std::int32_t next_index) noexcept;
65 private:
67 struct weak_ptr_equal
68 {
69 template <typename T>
70 bool operator()(const std::weak_ptr<T> &lhs, const std::weak_ptr<T> &rhs) const
71 {
72 return !lhs.owner_before(rhs) && !rhs.owner_before(lhs);
73 }
74 };
76 void cleanup_links();
77
81 bool has_key(const std::shared_ptr<cell> &c);
82
83 std::unordered_map<std::weak_ptr<cell>, bool, weak_ptr_hash, weak_ptr_equal> m_links;
84
85 mutable std::shared_mutex m_links_mutex;
86
87 std::int32_t m_index;
88 };
89} // namespace mazes
90
91#endif // CELL_H
void add_link(const std::shared_ptr< cell > &other)
Add a link to another cell (passage between cells).
cell & operator=(const cell &other)
Assigns the value of another cell to this cell.
cell(const cell &other)
Copy constructor for the cell class.
~cell()
Destroys the cell object and releases any associated resources.
cell(std::int32_t index=0)
Constructs a cell object with an optional index.
cell(cell &&other) noexcept
Move constructor for the cell class. Transfers the resources from another cell to this one.
void set_index(std::int32_t next_index) noexcept
Sets the index to the specified value.
int32_t get_index() const noexcept
Retrieves the index of the current cell.
void remove_link(const std::shared_ptr< cell > &other)
Remove a link to another cell.
cell & operator=(cell &&other) noexcept
Move assignment operator for the cell class.
bool is_linked(const std::shared_ptr< cell > &c)
Checks if a cell is linked.
Hashing function to store a weak_ptr.
Definition hash_funcs.h:71