Commit 3e5095d8 authored by Ronan's avatar Ronan

feat(Object): create MetaObjectSignalInfo at compil time

parent 9e4513f7
......@@ -278,6 +278,13 @@ namespace Private {
#define L_DECL_C_STRUCT(STRUCT) typedef struct _ ## STRUCT STRUCT;
#define L_DECL_C_STRUCT_PREFIX_LESS(STRUCT) typedef struct STRUCT STRUCT;
// -----------------------------------------------------------------------------
// Generic helpers.
// -----------------------------------------------------------------------------
// See: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4121.pdf
template<int N> using StringLiteral = const char [N];
#endif // ifdef __cplusplus
LINPHONE_END_NAMESPACE
......
......@@ -31,10 +31,8 @@
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
// Internal, do not use directly.
// Internal macros, do not use directly.
// -----------------------------------------------------------------------------
#define L_INTERNAL_SIGNAL_CONCAT_TYPE_ARG(TYPE, PARAM) TYPE PARAM
......@@ -57,23 +55,8 @@ LINPHONE_BEGIN_NAMESPACE
#define L_INTERNAL_META_RETURN(VALUE) -> decltype(VALUE) { return VALUE; }
namespace Private {
template<int N = 255>
struct MetaObjectCounter : MetaObjectCounter<N - 1> {
static constexpr int value = N;
static constexpr MetaObjectCounter<N - 1> prev () {
return {};
}
};
template<>
struct MetaObjectCounter<0> {
static constexpr int value = 0;
};
};
// -----------------------------------------------------------------------------
// Public API.
// Public macros API.
// -----------------------------------------------------------------------------
// Must be used in Object or ObjectPrivate.
......@@ -111,10 +94,49 @@ namespace Private {
) L_INTERNAL_META_RETURN( \
std::tuple_cat( \
lMetaSignals(counter.prev(), context), \
std::make_tuple('a') \
std::make_tuple(LinphonePrivate::Private::makeMetaObjectSignalInfo( \
L_CALL(L_RESOLVE_OVERLOAD, TYPES)(&lType::NAME), \
#NAME \
)) \
) \
)
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
namespace Private {
// Compilation counter.
template<int N = 255>
struct MetaObjectCounter : MetaObjectCounter<N - 1> {
static constexpr int value = N;
static constexpr MetaObjectCounter<N - 1> prev () {
return {};
}
};
template<>
struct MetaObjectCounter<0> {
static constexpr int value = 0;
};
/*
* Meta data of one object's signal.
* Useful to get arguments number, params and signal name.
*/
template<typename Signal, int NameLength>
struct MetaObjectSignalInfo {
Signal signal;
StringLiteral<NameLength> name;
static constexpr int argumentsNumber = FunctionPointer<Signal>::ArgumentsNumber;
};
template<typename Signal, int NameLength>
constexpr MetaObjectSignalInfo<Signal, NameLength> makeMetaObjectSignalInfo (Signal signal, StringLiteral<NameLength> &name) {
return { signal, *name };
}
};
/*
* Main Object of Linphone. Can be shared but is not Clonable.
* Supports properties and shared from this.
......@@ -190,8 +212,8 @@ private:
L_DISABLE_COPY(Object);
};
#undef L_INTERNAL_CHECK_CONNECT_TYPES
LINPHONE_END_NAMESPACE
#undef L_INTERNAL_CHECK_CONNECT_TYPES
#endif // ifndef _L_OBJECT_H_
......@@ -30,8 +30,8 @@ using namespace LinphonePrivate;
// -----------------------------------------------------------------------------
#define CHECK_SIGNAL_INDEX(NAME, EXPECTED_VALUE) \
static_assert(L_INTERNAL_SIGNAL_INDEX(NAME, __LINE__) == EXPECTED_VALUE, "Bad signal index.");
#define CHECK_SIGNAL(NAME, INDEX) \
static_assert(L_INTERNAL_SIGNAL_INDEX(NAME, __LINE__) == INDEX, "Bad signal index.");
class TestObjectPrivate : public ObjectPrivate {
public:
......@@ -43,8 +43,8 @@ class TestObject : public Object {
public:
TestObject () : Object(*new TestObjectPrivate) {}
L_SIGNAL(signal1, (int, float), toto, tata); CHECK_SIGNAL_INDEX(signal1, 0);
L_SIGNAL(signal2, (bool, float, int), a, b, c); CHECK_SIGNAL_INDEX(signal2, 1);
L_SIGNAL(signal1, (int, float), toto, tata); CHECK_SIGNAL(signal1, 0);
L_SIGNAL(signal2, (bool, float, int), a, b, c); CHECK_SIGNAL(signal2, 1);
private:
L_DECLARE_PRIVATE(TestObject);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment