18#ifndef UpdateField_h__
19#define UpdateField_h__
47 template<
typename T,
int32 BlockBit, u
int32 Bit>
53 template<
typename T, std::
size_t Size>
56 template<
typename T, std::
size_t Size, u
int32 Bit,
int32 FirstElementBit>
62 template<
typename T,
int32 BlockBit, u
int32 Bit>
68 template<
typename T,
int32 BlockBit, u
int32 Bit>
71 template<
typename T,
bool PublicSet>
74 template<
typename T,
bool PublicSet>
109 _value = std::move(value);
135 _value = std::move(value);
170 MarkNewValue(value, std::is_base_of<HasChangesMaskTag, T>{});
177 for (std::size_t i = index; i <
_values.size(); ++i)
190 for (std::size_t i = index; i <
_values.size(); ++i)
223 value._changesMask.SetAll();
248 template<
typename T,
bool PublicSet>
255 template<
typename V,
int32 BlockBit, u
int32 Bit,
typename U = T>
256 std::enable_if_t<std::is_base_of_v<HasChangesMaskTag, U>,
257 std::conditional_t<std::is_base_of_v<IsUpdateFieldStructureTag, V>,
259 std::conditional_t<std::is_base_of_v<IsUpdateFieldHolderTag, V>,
264 if constexpr (BlockBit >= 0)
265 _value._changesMask.Set(BlockBit);
267 _value._changesMask.Set(Bit);
271 template<
typename V, std::
size_t Size, u
int32 Bit,
int32 FirstElementBit,
typename U = T>
272 std::enable_if_t<std::is_base_of_v<HasChangesMaskTag, U>,
273 std::conditional_t<std::is_base_of_v<IsUpdateFieldStructureTag, V>,
275 std::conditional_t<std::is_base_of_v<IsUpdateFieldHolderTag, V>,
280 _value._changesMask.Set(Bit);
281 if constexpr (FirstElementBit >= 0)
283 if constexpr (!std::is_base_of_v<IsUpdateFieldHolderTag, V>)
284 _value._changesMask.Set(FirstElementBit + index);
286 _value._changesMask.Set(FirstElementBit);
289 return { (
_value.*field)._values[index] };
292 template<
typename V,
int32 BlockBit, u
int32 Bit,
typename U = T>
296 if constexpr (BlockBit >= 0)
297 _value._changesMask.Set(BlockBit);
299 _value._changesMask.Set(Bit);
300 return { (
_value.*field)._values, (
_value.*field)._updateMask };
303 template<
typename V,
int32 BlockBit, u
int32 Bit,
typename U = T>
304 std::enable_if_t<std::is_base_of_v<HasChangesMaskTag, U>,
305 std::conditional_t<std::is_base_of_v<IsUpdateFieldStructureTag, V>,
307 std::conditional_t<std::is_base_of_v<IsUpdateFieldHolderTag, V>,
312 if (index >= (
_value.*field).size())
315 (
_value.*field)._values.resize(index + 1);
316 (
_value.*field)._updateMask.resize(((
_value.*field)._values.size() + 31) / 32);
319 if constexpr (BlockBit >= 0)
320 _value._changesMask.Set(BlockBit);
322 _value._changesMask.Set(Bit);
323 (
_value.*field).MarkChanged(index);
324 return { (
_value.*field)._values[index] };
327 template<
typename V,
int32 BlockBit, u
int32 Bit,
typename U = T>
331 if constexpr (BlockBit >= 0)
332 _value._changesMask.Set(BlockBit);
334 _value._changesMask.Set(Bit);
338 template<
typename V,
int32 BlockBit, u
int32 Bit,
typename U = T>
339 std::enable_if_t<std::is_base_of_v<HasChangesMaskTag, U>,
340 std::conditional_t<std::is_base_of_v<IsUpdateFieldStructureTag, V>,
342 std::conditional_t<std::is_base_of_v<IsUpdateFieldHolderTag, V>,
347 if (!(
_value.*field).has_value())
348 (
_value.*field).ConstructValue();
350 if constexpr (BlockBit >= 0)
351 _value._changesMask.Set(BlockBit);
353 _value._changesMask.Set(Bit);
357 template<
typename V,
typename U = T>
358 std::enable_if_t<!std::is_base_of_v<HasChangesMaskTag, U> && !std::is_array_v<V>,
365 template<
typename V, std::
size_t Size,
typename U = T>
366 std::enable_if_t<!std::is_base_of_v<HasChangesMaskTag, U>,
370 return { (
_value.*field)[index] };
377 template<
typename T,
bool PublicSet>
386 template<
typename U = T>
387 std::enable_if_t<std::is_base_of_v<UpdateFieldBase<value_type>, U>,
388 std::conditional_t<std::is_base_of_v<IsUpdateFieldStructureTag, value_type>,
390 std::conditional_t<std::is_base_of_v<IsUpdateFieldHolderTag, value_type>,
398 template<
typename U = T>
399 std::enable_if_t<std::is_base_of_v<UpdateFieldArrayBaseWithoutSize<value_type>, U>,
400 std::conditional_t<std::is_base_of_v<IsUpdateFieldStructureTag, value_type>,
402 std::conditional_t<std::is_base_of_v<IsUpdateFieldHolderTag, value_type>,
407 return {
_value._values[index] };
410 template<
typename U = T>
417 template<
typename U = T>
418 std::enable_if_t<std::is_base_of_v<DynamicUpdateFieldBase<value_type>, U>,
419 std::conditional_t<std::is_base_of_v<IsUpdateFieldStructureTag, value_type>,
421 std::conditional_t<std::is_base_of_v<IsUpdateFieldHolderTag, value_type>,
426 if (index >=
_value.size())
429 _value._values.resize(index + 1);
430 _value._updateMask.resize((
_value._values.size() + 31) / 32);
433 _value.MarkChanged(index);
434 return {
_value._values[index] };
437 template<
typename U = T>
444 template<
typename U = T>
445 std::enable_if_t<std::is_base_of_v<OptionalUpdateFieldBase<value_type>, U>,
446 std::conditional_t<std::is_base_of_v<IsUpdateFieldStructureTag, value_type>,
448 std::conditional_t<std::is_base_of_v<IsUpdateFieldHolderTag, value_type>,
456 return { *(
_value._value) };
463 template<std::
size_t Bits>
469 template<
typename T,
bool PublicSet>
472 template<
typename T,
int32 BlockBit, u
int32 Bit>
475 template<
typename T, std::
size_t Size, u
int32 Bit,
int32 FirstElementBit>
478 template<
typename T,
int32 BlockBit, u
int32 Bit>
485 template<
typename Derived,
typename T,
int32 BlockBit, u
int32 Bit>
489 return { (
static_cast<Derived*
>(
this)->*field)._value };
492 template<
typename Derived,
typename T, std::
size_t Size, u
int32 Bit,
int32 FirstElementBit>
496 return { (
static_cast<Derived*
>(
this)->*field)._values[index] };
499 template<
typename Derived,
typename T,
int32 BlockBit, u
int32 Bit>
503 return { (
static_cast<Derived*
>(
this)->*field)._values };
506 template<
typename Derived,
typename T,
int32 BlockBit, u
int32 Bit>
510 if (index >= uf.
size())
518 (
static_cast<Derived*
>(
this)->*field).MarkChanged(index);
522 template<
typename Derived,
typename T,
int32 BlockBit, u
int32 Bit>
526 return { *((
static_cast<Derived*
>(
this)->*field)._value) };
529 template<
typename Derived,
typename T,
int32 BlockBit, u
int32 Bit>
532 static_assert(std::is_base_of_v<Base, Derived>,
"Given field argument must belong to the same structure as this HasChangesMask");
534 if constexpr (BlockBit >= 0)
540 template<
typename Derived,
typename T, std::
size_t Size, u
int32 Bit,
int32 FirstElementBit>
543 static_assert(std::is_base_of_v<Base, Derived>,
"Given field argument must belong to the same structure as this HasChangesMask");
546 if constexpr (FirstElementBit >= 0)
548 if constexpr (!std::is_base_of_v<IsUpdateFieldHolderTag, T>)
555 template<
typename Derived,
typename T,
int32 BlockBit, u
int32 Bit>
558 static_assert(std::is_base_of_v<Base, Derived>,
"Given field argument must belong to the same structure as this HasChangesMask");
560 if constexpr (BlockBit >= 0)
566 template<
typename Derived,
typename T,
int32 BlockBit, u
int32 Bit>
569 static_assert(std::is_base_of_v<Base, Derived>,
"Given field argument must belong to the same structure as this HasChangesMask");
571 if constexpr (BlockBit >= 0)
577 template<
typename Derived,
typename T,
int32 BlockBit, u
int32 Bit>
580 static_assert(std::is_base_of_v<Base, Derived>,
"Given field argument must belong to the same structure as this HasChangesMask");
585 template<
typename Derived,
typename T, std::
size_t Size, u
int32 Bit,
int32 FirstElementBit>
588 static_assert(std::is_base_of_v<Base, Derived>,
"Given field argument must belong to the same structure as this HasChangesMask");
590 if constexpr (FirstElementBit >= 0)
592 if constexpr (!std::is_base_of_v<IsUpdateFieldHolderTag, T>)
599 template<
typename Derived,
typename T,
int32 BlockBit, u
int32 Bit>
603 (
static_cast<Derived*
>(
this)->*field).ClearChanged(index);
606 template<
typename Derived,
typename T,
int32 BlockBit, u
int32 Bit>
609 static_assert(std::is_base_of_v<Base, Derived>,
"Given field argument must belong to the same structure as this HasChangesMask");
617 template<
typename T,
int32 BlockBit, u
int32 Bit>
623 template<
typename T,
int32 BlockBit, u
int32 Bit>
626 template<
typename T,
int32 BlockBit, u
int32 Bit>
629 field.
_value.ClearChangesMask();
632 template<
typename T, std::
size_t Size, u
int32 Bit,
int32 FirstElementBit>
635 ClearChangesMask(field, std::disjunction<std::is_base_of<HasChangesMaskTag, T>, std::is_base_of<IsUpdateFieldHolderTag, T>>{});
638 template<
typename T, std::
size_t Size, u
int32 Bit,
int32 FirstElementBit>
641 template<
typename T, std::
size_t Size, u
int32 Bit,
int32 FirstElementBit>
645 field.
_values[i].ClearChangesMask();
648 template<
typename T,
int32 BlockBit, u
int32 Bit>
655 template<
typename T,
int32 BlockBit, u
int32 Bit>
658 template<
typename T,
int32 BlockBit, u
int32 Bit>
662 field.
_values[i].ClearChangesMask();
665 template<
typename T,
int32 BlockBit, u
int32 Bit>
671 template<
typename T,
int32 BlockBit, u
int32 Bit>
674 template<
typename T,
int32 BlockBit, u
int32 Bit>
678 field.
_value->ClearChangesMask();
691 template<
typename Derived,
typename T,
int32 BlockBit, u
int32 Bit>
695 return { (
static_cast<Derived*
>(
_owner)->*field)._value };
698 template<
typename Derived,
typename T,
int32 BlockBit, u
int32 Bit>
702 (
static_cast<Derived*
>(
_owner)->*field)._value.ClearChangesMask();
723 template<
typename F,
bool PublicSet>
726 template<
typename F,
bool PublicSet>
729 template<std::
size_t Bits>
737 operator T
const& ()
const
754 template<
typename T,
int32 BlockBit, u
int32 Bit>
764 template<
typename T, std::
size_t Size>
767 template<
typename F,
bool PublicSet>
770 template<
typename F,
bool PublicSet>
773 template<std::
size_t Bits>
789 static constexpr std::size_t
size()
813 return sizeof(
typename T::value_type);
816 template<
typename T, std::
size_t Size, u
int32 Bit,
int32 FirstElementBit>
827 template<
typename F,
bool PublicSet>
830 template<
typename F,
bool PublicSet>
833 template<std::
size_t Bits>
844 typename std::vector<T>::const_iterator
begin()
const
849 typename std::vector<T>::const_iterator
end()
const
878 template<
typename Pred>
881 auto itr = std::find_if(
_values.begin(),
_values.end(), std::ref(pred));
890 return (
_updateMask[index / 32] & (1 << (index % 32))) != 0;
926 template<
typename T,
int32 BlockBit, u
int32 Bit>
934 template<
typename F,
bool PublicSet>
937 template<
typename F,
bool PublicSet>
940 template<std::
size_t Bits>
948 using IsLarge = std::integral_constant<bool,
sizeof(
void*) * 3 <
sizeof(T)>;
961 operator T
const& ()
const
987 _value = std::make_unique<T>();
998 template<
typename T,
int32 BlockBit, u
int32 Bit>
1003 template<
typename T>
std::optional< T > Optional
Optional helper class to wrap optional values within.
std::vector< T >::const_iterator begin() const
void ClearChanged(std::size_t index)
std::vector< T >::const_iterator end() const
bool HasChanged(uint32 index) const
void MarkChanged(std::size_t index)
T const & operator[](std::size_t index) const
void WriteUpdateMask(ByteBuffer &data, int32 bitsForSize=32) const
std::vector< uint32 > _updateMask
int32 FindIndexIf(Pred pred) const
int32 FindIndex(T const &value) const
static void ClearChangesMask(OptionalUpdateField< T, BlockBit, Bit > &, std::false_type)
MutableFieldReference< T, false > ModifyValue(UpdateField< T, BlockBit, Bit >(Derived::*field))
static void ClearChangesMask(OptionalUpdateField< T, BlockBit, Bit > &field)
MutableFieldReference< T, false > ModifyValue(DynamicUpdateField< T, BlockBit, Bit >(Derived::*field))
void ClearChanged(UpdateField< T, BlockBit, Bit >(Derived::*))
static void ClearChangesMask(UpdateField< T, BlockBit, Bit > &field, std::true_type)
MutableFieldReference< T, false > ModifyValue(UpdateFieldArray< T, Size, Bit, FirstElementBit >(Derived::*field), uint32 index)
static void ClearChangesMask(UpdateFieldArray< T, Size, Bit, FirstElementBit > &field, std::true_type)
static void ClearChangesMask(DynamicUpdateField< T, BlockBit, Bit > &, std::false_type)
void ClearChanged(DynamicUpdateField< T, BlockBit, Bit >(Derived::*field), uint32 index)
static void ClearChangesMask(DynamicUpdateField< T, BlockBit, Bit > &field, std::true_type)
MutableFieldReference< T, false > ModifyValue(DynamicUpdateField< T, BlockBit, Bit >(Derived::*field), uint32 index)
static void ClearChangesMask(UpdateFieldArray< T, Size, Bit, FirstElementBit > &field)
static void ClearChangesMask(UpdateFieldArray< T, Size, Bit, FirstElementBit > &, std::false_type)
static void ClearChangesMask(UpdateField< T, BlockBit, Bit > &field)
void ClearChanged(OptionalUpdateField< T, BlockBit, Bit >(Derived::*))
void MarkChanged(OptionalUpdateField< T, BlockBit, Bit >(Derived::*))
Mask const & GetChangesMask() const
void MarkChanged(DynamicUpdateField< T, BlockBit, Bit >(Derived::*), uint32)
void ClearChanged(UpdateFieldArray< T, Size, Bit, FirstElementBit >(Derived::*), uint32 index)
MutableFieldReference< T, false > ModifyValue(OptionalUpdateField< T, BlockBit, Bit >(Derived::*field))
static void ClearChangesMask(DynamicUpdateField< T, BlockBit, Bit > &field)
void MarkChanged(UpdateFieldArray< T, Size, Bit, FirstElementBit >(Derived::*), uint32 index)
static void ClearChangesMask(OptionalUpdateField< T, BlockBit, Bit > &field, std::true_type)
void MarkChanged(UpdateField< T, BlockBit, Bit >(Derived::*))
static void ClearChangesMask(UpdateField< T, BlockBit, Bit > &, std::false_type)
T const & operator*() const
std::integral_constant< bool, sizeof(void *) *3< sizeof(T)> IsLarge
void ConstructValue(std::false_type)
std::conditional_t< IsLarge::value, std::unique_ptr< T >, Optional< T > > StorageType
T const * operator->() const
void ConstructValue(std::true_type)
~OptionalUpdateFieldBase()
static constexpr std::size_t size()
T const & operator[](std::size_t index) const
T const & operator*() const
T const * operator->() const
MutableFieldReference< T, false > ModifyValue(UpdateField< T, BlockBit, Bit >(Derived::*field))
void ClearChangesMask(UpdateField< T, BlockBit, Bit >(Derived::*field))
UpdateMask< NUM_CLIENT_OBJECT_TYPES > _changesMask
bool HasChanged(uint32 index) const
UpdateFieldHolder(Object *owner)
uint32 GetChangedObjectTypeMask() const
constexpr uint32 GetBlock(uint32 index) const
constexpr void Reset(uint32 index)
constexpr void Set(uint32 index)
bool Size(ContainerUnorderedMap< TypeList< H, T >, KEY_TYPE > const &elements, std::size_t *size, SPECIFIC_TYPE *obj)
constexpr std::size_t size()
void WriteCompleteDynamicFieldUpdateMask(std::size_t size, ByteBuffer &data, int32 bitsForSize=32)
void WriteDynamicFieldUpdateMask(std::size_t size, std::vector< uint32 > const &updateMask, ByteBuffer &data, int32 bitsForSize=32)
constexpr std::size_t size_of_value_type()
DEFINE_ENUM_FLAG(UpdateFieldFlag)
constexpr std::size_t GetBlockIndex(std::size_t bit)
constexpr uint32 GetBlockFlag(std::size_t bit)
DynamicUpdateFieldSetter(std::vector< T > &values, std::vector< uint32 > &updateMask)
friend void ClearDynamicUpdateFieldValues(DynamicUpdateFieldSetter< F > &setter)
friend DynamicUpdateFieldSetter< F >::insert_result InsertDynamicUpdateFieldValue(DynamicUpdateFieldSetter< F > &setter, uint32 index)
friend DynamicUpdateFieldSetter< F >::insert_result AddDynamicUpdateFieldValue(DynamicUpdateFieldSetter< F > &setter)
friend void RemoveDynamicUpdateFieldValue(DynamicUpdateFieldSetter< F > &setter, uint32 index)
std::conditional_t< std::is_base_of_v< HasChangesMaskTag, T >, MutableFieldReference< T, true >, T & > insert_result
void RemoveValue(std::size_t index)
std::vector< T > & _values
static void MarkNewValue(T &, std::false_type)
static void MarkNewValue(T &value, std::true_type)
void MarkChanged(std::size_t index)
std::vector< uint32 > & _updateMask
insert_result InsertValue(std::size_t index)
std::enable_if_t<!std::is_base_of_v< HasChangesMaskTag, U > &&!std::is_array_v< V >, std::conditional_t< PublicSet, UpdateFieldPublicSetter< V >, UpdateFieldSetter< V > > > ModifyValue(V(T::*field))
std::enable_if_t< std::is_base_of_v< HasChangesMaskTag, U >, std::conditional_t< std::is_base_of_v< IsUpdateFieldStructureTag, V >, MutableFieldReference< V, PublicSet >, std::conditional_t< std::is_base_of_v< IsUpdateFieldHolderTag, V >, MutableNestedFieldReference< V, PublicSet >, std::conditional_t< PublicSet, UpdateFieldPublicSetter< V >, UpdateFieldSetter< V > > > > > ModifyValue(OptionalUpdateField< V, BlockBit, Bit >(T::*field), uint32)
std::enable_if_t< std::is_base_of_v< HasChangesMaskTag, U >, std::conditional_t< std::is_base_of_v< IsUpdateFieldStructureTag, V >, MutableFieldReference< V, PublicSet >, std::conditional_t< std::is_base_of_v< IsUpdateFieldHolderTag, V >, MutableNestedFieldReference< V, PublicSet >, std::conditional_t< PublicSet, UpdateFieldPublicSetter< V >, UpdateFieldSetter< V > > > > > ModifyValue(UpdateFieldArray< V, Size, Bit, FirstElementBit >(T::*field), uint32 index)
std::enable_if_t< std::is_base_of_v< HasChangesMaskTag, U >, std::conditional_t< std::is_base_of_v< IsUpdateFieldStructureTag, V >, MutableFieldReference< V, PublicSet >, std::conditional_t< std::is_base_of_v< IsUpdateFieldHolderTag, V >, MutableNestedFieldReference< V, PublicSet >, std::conditional_t< PublicSet, UpdateFieldPublicSetter< V >, UpdateFieldSetter< V > > > > > ModifyValue(DynamicUpdateField< V, BlockBit, Bit >(T::*field), uint32 index)
std::enable_if_t< std::is_base_of_v< HasChangesMaskTag, U >, DynamicUpdateFieldSetter< V > > ModifyValue(DynamicUpdateField< V, BlockBit, Bit >(T::*field))
MutableFieldReference(T &value)
std::enable_if_t< std::is_base_of_v< HasChangesMaskTag, U >, std::conditional_t< std::is_base_of_v< IsUpdateFieldStructureTag, V >, MutableFieldReference< V, PublicSet >, std::conditional_t< std::is_base_of_v< IsUpdateFieldHolderTag, V >, MutableNestedFieldReference< V, PublicSet >, std::conditional_t< PublicSet, UpdateFieldPublicSetter< V >, UpdateFieldSetter< V > > > > > ModifyValue(UpdateField< V, BlockBit, Bit >(T::*field))
std::enable_if_t<!std::is_base_of_v< HasChangesMaskTag, U >, std::conditional_t< PublicSet, UpdateFieldPublicSetter< V >, UpdateFieldSetter< V > > > ModifyValue(V(T::*field)[Size], uint32 index)
std::enable_if_t< std::is_base_of_v< HasChangesMaskTag, U >, OptionalUpdateFieldSetter< V > > ModifyValue(OptionalUpdateField< V, BlockBit, Bit >(T::*field))
typename T::value_type value_type
std::enable_if_t< std::is_base_of_v< DynamicUpdateFieldBase< value_type >, U >, std::conditional_t< std::is_base_of_v< IsUpdateFieldStructureTag, value_type >, MutableFieldReference< value_type, PublicSet >, std::conditional_t< std::is_base_of_v< IsUpdateFieldHolderTag, value_type >, MutableNestedFieldReference< value_type, PublicSet >, std::conditional_t< PublicSet, UpdateFieldPublicSetter< value_type >, UpdateFieldSetter< value_type > > > > > ModifyValue(uint32 index)
std::enable_if_t< std::is_base_of_v< UpdateFieldBase< value_type >, U >, std::conditional_t< std::is_base_of_v< IsUpdateFieldStructureTag, value_type >, MutableFieldReference< value_type, PublicSet >, std::conditional_t< std::is_base_of_v< IsUpdateFieldHolderTag, value_type >, MutableNestedFieldReference< value_type, PublicSet >, std::conditional_t< PublicSet, UpdateFieldPublicSetter< value_type >, UpdateFieldSetter< value_type > > > > > ModifyValue()
MutableNestedFieldReference(T &value)
std::enable_if_t< std::is_base_of_v< OptionalUpdateFieldBase< value_type >, U >, std::conditional_t< std::is_base_of_v< IsUpdateFieldStructureTag, value_type >, MutableFieldReference< value_type, PublicSet >, std::conditional_t< std::is_base_of_v< IsUpdateFieldHolderTag, value_type >, MutableNestedFieldReference< value_type, PublicSet >, std::conditional_t< PublicSet, UpdateFieldPublicSetter< value_type >, UpdateFieldSetter< value_type > > > > > ModifyValue(uint32)
std::enable_if_t< std::is_base_of_v< UpdateFieldArrayBaseWithoutSize< value_type >, U >, std::conditional_t< std::is_base_of_v< IsUpdateFieldStructureTag, value_type >, MutableFieldReference< value_type, PublicSet >, std::conditional_t< std::is_base_of_v< IsUpdateFieldHolderTag, value_type >, MutableNestedFieldReference< value_type, PublicSet >, std::conditional_t< PublicSet, UpdateFieldPublicSetter< value_type >, UpdateFieldSetter< value_type > > > > > ModifyValue(uint32 index)
std::enable_if_t< std::is_base_of_v< DynamicUpdateFieldBase< value_type >, U >, DynamicUpdateFieldSetter< value_type > > ModifyValue()
std::enable_if_t< std::is_base_of_v< OptionalUpdateFieldBase< value_type >, U >, OptionalUpdateFieldSetter< value_type > > ModifyValue()
OptionalUpdateFieldSetter(OptionalUpdateFieldBase< T > &field)
OptionalUpdateFieldBase< T > & _field
friend void RemoveOptionalUpdateFieldValue(OptionalUpdateFieldSetter< F > &setter)
UpdateFieldPublicSetter(T &value)
friend bool SetUpdateFieldValue(UpdateFieldSetter< F > &setter, typename UpdateFieldSetter< F >::value_type &&value)
UpdateFieldSetter(T &value)