CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
MergePath.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "EmptyPath.hpp"
11#include "PathVertex.hpp"
12#include "Utility.hpp"
13
15
17 template<typename... Path> class MergePath; // undefined
18
19 template<> class MergePath<> : public EmptyPath {};
20
21 template<typename Head, typename... Tail> class MergePath<Head, Tail...> {
22 public:
23 class Edges {
24 public:
25 [[nodiscard]] Edge generate() const {
26 if(!mHead.done())
27 return mHead.generate();
28 return mTail.generate() + mHeadVertexCount;
29 }
30
31 [[nodiscard]] bool done() const noexcept { return mAllDone; }
32
33 void next() {
34 if(!mHead.done())
35 mHead.next();
36 else
37 mTail.next();
38
39 mAllDone = mTail.done() && mHead.done();
40 }
41
42 private:
44 typename EdgeGeneratorType<MergePath<Tail...>>::type mTail;
45
47
49
50 Edges(const MergePath& path)
51 : mHead{path.mHead.triangles()},
52 mTail(path.mTail.triangles()), mHeadVertexCount{count(path.mHead.vertices())}, mAllDone{mTail.done() && mHead.done()} {}
53
54 friend class MergePath<Head, Tail...>;
55 };
56
57 class Vertices {
58 public:
60 if(!mHead.done())
61 return mHead.generate();
62 return mTail.generate();
63 }
64
65 [[nodiscard]] bool done() const noexcept { return mAllDone; }
66
67 void next() {
68 if(!mHead.done())
69 mHead.next();
70 else
71 mTail.next();
72
73 mAllDone = mTail.done() && mHead.done();
74 }
75
76 private:
78 typename VertexGeneratorType<MergePath<Tail...>>::type mTail;
80
81 Vertices(const MergePath& path) : mHead{path.mHead.vertices()}, mTail(path.mTail.vertices()), mAllDone{mTail.done() && mHead.done()} {}
82
83 friend class MergePath<Head, Tail...>;
84 };
85
86 MergePath(Head head, Tail... tail) : mHead{head}, mTail{tail...} {}
87
88 [[nodiscard]] Edges edges() const noexcept { return *this; }
89
90 [[nodiscard]] Vertices vertices() const noexcept { return *this; }
91
92 private:
93 Head mHead;
94 MergePath<Tail...> mTail;
95 };
96
97 template<typename... Path> MergePath<Path...> mergePath(Path... paths) { return MergePath<Path...>{std::move(paths)...}; }
98
99} // namespace CeresEngine::MeshGenerator
Will have a type named "Type" that has same type as value returned by method edges() for type Primiti...
Definition Utility.hpp:23
Definition Edge.hpp:14
Empty path with zero vertices and edges.
Definition EmptyPath.hpp:17
EdgeGeneratorType< MergePath< Tail... > >::type mTail
Definition MergePath.hpp:44
Edges(const MergePath &path)
Definition MergePath.hpp:50
EdgeGeneratorType< Head >::type mHead
Definition MergePath.hpp:43
Edge generate() const
Definition MergePath.hpp:25
bool done() const noexcept
Definition MergePath.hpp:31
bool done() const noexcept
Definition MergePath.hpp:65
PathVertex generate() const
Definition MergePath.hpp:59
VertexGeneratorType< Head >::type mHead
Definition MergePath.hpp:77
VertexGeneratorType< MergePath< Tail... > >::type mTail
Definition MergePath.hpp:78
MergePath(Head head, Tail... tail)
Definition MergePath.hpp:86
Vertices vertices() const noexcept
Definition MergePath.hpp:90
Edges edges() const noexcept
Definition MergePath.hpp:88
MergePath< Tail... > mTail
Definition MergePath.hpp:94
Merges (concatenates) multiple paths together.
Definition MergePath.hpp:17
Definition PathVertex.hpp:14
Will have a type named "Type" that has same type as value returned by method vertices() for type Prim...
Definition Utility.hpp:37
Definition AnyGenerator.hpp:12
MergePath< Path... > mergePath(Path... paths)
Definition MergePath.hpp:97
constexpr CountAlgorithmFunctor count
Returns the number of elements matching an element.
Definition Count.hpp:82
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25