MeshLib C++ Docs
Loading...
Searching...
No Matches
MRSharedThreadSafeOwner.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include "MRPch/MRBindingMacros.h"
5#include <functional>
6#include <memory>
7
8namespace MR
9{
10
11struct TaskGroup;
12
15
19template<typename T>
20class MR_BIND_IGNORE SharedThreadSafeOwner
21{
22public:
25
27 [[nodiscard]] const T* get() { return obj_.get(); }
28
30 [[nodiscard]] std::shared_ptr<const T> getPtr() { return obj_; }
31
35 MRMESH_API const T & getOrCreate( const std::function<T()> & creator );
36
39 MRMESH_API void update( const std::function<void(T&)> & updater );
40
42 [[nodiscard]] MRMESH_API size_t heapBytes() const;
43
44private:
46 std::shared_ptr<T> obj_;
47
49 std::shared_ptr<TaskGroup> construction_;
50};
51
53
54} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:79
Definition MRSharedThreadSafeOwner.h:21
MRMESH_API void update(const std::function< void(T &)> &updater)
MRMESH_API size_t heapBytes() const
returns the amount of memory this object occupies on heap
const T * get()
returns the currently owned instance, the pointer becomes invalid after reset() or update()
Definition MRSharedThreadSafeOwner.h:27
MRMESH_API void reset()
stops owning T-instance
MRMESH_API const T & getOrCreate(const std::function< T()> &creator)
std::shared_ptr< const T > getPtr()
returns the currently owned instance
Definition MRSharedThreadSafeOwner.h:30