emitter: : (almost) transparent dll/.so support with ENTT_API
This commit is contained in:
10
TODO
10
TODO
@@ -43,14 +43,18 @@
|
||||
|
||||
* Mission: get rid of named types
|
||||
- make it possible to use custom generators (eg for plugins)
|
||||
- registry::assure -> pool_type<T> &
|
||||
- registry::group improve, reduce code
|
||||
- Make the following parts work across boundaries (define proper macros):
|
||||
* dispatcher
|
||||
* emitter
|
||||
* registry
|
||||
* meta
|
||||
* monostate
|
||||
* locator
|
||||
- registry::assure -> pool_type<T> &
|
||||
- registry::group improve, reduce code
|
||||
- families should be defined as out-of-class to guarantee the same identifiers for the same types
|
||||
- Make the following parts work across boundaries:
|
||||
* registry
|
||||
* monostate
|
||||
* locator
|
||||
- update doc: family, dispatcher, emitter, registry, meta, across boundaries
|
||||
- update tests
|
||||
|
||||
@@ -40,8 +40,10 @@ namespace entt {
|
||||
*/
|
||||
template<typename Derived>
|
||||
class emitter {
|
||||
struct ENTT_API emitter_event_family;
|
||||
|
||||
template<typename Type>
|
||||
using event_family = family<Type, struct ENTT_API internal_emitter_event_family>;
|
||||
using event_family = family<Type, emitter_event_family>;
|
||||
|
||||
struct basic_pool {
|
||||
virtual ~basic_pool() = default;
|
||||
|
||||
@@ -45,7 +45,7 @@ endif()
|
||||
|
||||
if(BUILD_LIB)
|
||||
SETUP_AND_ADD_LIB_TEST(dispatcher)
|
||||
# SETUP_AND_ADD_LIB_TEST(emitter)
|
||||
SETUP_AND_ADD_LIB_TEST(emitter)
|
||||
SETUP_AND_ADD_LIB_TEST(meta)
|
||||
# SETUP_AND_ADD_LIB_TEST(registry)
|
||||
endif()
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
#define ENTT_API_EXPORT
|
||||
|
||||
#include <entt/lib/attribute.h>
|
||||
#include <entt/signal/emitter.hpp>
|
||||
#include "types.h"
|
||||
|
||||
#ifndef LIB_EXPORT
|
||||
#if defined _WIN32 || defined __CYGWIN__
|
||||
#define LIB_EXPORT __declspec(dllexport)
|
||||
#elif defined __GNUC__
|
||||
#define LIB_EXPORT __attribute__((visibility("default")))
|
||||
#else
|
||||
#define LIB_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
template struct entt::family<event, test_emitter::emitter_event_family>;
|
||||
|
||||
LIB_EXPORT void emit_event(int value, test_emitter &emitter) {
|
||||
emitter.publish<event>(value);
|
||||
ENTT_EXPORT void emit(int value, test_emitter &emitter) {
|
||||
emitter.publish<message>(value);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
#define ENTT_API_IMPORT
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/lib/attribute.h>
|
||||
#include <entt/signal/emitter.hpp>
|
||||
#include "types.h"
|
||||
|
||||
extern void emit_event(int, test_emitter &);
|
||||
ENTT_API void emit(int, test_emitter &);
|
||||
|
||||
TEST(Lib, Emitter) {
|
||||
test_emitter emitter;
|
||||
int value{};
|
||||
|
||||
emitter.once<int>([](int, test_emitter &) { FAIL(); });
|
||||
emitter.once<event>([&](event event, test_emitter &) {
|
||||
ASSERT_EQ(event.payload, 42);
|
||||
value = event.payload;
|
||||
emitter.once<event>([](event, test_emitter &) { FAIL(); });
|
||||
emitter.once<message>([&](message msg, test_emitter &) {
|
||||
ASSERT_EQ(msg.payload, 42);
|
||||
value = msg.payload;
|
||||
});
|
||||
|
||||
emit_event(42, emitter);
|
||||
emit_event(3, emitter);
|
||||
emit(42, emitter);
|
||||
emit(3, emitter);
|
||||
|
||||
ASSERT_EQ(value, 42);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
#include <entt/core/type_traits.hpp>
|
||||
#ifndef ENTT_LIB_EMITTER_TYPES_H
|
||||
#define ENTT_LIB_EMITTER_TYPES_H
|
||||
|
||||
#include <entt/lib/attribute.h>
|
||||
#include <entt/signal/emitter.hpp>
|
||||
|
||||
struct test_emitter
|
||||
struct ENTT_API test_emitter
|
||||
: entt::emitter<test_emitter>
|
||||
{};
|
||||
|
||||
ENTT_NAMED_STRUCT(event, {
|
||||
struct ENTT_API event {};
|
||||
|
||||
struct ENTT_API message {
|
||||
int payload;
|
||||
});
|
||||
};
|
||||
|
||||
#endif // ENTT_LIB_EMITTER_TYPES_H
|
||||
|
||||
Reference in New Issue
Block a user