Maze Builder Docs 6.7.5
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
17class cell final {
18public:
21 explicit cell(std::int32_t index = 0);
22
25
28 cell(const cell& other);
29
33 cell& operator=(const cell& other);
34
37 cell(cell&& other) noexcept;
38
42 cell& operator=(cell&& other) noexcept;
43
46 void add_link(const std::shared_ptr<cell>& other);
47
50 void remove_link(const std::shared_ptr<cell>& other);
51
54 std::vector<std::pair<std::shared_ptr<cell>, bool>> get_links() const;
55
59 bool is_linked(const std::shared_ptr<cell>& c);
60
63 int32_t get_index() const noexcept;
64
67 void set_index(std::int32_t next_index) noexcept;
68
71
72private:
73
75 struct weak_ptr_equal {
76
77 template <typename T>
78 bool operator()(const std::weak_ptr<T>& lhs, const std::weak_ptr<T>& rhs) const {
79
80 return !lhs.owner_before(rhs) && !rhs.owner_before(lhs);
81 }
82 };
83
84 bool has_key(const std::shared_ptr<cell>& c);
85
86 std::unordered_map<std::weak_ptr<cell>, bool, weak_ptr_hash, weak_ptr_equal> m_links;
87
88 mutable std::shared_mutex m_links_mutex;
89
90 std::int32_t m_index;
91};
92
93} // namespace mazes
94
95#endif // CELL_H
Cell class with links to other cells.
Definition cell.h:17
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:9
Hashing function to store a weak_ptr.
Definition hash_funcs.h:65