Skip to content

Commit

Permalink
meta: standalone meta_data/meta_func
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Dec 17, 2024
1 parent b5b3106 commit da8e4bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
3 changes: 1 addition & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ TODO:
* cleanup common view from tricks to handle single swap-only and in-place, if constexpr branches
* entity based component_traits
* review cmake warning about FetchContent_Populate (need .28 and EXCLUDE_FROM_ALL for FetchContent)
* after removing meta prop vectors, copy meta objects in their handles directly
* suppress -Wself-move on CI with g++13
* view specializations for multi, single and filtered elements
* organizer support to groups
* meta range: move id to meta objects and return plain types (?), then remove id from meta base and meta ctor too
* don't pass reactive storage by default to callback
* runtime types support for meta for types that aren't backed by C++ types
* dtor, traits and custom should be part of meta descriptor (update meta_factory tests then)
* allow attaching const values of non-Type type to meta types
* built-in no-pagination storage - no_pagination page size as limits::max
* sparse_set shrink_to_fit argument for sparse array shrink policy (none, empty, deep, whatever)
* any cdynamic to support const ownership construction
* track meta context on meta elements
* safer meta_data/meta_func (no blind indirections)
52 changes: 26 additions & 26 deletions src/entt/meta/meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,32 +833,32 @@ struct meta_data {
* @param area The context from which to search for meta types.
* @param curr The underlying node with which to construct the instance.
*/
meta_data(const meta_ctx &area, const internal::meta_data_node &curr) noexcept
: node{&curr},
meta_data(const meta_ctx &area, internal::meta_data_node curr) noexcept
: node{std::move(curr)},
ctx{&area} {}

/**
* @brief Returns the number of setters available.
* @return The number of setters available.
*/
[[nodiscard]] size_type arity() const noexcept {
return node->arity;
return node.arity;
}

/**
* @brief Indicates whether a data member is constant or not.
* @return True if the data member is constant, false otherwise.
*/
[[nodiscard]] bool is_const() const noexcept {
return static_cast<bool>(node->traits & internal::meta_traits::is_const);
return static_cast<bool>(node.traits & internal::meta_traits::is_const);
}

/**
* @brief Indicates whether a data member is static or not.
* @return True if the data member is static, false otherwise.
*/
[[nodiscard]] bool is_static() const noexcept {
return static_cast<bool>(node->traits & internal::meta_traits::is_static);
return static_cast<bool>(node.traits & internal::meta_traits::is_static);
}

/*! @copydoc meta_any::type */
Expand All @@ -874,7 +874,7 @@ struct meta_data {
template<typename Type>
// NOLINTNEXTLINE(modernize-use-nodiscard)
bool set(meta_handle instance, Type &&value) const {
return node->set && node->set(meta_handle{*ctx, std::move(instance)}, meta_any{*ctx, std::forward<Type>(value)});
return node.set && node.set(meta_handle{*ctx, std::move(instance)}, meta_any{*ctx, std::forward<Type>(value)});
}

/**
Expand All @@ -883,7 +883,7 @@ struct meta_data {
* @return A wrapper containing the value of the underlying variable.
*/
[[nodiscard]] meta_any get(meta_handle instance) const {
return node->get(*ctx, meta_handle{*ctx, std::move(instance)});
return node.get(*ctx, meta_handle{*ctx, std::move(instance)});
}

/**
Expand All @@ -900,15 +900,15 @@ struct meta_data {
*/
template<typename Type>
[[nodiscard]] Type traits() const noexcept {
return internal::meta_to_user_traits<Type>(node->traits);
return internal::meta_to_user_traits<Type>(node.traits);
}

/**
* @brief Returns user defined data for a given meta object.
* @return User defined arbitrary data.
*/
[[nodiscard]] meta_custom custom() const noexcept {
return {node->custom};
return {node.custom};
}

/**
Expand All @@ -925,11 +925,11 @@ struct meta_data {
* @return True if the objects refer to the same type, false otherwise.
*/
[[nodiscard]] bool operator==(const meta_data &other) const noexcept {
return (ctx == other.ctx && node == other.node);
return (ctx == other.ctx) && (node.set == other.node.set) && (node.get == other.node.get);
}

private:
const internal::meta_data_node *node{};
internal::meta_data_node node{};
const meta_ctx *ctx{};
};

Expand All @@ -956,32 +956,32 @@ struct meta_func {
* @param area The context from which to search for meta types.
* @param curr The underlying node with which to construct the instance.
*/
meta_func(const meta_ctx &area, const internal::meta_func_node &curr) noexcept
: node{&curr},
meta_func(const meta_ctx &area, internal::meta_func_node curr) noexcept
: node{std::move(curr)},
ctx{&area} {}

/**
* @brief Returns the number of arguments accepted by a member function.
* @return The number of arguments accepted by the member function.
*/
[[nodiscard]] size_type arity() const noexcept {
return node->arity;
return node.arity;
}

/**
* @brief Indicates whether a member function is constant or not.
* @return True if the member function is constant, false otherwise.
*/
[[nodiscard]] bool is_const() const noexcept {
return static_cast<bool>(node->traits & internal::meta_traits::is_const);
return static_cast<bool>(node.traits & internal::meta_traits::is_const);
}

/**
* @brief Indicates whether a member function is static or not.
* @return True if the member function is static, false otherwise.
*/
[[nodiscard]] bool is_static() const noexcept {
return static_cast<bool>(node->traits & internal::meta_traits::is_static);
return static_cast<bool>(node.traits & internal::meta_traits::is_static);
}

/**
Expand All @@ -1005,7 +1005,7 @@ struct meta_func {
* @return A wrapper containing the returned value, if any.
*/
meta_any invoke(meta_handle instance, meta_any *const args, const size_type sz) const {
return sz == arity() ? node->invoke(*ctx, meta_handle{*ctx, std::move(instance)}, args) : meta_any{meta_ctx_arg, *ctx};
return sz == arity() ? node.invoke(*ctx, meta_handle{*ctx, std::move(instance)}, args) : meta_any{meta_ctx_arg, *ctx};
}

/**
Expand All @@ -1025,20 +1025,20 @@ struct meta_func {
/*! @copydoc meta_data::traits */
template<typename Type>
[[nodiscard]] Type traits() const noexcept {
return internal::meta_to_user_traits<Type>(node->traits);
return internal::meta_to_user_traits<Type>(node.traits);
}

/*! @copydoc meta_data::custom */
[[nodiscard]] meta_custom custom() const noexcept {
return {node->custom};
return {node.custom};
}

/**
* @brief Returns the next overload of a given function, if any.
* @return The next overload of the given function, if any.
*/
[[nodiscard]] meta_func next() const {
return node->next ? meta_func{*ctx, *node->next} : meta_func{};
return node.next ? meta_func{*ctx, *node.next} : meta_func{};
}

/**
Expand All @@ -1051,11 +1051,11 @@ struct meta_func {

/*! @copydoc meta_data::operator== */
[[nodiscard]] bool operator==(const meta_func &other) const noexcept {
return (ctx == other.ctx && node == other.node);
return (ctx == other.ctx) && (node.invoke == other.node.invoke);
}

private:
const internal::meta_func_node *node{};
internal::meta_func_node node{};
const meta_ctx *ctx{};
};

Expand Down Expand Up @@ -1582,19 +1582,19 @@ inline bool meta_any::assign(meta_any &&other) {
}

[[nodiscard]] inline meta_type meta_data::type() const noexcept {
return meta_type{*ctx, node->type(internal::meta_context::from(*ctx))};
return meta_type{*ctx, node.type(internal::meta_context::from(*ctx))};
}

[[nodiscard]] inline meta_type meta_data::arg(const size_type index) const noexcept {
return index < arity() ? node->arg(*ctx, index) : meta_type{};
return index < arity() ? node.arg(*ctx, index) : meta_type{};
}

[[nodiscard]] inline meta_type meta_func::ret() const noexcept {
return meta_type{*ctx, node->ret(internal::meta_context::from(*ctx))};
return meta_type{*ctx, node.ret(internal::meta_context::from(*ctx))};
}

[[nodiscard]] inline meta_type meta_func::arg(const size_type index) const noexcept {
return index < arity() ? node->arg(*ctx, index) : meta_type{};
return index < arity() ? node.arg(*ctx, index) : meta_type{};
}

/*! @cond TURN_OFF_DOXYGEN */
Expand Down

0 comments on commit da8e4bf

Please sign in to comment.