meta: separate resolve.hpp file

This commit is contained in:
Michele Caini
2020-04-22 20:05:24 +02:00
parent b35521dfcb
commit 9a67652c0c
7 changed files with 74 additions and 54 deletions

View File

@@ -22,6 +22,7 @@
#include "locator/locator.hpp"
#include "meta/factory.hpp"
#include "meta/meta.hpp"
#include "meta/resolve.hpp"
#include "meta/policy.hpp"
#include "process/process.hpp"
#include "process/scheduler.hpp"

View File

@@ -834,60 +834,6 @@ inline meta_factory<Type> meta() ENTT_NOEXCEPT {
}
/**
* @brief Returns the meta type associated with a given type.
* @tparam Type Type to use to search for a meta type.
* @return The meta type associated with the given type, if any.
*/
template<typename Type>
inline meta_type resolve() ENTT_NOEXCEPT {
return internal::meta_info<Type>::resolve();
}
/**
* @brief Returns the first meta type that satisfies specific criteria, if any.
* @tparam Func Type of the unary predicate to use to test the meta types.
* @param func Unary predicate which returns true for the required element.
* @return The first meta type satisfying the condition, if any.
*/
template<typename Func>
inline meta_type resolve_if(Func func) ENTT_NOEXCEPT {
return internal::find_if([&func](const auto *curr) {
return func(meta_type{curr});
}, *internal::meta_context::global);
}
/**
* @brief Returns the meta type associated with a given identifier, if any.
* @param id Unique identifier.
* @return The meta type associated with the given identifier, if any.
*/
inline meta_type resolve_id(const id_type id) ENTT_NOEXCEPT {
return resolve_if([id](const auto type) { return type.id() == id; });
}
/*! @copydoc resolve_id */
[[deprecated("use entt::resolve_id instead")]]
inline meta_type resolve(const id_type id) ENTT_NOEXCEPT {
return resolve_id(id);
}
/**
* @brief Iterates all the reflected types.
* @tparam Op Type of the function object to invoke.
* @param op A valid function object.
*/
template<typename Op>
inline std::enable_if_t<std::is_invocable_v<Op, meta_type>, void>
resolve(Op op) {
internal::visit<meta_type>(op, *internal::meta_context::global);
}
}

69
src/entt/meta/resolve.hpp Normal file
View File

@@ -0,0 +1,69 @@
#ifndef ENTT_META_RESOLVE_HPP
#define ENTT_META_RESOLVE_HPP
#include <type_traits>
#include "meta.hpp"
namespace entt {
/**
* @brief Returns the meta type associated with a given type.
* @tparam Type Type to use to search for a meta type.
* @return The meta type associated with the given type, if any.
*/
template<typename Type>
inline meta_type resolve() ENTT_NOEXCEPT {
return internal::meta_info<Type>::resolve();
}
/**
* @brief Returns the first meta type that satisfies specific criteria, if any.
* @tparam Func Type of the unary predicate to use to test the meta types.
* @param func Unary predicate which returns true for the required element.
* @return The first meta type satisfying the condition, if any.
*/
template<typename Func>
inline meta_type resolve_if(Func func) ENTT_NOEXCEPT {
return internal::find_if([&func](const auto *curr) {
return func(meta_type{curr});
}, *internal::meta_context::global);
}
/**
* @brief Returns the meta type associated with a given identifier, if any.
* @param id Unique identifier.
* @return The meta type associated with the given identifier, if any.
*/
inline meta_type resolve_id(const id_type id) ENTT_NOEXCEPT {
return resolve_if([id](const auto type) { return type.id() == id; });
}
/*! @copydoc resolve_id */
[[deprecated("use entt::resolve_id instead")]]
inline meta_type resolve(const id_type id) ENTT_NOEXCEPT {
return resolve_id(id);
}
/**
* @brief Iterates all the reflected types.
* @tparam Op Type of the function object to invoke.
* @param op A valid function object.
*/
template<typename Op>
inline std::enable_if_t<std::is_invocable_v<Op, meta_type>, void>
resolve(Op op) {
internal::visit<meta_type>(op, *internal::meta_context::global);
}
}
#endif

View File

@@ -7,6 +7,7 @@
#include <entt/core/utility.hpp>
#include <entt/meta/factory.hpp>
#include <entt/meta/meta.hpp>
#include <entt/meta/resolve.hpp>
template<typename Type>
void set(Type &prop, Type value) {

View File

@@ -2,6 +2,7 @@
#include <entt/core/attribute.h>
#include <entt/meta/factory.hpp>
#include <entt/meta/meta.hpp>
#include <entt/meta/resolve.hpp>
#include "types.h"
ENTT_API void set_up();

View File

@@ -4,6 +4,7 @@
#include <gtest/gtest.h>
#include <entt/meta/factory.hpp>
#include <entt/meta/meta.hpp>
#include <entt/meta/resolve.hpp>
#include "types.h"
TEST(Lib, Meta) {

View File

@@ -4,6 +4,7 @@
#include <gtest/gtest.h>
#include <entt/meta/factory.hpp>
#include <entt/meta/meta.hpp>
#include <entt/meta/resolve.hpp>
#include "types.h"
TEST(Lib, Meta) {