-#ifndef __DALI_FUNCTOR_DELEGATE_H__
-#define __DALI_FUNCTOR_DELEGATE_H__
+#ifndef DALI_FUNCTOR_DELEGATE_H
+#define DALI_FUNCTOR_DELEGATE_H
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// INTERNAL INCLUDES
#include <dali/public-api/common/dali-common.h>
-namespace Dali DALI_IMPORT_API
+namespace Dali
{
+/**
+ * @addtogroup dali_core_signals
+ * @{
+ */
/**
- * @brief Dispatcher to call a functor
+ * @brief Dispatcher to call a functor.
+ * @SINCE_1_0.0
*/
-template< class T >
+template< typename T >
struct FunctorDispatcher
{
/**
- * @brief Call a function object.
+ * @brief Calls a function object.
*
- * @param[in] objectPtr The object to call.
+ * @SINCE_1_0.0
+ * @param[in] functorPtr The functor to call
*/
- static void Dispatch( void* objectPtr )
+ static void Dispatch( void* functorPtr )
{
- // "downcast" the object and function type back to the correct ones
- T* object = reinterpret_cast< T* >( objectPtr );
- (*object)();
+ // "downcast" the functor type back to the correct one
+ T* functor = reinterpret_cast< T* >( functorPtr );
+ (*functor)();
}
};
/**
- * @brief Dispatcher to delete an object
+ * @brief Dispatcher to delete a functor object.
+ * @SINCE_1_0.0
*/
-template< class T >
+template< typename T >
struct FunctorDestroyer
{
/**
- * @brief Dispatcher to delete an object
+ * @brief Dispatcher to delete an object.
+ * @SINCE_1_0.0
+ * @param[in] functorPtr A functor object to delete
*/
- static void Delete( void* object )
+ static void Delete( void* functorPtr )
{
// FunctorDelegate owns the object but we're the only one who knows the real type so need
// to delete by "downcasting" from void* to the correct type
- delete reinterpret_cast< T* >( object );
+ delete reinterpret_cast< T* >( functorPtr );
}
};
/**
- * @brief Used to connect a void() functor to a signal via BaseObject::SignalConnect()
+ * @brief Used to connect a void() functor to a signal via BaseObject::SignalConnect().
+ * @SINCE_1_0.0
*/
-class FunctorDelegate
+class DALI_CORE_API FunctorDelegate
{
public:
/**
* @brief Constructor which copies a function object.
*
- * @param[in] object The object to copy.
+ * @SINCE_1_0.0
+ * @param[in] functor The functor object to copy, either a class with operator() or a C function
* @return A pointer to the new function object
*/
- template< class T >
- static FunctorDelegate* New( const T& object )
+ template< typename T >
+ static FunctorDelegate* New( const T& functor )
{
- return new FunctorDelegate( reinterpret_cast< void* >( new T( object ) ), // copy the object
- reinterpret_cast< FunctorDelegate::Dispatcher >( &FunctorDispatcher<T>::Dispatch ),
- reinterpret_cast< FunctorDelegate::Destructor >( &FunctorDestroyer<T>::Delete ) );
+ return new FunctorDelegate( reinterpret_cast< void* >( new T( functor ) ), // heap allocate the functor
+ reinterpret_cast< FunctorDelegate::Dispatcher >( &FunctorDispatcher<T>::Dispatch ),
+ reinterpret_cast< FunctorDelegate::Destructor >( &FunctorDestroyer<T>::Delete ) );
}
/**
* @brief Non-virtual destructor; not intended as a base class.
+ * @SINCE_1_0.0
*/
~FunctorDelegate();
/**
- * @brief Function to call the function or member function dispatcher
+ * @brief Function to call the function or member function dispatcher.
+ * @SINCE_1_0.0
*/
void Execute();
private:
/**
- * @brief Used to call the correct member function.
+ * @brief Used to call the correct function.
+ * @SINCE_1_0.0
*/
- typedef void (*Dispatcher)( void* objectPtr );
+ using Dispatcher = void ( * )( void* );
/**
- * @brief Used to destroy mObjectPointer (NULL if not mObjectPointer is not owned).
+ * @brief Used to destroy mObjectPointer.
+ * @SINCE_1_0.0
*/
- typedef void(*Destructor)( void* objectPtr );
+ using Destructor = void ( * )( void* );
/**
- * @brief Not defined
+ * @brief Not defined.
+ * @SINCE_1_0.0
*/
FunctorDelegate( const FunctorDelegate& rhs );
/**
- * @brief Not defined
+ * @brief Not defined.
+ * @SINCE_1_0.0
*/
const FunctorDelegate& operator=( const FunctorDelegate& rhs );
/**
* @brief Private constructor.
*
- * @param[in] objectPtr A newly allocated object (takes ownership)
- * @param dispatcher Used to call the actual object.
- * @param destructor Used to delete the owned object.
+ * @SINCE_1_0.0
+ * @param[in] functorPtr A newly allocated functor object (takes ownership)
+ * @param dispatcher Used to call the actual function
+ * @param destructor Used to delete the owned functor object
*/
- FunctorDelegate( void* objectPtr, Dispatcher dispatcher, Destructor destructor );
+ FunctorDelegate( void* functorPtr, Dispatcher dispatcher, Destructor destructor );
public: // Data for deriving classes & Dispatchers
- void* mObjectPointer; ///< Object whose member function will be called. Not owned if mDestructorDispatcher is NULL.
+ void* mFunctorPointer; ///< Functor that will be called
Dispatcher mMemberFunctionDispatcher; ///< Dispatcher for member functions
- Destructor mDestructorDispatcher; ///< Destructor for owned objects. NULL if mDestructorDispatcher is not owned.
+ Destructor mDestructorDispatcher; ///< Destructor for owned objects
};
+/**
+ * @}
+ */
} // namespace DALI
-#endif // __DALI_FUNCTOR_DELEGATE_H__
+#endif // DALI_FUNCTOR_DELEGATE_H