Unravel Engine C++ Reference
Loading...
Searching...
No Matches
any_path.hpp
Go to the documentation of this file.
1#ifndef GENERATOR_ANYPATH_HPP
2#define GENERATOR_ANYPATH_HPP
3
4#include <memory>
5
6#include "any_generator.hpp"
7#include "edge.hpp"
8#include "path_vertex.hpp"
9
10namespace generator
11{
12
15{
16public:
17 template<typename path_t>
18 any_path(path_t path) : base_{new derived<path_t>{std::move(path)}}
19 {
20 }
21
22 any_path(const any_path& that);
23
24 any_path(any_path&&) = default;
25
26 any_path& operator=(const any_path& that);
27
29
30 any_generator<edge_t> edges() const noexcept;
31
32 any_generator<path_vertex_t> vertices() const noexcept;
33
34private:
35 class base
36 {
37 public:
38 virtual ~base();
39 virtual std::unique_ptr<base> clone() const = 0;
40 virtual any_generator<edge_t> edges() const = 0;
41 virtual any_generator<path_vertex_t> vertices() const = 0;
42 };
43
44 template<typename path_t>
45 class derived : public base
46 {
47 public:
48 explicit derived(path_t path) : path_(std::move(path))
49 {
50 }
51
52 std::unique_ptr<base> clone() const override
53 {
54 return std::unique_ptr<base>{new derived{path_}};
55 }
56
57 any_generator<edge_t> edges() const override
58 {
59 return path_.edges();
60 }
61
62 any_generator<path_vertex_t> vertices() const override
63 {
64 return path_.vertices();
65 }
66
67 path_t path_;
68 };
69
70 std::unique_ptr<base> base_;
71};
72} // namespace generator
73
74#endif
A type erasing container that can store any path.
Definition any_path.hpp:15
any_path(path_t path)
Definition any_path.hpp:18
any_path & operator=(any_path &&)=default
any_path(any_path &&)=default