1 | // Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | #ifndef QT3DANIMATION_ANIMATION_NODEFUNCTOR_P_H |
4 | #define QT3DANIMATION_ANIMATION_NODEFUNCTOR_P_H |
5 | |
6 | // |
7 | // W A R N I N G |
8 | // ------------- |
9 | // |
10 | // This file is not part of the Qt API. It exists for the convenience |
11 | // of other Qt classes. This header file may change from version to |
12 | // version without notice, or even be removed. |
13 | // |
14 | // We mean it. |
15 | // |
16 | |
17 | #include <Qt3DCore/qnode.h> |
18 | #include <Qt3DCore/qbackendnode.h> |
19 | #include <private/qglobal_p.h> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | namespace Qt3DAnimation { |
24 | namespace Animation { |
25 | |
26 | class Handler; |
27 | |
28 | template<class Backend, class Manager> |
29 | class NodeFunctor : public Qt3DCore::QBackendNodeMapper |
30 | { |
31 | public: |
32 | explicit NodeFunctor(Handler *handler, Manager *manager) |
33 | : m_handler(handler) |
34 | , m_manager(manager) |
35 | { |
36 | } |
37 | |
38 | Qt3DCore::QBackendNode *create(const Qt3DCore::QNodeId nodeId) const final |
39 | { |
40 | Backend *backend = m_manager->getOrCreateResource(nodeId); |
41 | backend->setHandler(m_handler); |
42 | return backend; |
43 | } |
44 | |
45 | Qt3DCore::QBackendNode *get(Qt3DCore::QNodeId id) const final |
46 | { |
47 | return m_manager->lookupResource(id); |
48 | } |
49 | |
50 | void destroy(Qt3DCore::QNodeId id) const final |
51 | { |
52 | m_manager->releaseResource(id); |
53 | } |
54 | |
55 | private: |
56 | Handler *m_handler; |
57 | Manager *m_manager; |
58 | }; |
59 | |
60 | } // namespace Animation |
61 | } // namespace Qt3DAnimation |
62 | |
63 | QT_END_NAMESPACE |
64 | |
65 | #endif // QT3DANIMATION_ANIMATION_NODEFUNCTOR_P_H |
66 | |