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