Plasma Engine  2.0
Loading...
Searching...
No Matches
ObjectMetaData.h
1#pragma once
2
3#include <Foundation/Communication/Event.h>
4#include <Foundation/Containers/HashTable.h>
5#include <Foundation/Reflection/ReflectionUtils.h>
6#include <Foundation/Serialization/AbstractObjectGraph.h>
7#include <Foundation/Types/RefCounted.h>
8#include <Foundation/Types/SharedPtr.h>
9#include <ToolsFoundation/ToolsFoundationDLL.h>
10
14template <typename KEY, typename VALUE>
16{
17
18public:
19 struct EventData
20 {
21 KEY m_ObjectKey;
22 const VALUE* m_pValue;
23 plUInt32 m_uiModifiedFlags;
24 };
25
26 plEvent<const EventData&> m_DataModifiedEvent;
27
28 // \brief Storage for the meta data so it can be swapped when using multiple sub documents.
29 class Storage : public plRefCounted
30 {
31 public:
32 mutable enum class AccessMode { Nothing,
33 Read,
34 Write } m_AccessMode;
35 mutable KEY m_AcessingKey;
36 mutable plMutex m_Mutex;
37 plHashTable<KEY, VALUE> m_MetaData;
38
39 plEvent<const EventData&> m_DataModifiedEvent;
40 };
41
43
45
46 bool HasMetaData(const KEY objectKey) const;
47
48 void ClearMetaData(const KEY objectKey);
49
51 const VALUE* BeginReadMetaData(const KEY objectKey) const;
52 void EndReadMetaData() const;
53
54 VALUE* BeginModifyMetaData(const KEY objectKey);
55 void EndModifyMetaData(plUInt32 uiModifiedFlags = 0xFFFFFFFF);
56
57
58 plMutex& GetMutex() const { return m_pMetaStorage->m_Mutex; }
59
60 const VALUE& GetDefaultValue() const { return m_DefaultValue; }
61
65
68
70 plSharedPtr<plMetaStorageType> GetStorage() { return m_pMetaStorage; }
71
72private:
73 VALUE m_DefaultValue;
74 plSharedPtr<plMetaStorageType> m_pMetaStorage;
75 typename plEvent<const EventData&>::Unsubscriber m_EventsUnsubscriber;
76};
77
78#include <ToolsFoundation/Object/Implementation/ObjectMetaData_inl.h>
Definition AbstractObjectGraph.h:115
Definition Event.h:177
Definition HashTable.h:333
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
Definition ObjectMetaData.h:30
Stores meta data for document objects that is not part of the object itself. E.g. editor-only states ...
Definition ObjectMetaData.h:16
void AttachMetaDataToAbstractGraph(plAbstractObjectGraph &inout_graph) const
Uses reflection information from VALUE to store all properties that differ from the default value as ...
Definition ObjectMetaData_inl.h:97
void RestoreMetaDataFromAbstractGraph(const plAbstractObjectGraph &graph)
Uses reflection information from VALUE to restore all meta data properties from the graph.
Definition ObjectMetaData_inl.h:150
const VALUE * BeginReadMetaData(const KEY objectKey) const
Will always return a non-null result. May be a default object.
Definition ObjectMetaData_inl.h:15
Base class for reference counted objects.
Definition RefCounted.h:52
A Shared ptr manages a shared object and destroys that object when no one references it anymore....
Definition SharedPtr.h:10
Definition ObjectMetaData.h:20