Commit 1e2750a6 authored by Ronan's avatar Ronan

feat(Object): provide a new L_OBJECT macro to declare meta data

parent 5156b2c0
......@@ -26,6 +26,10 @@
LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
// Private Impl.
// -----------------------------------------------------------------------------
namespace Private {
// See: http://en.cppreference.com/w/cpp/types/void_t
template<typename... T> struct MakeVoid {
......@@ -46,12 +50,26 @@ namespace Private {
decltype(std::declval<T&>()[std::declval<const typename T::key_type&>()])
>
> : std::true_type {};
template<typename T, typename U = void>
struct IsDefinedTypeImpl : std::false_type {};
template<typename T>
struct IsDefinedTypeImpl<T, typename void_t<T>::type> : std::true_type {};
};
// -----------------------------------------------------------------------------
// Public API.
// -----------------------------------------------------------------------------
// Check if a type is a std container like map, unordered_map...
template<typename T>
struct IsMapContainer : Private::IsMapContainerImpl<T>::type {};
// Check if a type is defined.
template<typename T>
struct IsDefinedTypeImpl : Private::IsDefinedTypeImpl<T>::type {};
LINPHONE_END_NAMESPACE
#endif // ifndef _L_TRAITS_H_
......@@ -29,7 +29,7 @@
LINPHONE_BEGIN_NAMESPACE
class BaseObjectPrivate {
L_OBJECT_PRIVATE;
L_OBJECT_HEAD_PRIVATE;
public:
BaseObjectPrivate () = default;
......
......@@ -27,7 +27,7 @@
LINPHONE_BEGIN_NAMESPACE
L_OBJECT_IMPL(BaseObject);
L_OBJECT_HEAD_IMPL(BaseObject);
BaseObject::BaseObject (BaseObjectPrivate &p) : mPrivate(&p) {
mPrivate->mPublic = this;
......
......@@ -36,7 +36,7 @@ class BaseObjectPrivate;
* like Events.
*/
class LINPHONE_PUBLIC BaseObject {
L_OBJECT;
L_OBJECT_HEAD;
public:
virtual ~BaseObject ();
......
......@@ -31,7 +31,7 @@
LINPHONE_BEGIN_NAMESPACE
class ClonableObjectPrivate {
L_OBJECT_PRIVATE;
L_OBJECT_HEAD_PRIVATE;
public:
ClonableObjectPrivate () = default;
......
......@@ -28,7 +28,7 @@ LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
L_OBJECT_IMPL(ClonableObject);
L_OBJECT_HEAD_IMPL(ClonableObject);
ClonableObject::ClonableObject (ClonableObjectPrivate &p) {
setRef(p);
......
......@@ -42,7 +42,7 @@ LINPHONE_BEGIN_NAMESPACE
* intelligence.
*/
class LINPHONE_PUBLIC ClonableObject : public PropertyContainer {
L_OBJECT;
L_OBJECT_HEAD;
public:
virtual ~ClonableObject ();
......
......@@ -22,7 +22,7 @@
// =============================================================================
#define L_OBJECT_IMPL(CLASS) \
#define L_OBJECT_HEAD_IMPL(CLASS) \
void *CLASS::getCBackPtr () const { \
L_D(); \
return d->cBackPtr; \
......@@ -32,7 +32,7 @@
d->cBackPtr = cBackPtr; \
}
#define L_OBJECT_PRIVATE \
#define L_OBJECT_HEAD_PRIVATE \
void *cBackPtr = nullptr;
#endif // ifndef _L_OBJECT_HEAD_P_H_
......@@ -22,7 +22,7 @@
// =============================================================================
#define L_OBJECT \
#define L_OBJECT_HEAD \
void *getCBackPtr () const; \
void setCBackPtr (void *cBackPtr);
......
......@@ -41,6 +41,15 @@
#define L_SIGNAL_CONCAT_TYPE_ARG(TYPE, PARAM) TYPE PARAM
#define L_OBJECT(NAME) \
private: \
constexpr static const char *lName = #NAME; \
\
public: \
constexpr static const char *getName () { \
return lName; \
}
// Declare one signal method.
#define L_SIGNAL(NAME, TYPES, ...) void NAME (L_APPLY_LIST(L_SIGNAL_CONCAT_TYPE_ARG, TYPES, __VA_ARGS__)) { \
typedef std::remove_reference<decltype(*this)>::type ClassType; \
......
......@@ -35,6 +35,8 @@ public:
};
class TestObject : public Object {
L_OBJECT(TestObject);
public:
TestObject () : Object(*new TestObjectPrivate) {}
......
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