5 #include "AttributeModifier.h"
9 struct maReferenceObject
11 maReferenceObject() =
default;
17 maReferenceObject(
const kstl::string& nametype) : mObj(nullptr)
19 mSearchString = nametype;
23 kstl::string mSearchString;
36 template<
int notificationLevel>
44 maReferenceHeritage(
CoreModifiable& owner,
bool isInitAttribute, KigsID ID, kstl::string value) : CoreModifiableAttributeData<maReferenceObject>(owner, isInitAttribute, ID)
46 mValue = maReferenceObject{ value };
50 maReferenceHeritage() : CoreModifiableAttributeData<maReferenceObject>(KigsID{0u}, maReferenceObject{}) {}
62 void ResetFoundModifiable()
64 mValue.mObj =
nullptr;
66 virtual void CopyData(
const CoreModifiableAttributeData<maReferenceObject>& toCopy)
override
68 const auto& toCopyValue = toCopy.const_ref();
72 if (mValue.mObj != toCopyValue.mObj)
80 ReferenceModifiable(mValue.mObj);
97 operator T*(){
return static_cast<T*
>(SearchRef()); }
113 virtual bool getValue(kstl::string& value)
const override
119 #ifdef KEEP_NAME_AS_STRING
120 value = mValue.mObj->GetRuntimeType();
122 value = std::to_string(mValue.mObj->GetRuntimeType().toUInt());
126 value += mValue.mObj->getName();
131 value = mValue.mSearchString;
137 virtual bool getValue(usString& value)
const override
147 virtual bool getValue(
void*& value)
const override
160 InitAndSearch(value);
161 DO_NOTIFICATION(notificationLevel);
164 virtual bool setValue(
const kstl::string& value)
override
169 InitAndSearch(value);
170 DO_NOTIFICATION(notificationLevel);
178 if (mValue.mObj != value)
186 ReferenceModifiable(mValue.mObj);
189 DO_NOTIFICATION(notificationLevel);
196 InitAndSearch(value);
197 DO_NOTIFICATION(notificationLevel);
212 auto found = coremodigiablemap.find(current);
215 if (found != coremodigiablemap.end())
217 kstl::vector<CoreModifiableAttribute*>& referencevector = (*found).second;
219 kstl::vector<CoreModifiableAttribute*>::iterator itcurrent = referencevector.begin();
220 kstl::vector<CoreModifiableAttribute*>::iterator itend = referencevector.end();
222 while (itcurrent != itend)
224 if ((*itcurrent) ==
this)
226 referencevector.erase(itcurrent);
232 if (referencevector.size() == 0)
234 current->unflagAsReferenceRegistered();
235 coremodigiablemap.erase(found);
242 auto found = coremodigiablemap.find(current);
245 if (found != coremodigiablemap.end())
247 kstl::vector<CoreModifiableAttribute*>& referencevector = (*found).second;
248 referencevector.push_back(
this);
253 kstl::vector<CoreModifiableAttribute*> toAdd;
254 toAdd.push_back(
this);
255 coremodigiablemap[current] = toAdd;
257 current->flagAsReferenceRegistered();
264 if (!mValue.mSearchString.empty())
266 obj = CoreModifiable::SearchInstance(mValue.mSearchString, mOwner);
273 mValue.mObj =
nullptr;
279 if (mValue.mObj != obj.get())
284 mValue.mObj = obj.get();
285 ReferenceModifiable(mValue.mObj);
292 mValue.mObj =
nullptr;
295 void InitAndSearch(
const kstl::string& nametype)
298 mValue = maReferenceObject{ nametype };
299 mValue.mObj = old_obj;
332 #endif //_MAREFERENCE_H