Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TStrongHandle.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <Common/assertion.h>
7
8#include <cstddef>
9
10namespace ph::editor
11{
12
16template<typename ItemInterface, typename Index = std::size_t, typename Generation = Index>
17class TStrongHandle final
18{
19public:
22
24
25 inline TStrongHandle(const WeakHandleType& weakHandle, PoolType* const pool)
26 : m_pool(pool)
27 , m_weakHandle(weakHandle)
28 {}
29
33 inline const WeakHandleType& getWeak() const
34 {
35 return m_weakHandle;
36 }
37
41 inline bool isEmpty() const
42 {
43 return !m_pool || m_weakHandle.isEmpty();
44 }
45
46 ItemInterface* accessItem();
47 const ItemInterface* viewItem() const;
48
49 inline ItemInterface* operator -> ()
50 {
51 return accessItem();
52 }
53
54 inline const ItemInterface* operator -> () const
55 {
56 return viewItem();
57 }
58
62 inline operator bool () const
63 {
64 return !isEmpty();
65 }
66
67 inline bool operator == (const TStrongHandle& rhs) const = default;
68
69private:
70 PoolType* m_pool = nullptr;
71 WeakHandleType m_weakHandle;
72};
73
74}// end namespace ph::editor
75
77
78namespace ph::editor
79{
80
81template<typename ItemInterface, typename Index, typename Generation>
83{
84 PH_ASSERT(!isEmpty());
85 return m_pool->accessItem(m_weakHandle);
86}
87
88template<typename ItemInterface, typename Index, typename Generation>
90{
91 PH_ASSERT(!isEmpty());
92 return m_pool->viewItem(m_weakHandle);
93}
94
95}// end namespace ph::editor
Definition TItemPoolInterface.h:10
Handle with strong reference semantics. Default constructor creates empty handle.
Definition TStrongHandle.h:18
PH_DEFINE_INLINE_RULE_OF_5_MEMBERS(TStrongHandle)
bool operator==(const TStrongHandle &rhs) const =default
TStrongHandle(const WeakHandleType &weakHandle, PoolType *const pool)
Definition TStrongHandle.h:25
bool isEmpty() const
Definition TStrongHandle.h:41
const ItemInterface * viewItem() const
Definition TStrongHandle.h:89
ItemInterface * accessItem()
Definition TStrongHandle.h:82
const WeakHandleType & getWeak() const
Definition TStrongHandle.h:33
ItemInterface * operator->()
Definition TStrongHandle.h:49
Handle with weak reference semantics. Default constructor creates empty handle.
Definition TWeakHandle.h:23
bool isEmpty() const
Definition TWeakHandle.h:62
Definition ph_editor.h:10