7template <
typename T>
class LockBox;
8template <
typename T>
void swap(LockBox<T>& first, LockBox<T>& second);
35 LockBox(std::shared_ptr<Key> key, T* data);
69 bool Open(std::shared_ptr<Key> key,
const std::function<
void(T&)>& forValidKey);
80 std::shared_ptr<Key> key = std::shared_ptr<Key>(
nullptr);
84 Shared* shared =
nullptr;
94 swap(first.shared, second.shared);
105 shared = other.shared;
121 if (shared && --shared->refs == 0) {
126template <
typename T>
bool LockBox<T>::Open(std::shared_ptr<Key> key,
const std::function<
void(T&)>& forValidKey) {
127 if (shared && key.get() == shared->key.get()) {
128 forValidKey(*shared->data);
135 return shared ? shared->refs : 0;
Definition: LockBox.hpp:20
Definition: LockBox.hpp:16
uint32_t RefCount() const
Number of lockboxes with the same reference.
Definition: LockBox.hpp:134
LockBox()=default
Constructor that defaults to referencing no data.
LockBox< T > & operator=(LockBox< T > rhs)
Replace the currently held reference with a new one.
Definition: LockBox.hpp:115
~LockBox()
Definition: LockBox.hpp:120
friend void swap(LockBox< T > &first, LockBox< T > &second)
Swap two lockboxes with each other.
Definition: LockBox.hpp:92
bool Open(std::shared_ptr< Key > key, const std::function< void(T &)> &forValidKey)
Open a box to access underlying contents.
Definition: LockBox.hpp:126
Definition: ResourceView.hpp:12
void swap(LockBox< T > &first, LockBox< T > &second)
Swap two lockboxes with each other.
Definition: LockBox.hpp:92