UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MeshSharingUtil.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
8
9namespace UE
10{
11namespace Geometry
12{
13
14
49template<typename ObjectType>
51{
52public:
56
60 TConstObjectSharedAccess(const ObjectType* Object)
61 {
62 ObjectRawPtr = Object;
63 }
64
72
74 {
75 ensureMsgf(ObjectRawPtr == nullptr && ObjectSharedPtr.IsValid() == false,
76 TEXT("TConstObjectSharedAccess::~TConstObjectSharedAccess() : Object was not released!"));
77 }
78
84 {
85 ObjectLock.Lock();
86 ObjectRawPtr = nullptr;
88 ObjectLock.Unlock();
89 }
90
96 bool AccessSharedObject(TFunctionRef<void(const ObjectType&)> ProcessFunc)
97 {
98 bool bDone = false;
99 ObjectLock.Lock();
100 if (ObjectRawPtr != nullptr)
101 {
103 bDone = true;
104 }
105 else if (ObjectSharedPtr.IsValid())
106 {
108 bDone = true;
109 }
110 ObjectLock.Unlock();
111
112 if (bDone)
113 {
114 return true;
115 }
116 else
117 {
119 return false;
120 }
121 }
122
123
124protected:
125 // only one of ObjectRawPtr or ObjectSharedPtr should be initialized. ObjectRawPtr will be checked first.
126 const ObjectType* ObjectRawPtr = nullptr;
128
129 // default-constructed value of ObjectType that will be returned if ObjectRawPtr and ObjectSharedPtr are both null/invalid
130 ObjectType EmptyObject;
131
132 // controls access to the shared object
134};
135
136
138
139}
140}
#define ensureMsgf( InExpression, InFormat,...)
Definition AssertionMacros.h:465
#define TEXT(x)
Definition Platform.h:1272
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
Definition AssetRegistryState.h:50
Definition SharedPointer.h:692
UE_FORCEINLINE_HINT const bool IsValid() const
Definition SharedPointer.h:1085
Definition MeshSharingUtil.h:51
TConstObjectSharedAccess(TSharedPtr< ObjectType > Object)
Definition MeshSharingUtil.h:68
void ReleaseSharedObject()
Definition MeshSharingUtil.h:83
TConstObjectSharedAccess(const ObjectType *Object)
Definition MeshSharingUtil.h:60
~TConstObjectSharedAccess()
Definition MeshSharingUtil.h:73
FCriticalSection ObjectLock
Definition MeshSharingUtil.h:133
const ObjectType * ObjectRawPtr
Definition MeshSharingUtil.h:126
TSharedPtr< ObjectType > ObjectSharedPtr
Definition MeshSharingUtil.h:127
bool AccessSharedObject(TFunctionRef< void(const ObjectType &)> ProcessFunc)
Definition MeshSharingUtil.h:96
TConstObjectSharedAccess()
Definition MeshSharingUtil.h:53
ObjectType EmptyObject
Definition MeshSharingUtil.h:130
TConstObjectSharedAccess< FDynamicMesh3 > FSharedConstDynamicMesh3
Definition MeshSharingUtil.h:137
Definition AdvancedWidgetsModule.cpp:13