Fishnet 2.0.1
Framework for Graph-Based Analysis of GIS Vector Data
Loading...
Searching...
No Matches
SearchResult.hpp
Go to the documentation of this file.
1#pragma once
2#include <unordered_map>
3#include "NodeStatus.hpp"
5namespace fishnet::graph{
14template<class ResultImpl, typename N = ResultImpl::node_type,util::HashFunction<N> Hash=std::hash<N>, fishnet::util::BiPredicate<N> Equal = std::equal_to<N>>
16{
17protected:
18 std::unordered_map<N,NodeStatus,Hash,Equal> nodeStatus;
19public:
20 using node_type = N;
21
23 nodeStatus = std::unordered_map<N,NodeStatus,Hash,Equal>();
24 };
25
26 void onOpen(const N & node){
27 static_cast<ResultImpl *>(this)->onOpen(node);
28 }
29
30 void onClose(const N & node){
31 static_cast<ResultImpl *>(this)->onClose(node);
32 }
33
34 void onEdge(const N & from, const N & to){
35 static_cast<ResultImpl *>(this)->onEdge(from,to);
36 }
37
38 bool stop() const {
39 return static_cast<const ResultImpl *>(this)->stop();
40 }
41
42 NodeStatus getStatusOfNode(const N & node) const {
43 if (this->nodeStatus.contains(node))
44 return this->nodeStatus.at(node);
46 }
47
48 void open(const N & node){
49 if(this->isOpen(node))
50 return;
51 if (this->nodeStatus.contains(node)) {
52 this->nodeStatus[node] = NodeStatus::OPEN;
53 }
54 else {
55 this->nodeStatus.try_emplace(node,NodeStatus::OPEN);
56 }
57 this->onOpen(node);
58 }
59
60 void close(const N & node) {
61 if(this->isClosed(node))
62 return;
63 if (this->nodeStatus.contains(node)){
64 this->nodeStatus[node] = NodeStatus::CLOSED;
65 } else {
66 this->nodeStatus.try_emplace(node,NodeStatus::CLOSED);
67 }
68 this->onClose(node);
69 }
70
71 bool isOpen(const N & node) const {
72 return this->getStatusOfNode(node) == NodeStatus::OPEN;
73 }
74
75 bool isClosed(const N & node) const {
76 return this->getStatusOfNode(node) == NodeStatus::CLOSED;
77 }
78
79 bool isUnknown(const N & node) const {
80 return this->getStatusOfNode(node) == NodeStatus::UNKNOWN;
81 }
82 virtual ~SearchResult() = default;
83};
84}
CRTP Abstraction of Search Results.
Definition SearchResult.hpp:16
void onOpen(const N &node)
Definition SearchResult.hpp:26
SearchResult()
Definition SearchResult.hpp:22
void close(const N &node)
Definition SearchResult.hpp:60
bool stop() const
Definition SearchResult.hpp:38
bool isOpen(const N &node) const
Definition SearchResult.hpp:71
void onEdge(const N &from, const N &to)
Definition SearchResult.hpp:34
virtual ~SearchResult()=default
std::unordered_map< N, NodeStatus, Hash, Equal > nodeStatus
Definition SearchResult.hpp:18
NodeStatus getStatusOfNode(const N &node) const
Definition SearchResult.hpp:42
void onClose(const N &node)
Definition SearchResult.hpp:30
bool isClosed(const N &node) const
Definition SearchResult.hpp:75
void open(const N &node)
Definition SearchResult.hpp:48
bool isUnknown(const N &node) const
Definition SearchResult.hpp:79
N node_type
Definition SearchResult.hpp:20
Definition AdjacencyContainer.hpp:4
NodeStatus
Definition NodeStatus.hpp:3