22 class SB_CLASS
object :
public object_owner,
public std::enable_shared_from_this<object>,
public boost::noncopyable
24 REGISTER_REFLECTION(
object)
32 [[nodiscard]]
auto casted_shared_from_this() -> std::shared_ptr<T>;
44 [[nodiscard]] auto try_convert_object() const noexcept -> const T*;
46 auto destroy() ->
void;
48 [[nodiscard]] auto get_object_type() const -> rttr::type;
50 [[nodiscard]] auto get_owner_object() const ->
object*;
51 [[nodiscard]] auto get_on_destroy() -> MulticastDelegate<
object*>&;
53 [[nodiscard]] auto get_flags() const -> object_flags;
54 [[nodiscard]] auto set_flags(object_flags flagsToSet) ->
void;
55 [[nodiscard]] auto clear_flags(object_flags flagsToClear) ->
void;
56 [[nodiscard]] auto has_flag(object_flags flagsToCheck) ->
bool;
58 template <class archive_class>
59 void serialize(archive_class& archive, const
unsigned int fileVersion)
61 const rttr::type type = get_object_type();
62 BOOST_ASSERT(type.is_valid());
64 for (rttr::property
property : type.get_properties())
67 std::string propertyName =
property.get_name().data();
68 std::replace(propertyName.begin(), propertyName.end(),
' ',
'_');
70 if (
typename archive_class::is_saving())
72 rttr::variant propertyVariant =
property.get_value(rttr::instance(
this));
73 archive & boost::serialization::make_nvp(propertyName.c_str(), propertyVariant);
75 else if (
typename archive_class::is_loading())
77 rttr::variant loadedVariant =
property.get_value(rttr::instance(
this));
78 BOOST_VERIFY(loadedVariant.is_valid());
79 BOOST_VERIFY(loadedVariant.get_type().is_valid());
80 archive & boost::serialization::make_nvp(propertyName.c_str(), loadedVariant);
82 if (
property.get_type() == rttr::type::get<std::string_view>() &&
83 loadedVariant.get_type() == rttr::type::get<std::string>())
85 std::string loadedString = loadedVariant.convert<std::string>();
86 std::string_view loadedStringView = loadedString;
88 if (has_flag(object_flag_loading))
90 property.set_value(rttr::instance(
this), loadedStringView);
95 if (has_flag(object_flag_loading))
97 loadedVariant.convert(
property.get_type());
98 BOOST_ASSERT(loadedVariant.get_type() ==
property.get_type());
99 property.set_value(rttr::instance(
this), loadedVariant);
110 auto cache_type() -> void;
113 object_flags m_flags = object_flag_none;
119 mutable std::optional<rttr::type> m_type = std::nullopt;
121 MulticastDelegate<object*> m_onDestroyEvent;