Replace FastDelegate in event module with std::function
authorZbigniew Kostrzewa <z.kostrzewa@samsung.com>
Tue, 29 Oct 2013 12:49:11 +0000 (13:49 +0100)
committerSoo-Hyun Choi <sh9.choi@samsung.com>
Thu, 31 Oct 2013 11:39:10 +0000 (20:39 +0900)
[Issue#]   LINUXWRT-1061
[Problem]  Remove FastDelegate
[Cause]    Licensing issues
[Solution] Remove references to FastDelegate from event module.

[Verification]
1. Build repository with tests
2. Launch (on DUT):
   - `wrt-commons-tests-core --output=text`
   - `wrt-commons-tests-event --output=text`
   The same number of tests should pass after and before applying this change.

Change-Id: Ib1a074f07baa0ed801e8720a3321f08d9aded0e9

modules/event/include/dpl/event/event_support.h
modules/event/include/dpl/event/generic_event_call.h
modules/event/include/dpl/event/property.h
tests/event/test_property.cpp

index f7a8d8f..66b5d5f 100644 (file)
 #ifndef DPL_EVENT_SUPPORT_H
 #define DPL_EVENT_SUPPORT_H
 
+#include <functional>
 #include <dpl/event/event_listener.h>
 #include <dpl/event/abstract_event_dispatcher.h>
 #include <dpl/event/main_event_dispatcher.h>
 #include <dpl/event/thread_event_dispatcher.h>
 #include <dpl/event/generic_event_call.h>
 #include <dpl/waitable_event.h>
-#include <dpl/fast_delegate.h>
 #include <memory>
 #include <dpl/exception.h>
 #include <dpl/thread.h>
@@ -66,7 +66,9 @@ class EventSupport :
     typedef EventSupport<EventType> EventSupportType;
 
     typedef EventListener<EventType> EventListenerType;
-    typedef FastDelegate1<const EventType &> DelegateType;
+
+    typedef void DelegateSignature(const EventType&);
+    typedef std::function<DelegateSignature> DelegateType;
 
     class EventSupportData; // Forward declaration
     typedef EventSupportData *EventSupportDataPtr;
@@ -80,8 +82,17 @@ class EventSupport :
     typedef std::map<EventListenerType *, Thread *> EventListenerList;
     EventListenerList m_eventListenerList;
 
+    struct DelegateCompare
+    {
+        bool operator()(const DelegateType& a, const DelegateType& b) const
+        {
+            return a.template target<DelegateSignature>() <
+                   b.template target<DelegateSignature>();
+        }
+    };
+
     // Delegate list
-    typedef std::map<DelegateType, Thread *> DelegateList;
+    typedef std::map<DelegateType, Thread *, DelegateCompare> DelegateList;
     DelegateList m_delegateList;
 
     // Event support operation mutex
@@ -643,7 +654,7 @@ class EventSupport :
         Mutex::ScopedLock lock(&m_listenerDelegateMutex);
 
         // Delegate must not be empty
-        Assert(!delegate.empty());
+        Assert(delegate);
 
         // Delegate must not already exists
         Assert(m_delegateList.find(delegate) == m_delegateList.end());
@@ -679,7 +690,7 @@ class EventSupport :
         Mutex::ScopedLock lock(&m_listenerDelegateMutex);
 
         // Delegate must not be empty
-        Assert(!delegate.empty());
+        Assert(delegate);
 
         // Delegate must exist
         typename DelegateList::iterator iterator =
index 77fea72..2cdf026 100644 (file)
 #ifndef DPL_GENERIC_EVENT_CALL_H
 #define DPL_GENERIC_EVENT_CALL_H
 
+#include <functional>
+
 #include <dpl/event/abstract_event_call.h>
 #include <dpl/event/event_listener.h>
 #include <dpl/noncopyable.h>
-#include <dpl/fast_delegate.h>
 #include <dpl/log/log.h>
 #include <dpl/assert.h>
 
@@ -37,7 +38,7 @@ class GenericEventCall :
 {
   public:
     typedef EventListener<EventType> EventListenerType;
-    typedef FastDelegate1<const EventType &> DelegateType;
+    typedef std::function<void(const EventType &)> DelegateType;
 
   protected:
     SupportDataType m_supportData;
index cb88431..e5cb8a0 100644 (file)
 #ifndef DPL_PROPERTY_H
 #define DPL_PROPERTY_H
 
+#include <functional>
+
 #include <dpl/event/model.h>
 #include <dpl/event/event_support.h>
 #include <dpl/assert.h>
 #include <dpl/noncopyable.h>
 #include <dpl/read_write_mutex.h>
-#include <dpl/fast_delegate.h>
 #include <dpl/once.h>
 
 namespace DPL {
@@ -303,13 +304,13 @@ class PropertyStorageMethod<Type,
 
     Type Get() const
     {
-        Assert(!this->m_readValue.empty());
+        Assert(this->m_readValue);
         return this->m_readValue(m_model);
     }
 
     void Set(const Type &value)
     {
-        Assert(!this->m_writeValue.empty());
+        Assert(this->m_writeValue);
         this->m_writeValue(value, m_model);
     }
 };
@@ -353,14 +354,14 @@ class PropertyStorageMethod<Type,
 
     Type Get() const
     {
-        Assert(!this->m_readValue.empty());
+        Assert(this->m_readValue);
         m_once.Call(Once::Delegate(this, &ThisType::OnceEnsure));
         return this->m_value;
     }
 
     void Set(const Type &value)
     {
-        Assert(!this->m_writeValue.empty());
+        Assert(this->m_writeValue);
 
         this->m_writeValue(value, m_model);
         this->m_value = value;
@@ -379,10 +380,10 @@ class PropertyBase :
     typedef typename EventSupport<PropertyEvent<Type> >::DelegateType
     DelegateType;
 
-    typedef FastDelegate<Type(Model *)>
+    typedef std::function<Type(Model *)>
     ReadDelegateType;
 
-    typedef FastDelegate<void (const Type &, Model *)>
+    typedef std::function<void (const Type &, Model *)>
     WriteDelegateType;
 
   protected:
index d72d02e..2760932 100644 (file)
@@ -74,12 +74,12 @@ class MyModel :
     Testproperty5;
 
     MyModel() :
-        Caption(this, "Foo caption"),
-        Testproperty0(this, "", &ReadSomething),
+        Caption(this, std::string("Foo caption")),
+        Testproperty0(this, std::string(""), &ReadSomething),
         Testproperty1(this),
         Testproperty2(this),
         Testproperty3(this),
-        Testproperty4(this, "test", &ReadSomething, &WriteSomething),
+        Testproperty4(this, std::string("test"), &ReadSomething, &WriteSomething),
         Testproperty5(this, &ReadSomething2)
     {}
 };