Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TQuery.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <Common/assertion.h>
6#include <Common/primitive_type.h>
7#include <Utility/utility.h>
8#include <Utility/traits.h>
9
10#include <cstddef>
11#include <memory>
12#include <utility>
13
14namespace ph::editor
15{
16
27template<typename Target, typename Performer = TQueryPerformer<Target>>
28class TQuery final
29{
30public:
32
33 TQuery(std::shared_ptr<Performer> performer, EQuery mode);
34
37 template<CDerived<Performer> DerivedPerformer>
38 TQuery(const TQuery<Target, DerivedPerformer>& derivedQuery);
39
42 template<CDerived<Performer> DerivedPerformer>
44
46
50 bool run(Target& target);
51
55 void clear();
56
57 bool isEmpty() const;
58
62 void cancel();
63
66 bool isCanceled() const;
67
68 Performer& get();
69 const Performer& get() const;
70 Performer* operator -> ();
71 const Performer* operator -> () const;
72
73 template<CDerived<Performer> DerivedPerformer = Performer, typename... Args>
74 static auto once(Args&&... args) -> TQuery<Target, DerivedPerformer>
75 {
77 std::make_shared<DerivedPerformer>(std::forward<Args>(args)...), EQuery::Once);
78 }
79
80 template<CDerived<Performer> DerivedPerformer = Performer, typename... Args>
81 static auto autoRetry(Args&&... args) -> TQuery<Target, DerivedPerformer>
82 {
84 std::make_shared<DerivedPerformer>(std::forward<Args>(args)...), EQuery::AutoRetry);
85 }
86
87private:
88 std::shared_ptr<Performer> m_performer;
89 uint32 m_numRetries = 0;
90 EQuery m_mode = EQuery::Once;
91
92 // For implicit copy/move from derived performer.
93 // (would be better if more constraints can be specified in the friend declaration)
94 template<typename OtherTarget, typename OtherPerformer>
95 friend class TQuery;
96};
97
98template<typename Target, typename Performer>
100{
101 m_performer = nullptr;
102}
103
104template<typename Target, typename Performer>
106{
107 return m_performer == nullptr;
108}
109
110template<typename Target, typename Performer>
112-> Performer&
113{
114 PH_ASSERT(m_performer);
115 return *m_performer;
116}
117
118template<typename Target, typename Performer>
120-> const Performer&
121{
122 PH_ASSERT(m_performer);
123 return *m_performer;
124}
125
126template<typename Target, typename Performer>
128-> Performer*
129{
130 return &(get());
131}
132
133template<typename Target, typename Performer>
135-> const Performer*
136{
137 return &(get());
138}
139
140}// end namespace ph::editor
141
Definition TQuery.h:29
bool isEmpty() const
Definition TQuery.h:105
bool isCanceled() const
Whether the query is canceled.
Definition TQuery.ipp:88
PH_DEFINE_INLINE_RULE_OF_5_MEMBERS_NO_DTOR(TQuery)
void clear()
Clear the underlying query performer. After this call, isEmpty() is true.
Definition TQuery.h:99
friend class TQuery
Definition TQuery.h:95
Performer * operator->()
Definition TQuery.h:127
void cancel()
Cancel the query. Does nothing if isEmpty() is true.
Definition TQuery.ipp:79
bool run(Target &target)
Definition TQuery.ipp:40
const Performer & get() const
Definition TQuery.h:119
static auto autoRetry(Args &&... args) -> TQuery< Target, DerivedPerformer >
Definition TQuery.h:81
Performer & get()
Definition TQuery.h:111
static auto once(Args &&... args) -> TQuery< Target, DerivedPerformer >
Definition TQuery.h:74
Definition ph_editor.h:10
EQuery
Definition fwd.h:7
@ AutoRetry
Definition fwd.h:9
@ Once
Definition fwd.h:8