3template <
typename KEY,
typename VALUE>
6 m_DefaultValue = VALUE();
8 auto pStorage = PL_DEFAULT_NEW(Storage);
9 pStorage->m_AcessingKey = KEY();
10 pStorage->m_AccessMode = Storage::AccessMode::Nothing;
11 SwapStorage(pStorage);
14template <
typename KEY,
typename VALUE>
17 m_pMetaStorage->m_Mutex.Lock();
18 PL_ASSERT_DEV(m_pMetaStorage->m_AccessMode == Storage::AccessMode::Nothing,
"Already accessing some data");
19 m_pMetaStorage->m_AccessMode = Storage::AccessMode::Read;
20 m_pMetaStorage->m_AcessingKey = objectKey;
22 const VALUE* pRes =
nullptr;
23 if (m_pMetaStorage->m_MetaData.TryGetValue(objectKey, pRes))
26 return &m_DefaultValue;
29template <
typename KEY,
typename VALUE>
32 PL_LOCK(m_pMetaStorage->m_Mutex);
33 PL_ASSERT_DEV(m_pMetaStorage->m_AccessMode == Storage::AccessMode::Nothing,
"Already accessing some data");
35 if (HasMetaData(objectKey))
37 m_pMetaStorage->m_MetaData.Remove(objectKey);
40 e.m_ObjectKey = objectKey;
41 e.m_pValue = &m_DefaultValue;
43 m_pMetaStorage->m_DataModifiedEvent.Broadcast(e);
47template <
typename KEY,
typename VALUE>
50 PL_LOCK(m_pMetaStorage->m_Mutex);
51 const VALUE* pValue =
nullptr;
52 return m_pMetaStorage->m_MetaData.TryGetValue(objectKey, pValue);
55template <
typename KEY,
typename VALUE>
58 m_pMetaStorage->m_Mutex.Lock();
59 PL_ASSERT_DEV(m_pMetaStorage->m_AccessMode == Storage::AccessMode::Nothing,
"Already accessing some data");
60 m_pMetaStorage->m_AccessMode = Storage::AccessMode::Write;
61 m_pMetaStorage->m_AcessingKey = objectKey;
63 return &m_pMetaStorage->m_MetaData[objectKey];
66template <
typename KEY,
typename VALUE>
69 PL_ASSERT_DEV(m_pMetaStorage->m_AccessMode == Storage::AccessMode::Read,
"Not accessing data at the moment");
71 m_pMetaStorage->m_AccessMode = Storage::AccessMode::Nothing;
72 m_pMetaStorage->m_Mutex.Unlock();
76template <
typename KEY,
typename VALUE>
79 PL_ASSERT_DEV(m_pMetaStorage->m_AccessMode == Storage::AccessMode::Write,
"Not accessing data at the moment");
80 m_pMetaStorage->m_AccessMode = Storage::AccessMode::Nothing;
82 if (uiModifiedFlags != 0)
85 e.m_ObjectKey = m_pMetaStorage->m_AcessingKey;
86 e.m_pValue = &m_pMetaStorage->m_MetaData[m_pMetaStorage->m_AcessingKey];
87 e.m_uiModifiedFlags = uiModifiedFlags;
89 m_pMetaStorage->m_DataModifiedEvent.Broadcast(e);
92 m_pMetaStorage->m_Mutex.Unlock();
96template <
typename KEY,
typename VALUE>
99 auto& AllNodes = inout_graph.GetAllNodes();
101 PL_LOCK(m_pMetaStorage->m_Mutex);
107 DefaultValues.
Reserve(m_DefaultValue.GetDynamicRTTI()->GetProperties().GetCount());
109 for (
const auto& pProp : m_DefaultValue.GetDynamicRTTI()->GetProperties())
114 DefaultValues[pProp->GetPropertyName()] =
123 for (
auto it = AllNodes.GetIterator(); it.IsValid(); ++it)
125 auto* pNode = it.Value();
126 const plUuid& guid = pNode->GetGuid();
128 const VALUE* pMeta =
nullptr;
129 if (!m_pMetaStorage->m_MetaData.TryGetValue(guid, pMeta))
132 for (
const auto& pProp : pMeta->GetDynamicRTTI()->GetProperties())
139 if (value.
IsValid() && DefaultValues[pProp->GetPropertyName()] != value)
141 pNode->AddProperty(pProp->GetPropertyName(), value);
149template <
typename KEY,
typename VALUE>
152 PL_LOCK(m_pMetaStorage->m_Mutex);
158 for (
const auto& pProp : m_DefaultValue.GetDynamicRTTI()->GetProperties())
163 PropertyNames.
PushBack(pProp->GetPropertyName());
167 auto& AllNodes = graph.GetAllNodes();
169 for (
auto it = AllNodes.GetIterator(); it.IsValid(); ++it)
171 auto* pNode = it.Value();
172 const plUuid& guid = pNode->GetGuid();
174 for (
const auto& name : PropertyNames)
176 if (
const auto* pProp = pNode->FindProperty(name))
178 VALUE* pValue = &m_pMetaStorage->m_MetaData[guid];
180 plReflectionUtils::SetMemberPropertyValue(
181 static_cast<const plAbstractMemberProperty*
>(pValue->GetDynamicRTTI()->FindPropertyByName(name)), pValue, pProp->m_Value);
187template <
typename KEY,
typename VALUE>
190 PL_ASSERT_ALWAYS(pNewStorage !=
nullptr,
"Need a valid history storage object");
192 auto retVal = m_pMetaStorage;
194 m_EventsUnsubscriber.Unsubscribe();
196 m_pMetaStorage = pNewStorage;
198 m_pMetaStorage->m_DataModifiedEvent.AddEventHandler([
this](
const EventData& e) { m_DataModifiedEvent.Broadcast(e); }, m_EventsUnsubscriber);
This is the base class for all properties that are members of a class. It provides more information a...
Definition AbstractProperty.h:237
Definition AbstractObjectGraph.h:115
void PushBack(const T &value)
Pushes value at the end of the array.
Definition ArrayBase_inl.h:333
void Reserve(plUInt32 uiCapacity)
Expands the hashtable by over-allocating the internal storage so that the load factor is lower or equ...
Definition HashTable_inl.h:307
Definition HashTable.h:333
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
A Shared ptr manages a shared object and destroys that object when no one references it anymore....
Definition SharedPtr.h:10
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
bool IsValid() const
Returns whether this variant stores any other type than 'Invalid'.
Definition Variant_inl.h:274
@ Member
The property is a 'member property', i.e. it represents some accessible value. Cast to plAbstractMemb...
Definition AbstractProperty.h:138