Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
SquareGrid4.hpp
Go to the documentation of this file.
1
6// Copyright (c) 2017 Czech Technical University in Prague | Faculty of Information Technology. All rights reserved.
7
8#pragma once
9
10#include <alib/pair>
11#include <alib/tuple>
12
13#include "SquareGrid.hpp"
14
15namespace grid {
16
17template<typename TCoordinate, typename TEdge>
18class SquareGrid4 final : public SquareGrid<TCoordinate, TEdge> {
19// ---------------------------------------------------------------------------------------------------------------------
20
21 public:
22 using coordinate_type = TCoordinate;
23 using edge_type = TEdge;
26
27// =====================================================================================================================
28// Constructor, Destructor, Operators
29 public:
30 explicit SquareGrid4(TCoordinate height, TCoordinate width);
31
32// =====================================================================================================================
33// GridBase interface
34 public:
35 auto operator <=> (const SquareGrid4 &other) const {
36 return ext::tie(this->m_obstacles, this->m_height, this->m_width) <=> ext::tie(other.getObstacleList(), other.getHeight(), other.getWidth());
37 }
38
39 bool operator == (const SquareGrid4 &other) const {
40 return ext::tie(this->m_obstacles, this->m_height, this->m_width) == ext::tie(other.getObstacleList(), other.getHeight(), other.getWidth());
41 }
42
43// =====================================================================================================================
44// GridInterface interface
45
46 public:
47
48 bool isValidDirection(direction_type direction) const override;
49
50// ---------------------------------------------------------------------------------------------------------------------
51
52 protected:
53 TEdge createEdge(const node_type &a, const node_type &b) const override;
54
55// ---------------------------------------------------------------------------------------------------------------------
56// =====================================================================================================================
57// GraphInterface interface
58
59 public:
60
61 std::string name() const override;
62
63// ---------------------------------------------------------------------------------------------------------------------
64
65};
66
67// =====================================================================================================================
68
69template<typename TCoordinate, typename TEdge>
70SquareGrid4<TCoordinate, TEdge>::SquareGrid4(TCoordinate height, TCoordinate width)
71 : SquareGrid<TCoordinate, TEdge>(height, width) {
72}
73
74// ---------------------------------------------------------------------------------------------------------------------
75
76template<typename TCoordinate, typename TEdge>
78 switch (direction) {
83 return true;
84 default:
85 return false;
86 }
87}
88
89// ---------------------------------------------------------------------------------------------------------------------
90
91template<typename TCoordinate, typename TEdge>
93 const SquareGrid4::node_type &b) const {
94 return TEdge(a, b);
95}
96
97// ---------------------------------------------------------------------------------------------------------------------
98
99template<typename TCoordinate, typename TEdge>
101 return "SquareGrid4";
102}
103
104// ---------------------------------------------------------------------------------------------------------------------
105
106} // namespace grid
107
108// =====================================================================================================================
109
110namespace core {
111
118template<typename TCoordinate, typename TEdge>
119struct normalize < grid::SquareGrid4 < TCoordinate, TEdge > > {
121 grid::SquareGrid4<> grid(value.getHeight(), value.getWidth());
122
123 // Copy obstacles
124 for (auto &&i: ext::make_mover(std::move(value).getObstacleList())) {
126 obstacle = graph::GraphNormalize::normalizeObstacle(std::move(i));
127
128 grid.addObstacle(std::move(obstacle));
129 }
130
131 return grid;
132 }
133};
134
135} // namespace grid
136
137// =====================================================================================================================
138
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
static ext::pair< DefaultCoordinateType, DefaultCoordinateType > normalizeObstacle(ext::pair< TCoordinate, TCoordinate > &&obstacle)
Definition: Normalize.hpp:82
TCoordinate coordinate_type
Definition: GridInterface.hpp:23
TEdge edge_type
Definition: GridInterface.hpp:24
Definition: SquareGrid4.hpp:18
std::string name() const override
Definition: SquareGrid4.hpp:100
SquareGrid4(TCoordinate height, TCoordinate width)
Definition: SquareGrid4.hpp:70
TEdge createEdge(const node_type &a, const node_type &b) const override
Definition: SquareGrid4.hpp:92
bool operator==(const SquareGrid4 &other) const
Definition: SquareGrid4.hpp:39
auto operator<=>(const SquareGrid4 &other) const
Definition: SquareGrid4.hpp:35
SquareGridDirections direction_type
Definition: SquareGrid4.hpp:25
ext::pair< TCoordinate, TCoordinate > node_type
Definition: SquareGrid4.hpp:24
bool isValidDirection(direction_type direction) const override
Definition: SquareGrid4.hpp:77
Definition: SquareGrid.hpp:29
TCoordinate getHeight() const
Definition: SquareGrid.hpp:155
TCoordinate getWidth() const
Definition: SquareGrid.hpp:160
TCoordinate m_height
Definition: SquareGrid.hpp:41
TCoordinate m_width
Definition: SquareGrid.hpp:42
ext::set< node_type > m_obstacles
Definition: SquareGrid.hpp:43
const ext::set< node_type > & getObstacleList() const &
Definition: SquareGrid.hpp:142
int i
Definition: AllEpsilonClosure.h:118
Definition: normalize.hpp:10
constexpr tuple< Elements &... > tie(Elements &... args) noexcept
Helper of extended tuple of references construction. The tuple is constructed to reffer to values in ...
Definition: tuple.hpp:218
reference_mover< T > make_mover(T &param)
Move adaptor construction function specialized to lvalue reference parameter.
Definition: iterator.hpp:468
Definition: GridDirection.hpp:12
SquareGridDirections
Definition: GridDirection.hpp:16
static grid::SquareGrid4 eval(grid::SquareGrid4< TCoordinate, TEdge > &&value)
Definition: SquareGrid4.hpp:120
Definition: normalize.hpp:13