Maze Builder Docs 7.5.6
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#include <vector>
9
11
12namespace mazes
13{
14
18 class cell final
19 {
20 public:
23 explicit cell(std::int32_t index = 0);
24
27
30 cell(const cell &other);
31
35 cell &operator=(const cell &other);
36
39 cell(cell &&other) noexcept;
40
44 cell &operator=(cell &&other) noexcept;
45
48 void add_link(const std::shared_ptr<cell> &other);
49
52 void remove_link(const std::shared_ptr<cell> &other);
53
56 std::vector<std::pair<std::shared_ptr<cell>, bool>> get_links() const;
57
61 bool is_linked(const std::shared_ptr<cell> &c);
62
65 int32_t get_index() const noexcept;
66
69 void set_index(std::int32_t next_index) noexcept;
70
73
74 private:
76 struct weak_ptr_equal
77 {
78
79 template <typename T>
80 bool operator()(const std::weak_ptr<T> &lhs, const std::weak_ptr<T> &rhs) const
81 {
82
83 return !lhs.owner_before(rhs) && !rhs.owner_before(lhs);
84 }
85 };
86
87 bool has_key(const std::shared_ptr<cell> &c);
88
89 std::unordered_map<std::weak_ptr<cell>, bool, weak_ptr_hash, weak_ptr_equal> m_links;
90
91 mutable std::shared_mutex m_links_mutex;
92
93 std::int32_t m_index;
94 };
95
96} // namespace mazes
97
98#endif // CELL_H
Cell class with links to other cells.
Definition cell.h:19
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 cleanup_links()
Cleans up or removes links, typically as part of a resource management or shutdown process.
void remove_link(const std::shared_ptr< cell > &other)
Remove a link to another cell.
std::vector< std::pair< std::shared_ptr< cell >, bool > > get_links() const
Retrieves links to other cells.
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.
Namespace for the maze builder.
Definition algo_interface.h:6
Hashing function to store a weak_ptr.
Definition hash_funcs.h:73