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