1// Copyright (C) 2016 Paul Lemire
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QT3DRENDER_RENDER_GENERICLAMBDAJOB_H
5#define QT3DRENDER_RENDER_GENERICLAMBDAJOB_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <Qt3DCore/qaspectjob.h>
19#include <Qt3DRender/private/job_common_p.h>
20
21QT_BEGIN_NAMESPACE
22
23namespace Qt3DRender {
24
25namespace Render {
26
27template<typename T>
28class GenericLambdaJob : public Qt3DCore::QAspectJob
29{
30public:
31 explicit GenericLambdaJob(T callable, JobTypes::JobType type = JobTypes::GenericLambda, const char *name = "GenericLambda", int instance = 0)
32 : Qt3DCore::QAspectJob()
33 , m_callable(callable)
34 {
35 SET_JOB_RUN_STAT_TYPE_AND_NAME(this, type, name, instance)
36 }
37
38 // QAspectJob interface
39 void run() final
40 {
41 m_callable();
42 }
43
44private:
45 T m_callable;
46};
47
48template<typename T>
49using GenericLambdaJobPtr = QSharedPointer<GenericLambdaJob<T>>;
50
51template<typename T, typename U>
52class GenericLambdaJobAndPostFramePrivate : public Qt3DCore::QAspectJobPrivate
53{
54public:
55 explicit GenericLambdaJobAndPostFramePrivate(U postFrameCallable)
56 : m_postFrameCallable(postFrameCallable)
57 {}
58
59 ~GenericLambdaJobAndPostFramePrivate() override {}
60
61 void postFrame(Qt3DCore::QAspectManager *manager) override
62 {
63 m_postFrameCallable(manager);
64 }
65
66private:
67 U m_postFrameCallable;
68};
69
70template<typename T, typename U>
71class GenericLambdaJobAndPostFrame : public Qt3DCore::QAspectJob
72{
73public:
74 explicit GenericLambdaJobAndPostFrame(T runCallable, U postFrameCallable, JobTypes::JobType type = JobTypes::GenericLambda, const char *name = "GenericLambda")
75 : Qt3DCore::QAspectJob(*new GenericLambdaJobAndPostFramePrivate<T, U>(postFrameCallable))
76 , m_runCallable(runCallable)
77 {
78 SET_JOB_RUN_STAT_TYPE_AND_NAME(this, type, name, 0)
79 }
80
81 // QAspectJob interface
82 void run() final
83 {
84 m_runCallable();
85 }
86
87private:
88 T m_runCallable;
89};
90
91template<typename T, typename U>
92using GenericLambdaJobAndPostFramePtr = QSharedPointer<GenericLambdaJobAndPostFrame<T, U>>;
93
94} // Render
95
96} // Qt3DRender
97
98QT_END_NAMESPACE
99
100#endif // QT3DRENDER_RENDER_GENERICLAMBDAJOB_H
101

source code of qt3d/src/render/jobs/genericlambdajob_p.h