Use modern construct 'using' instead of typedef.
[platform/core/uifw/dali-core.git] / dali / internal / common / message.h
index 13c67bb..48dac3f 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_MESSAGE_H__
-#define __DALI_INTERNAL_MESSAGE_H__
+#ifndef DALI_INTERNAL_MESSAGE_H
+#define DALI_INTERNAL_MESSAGE_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.
@@ -70,8 +70,7 @@ template< typename T >
 class Message : public MessageBase
 {
 public:
-
-  typedef void(T::*MemberFunction)();
+  using MemberFunction = void ( T::* )();
 
   /**
    * Create a message.
@@ -85,6 +84,7 @@ public:
     object( const_cast< T* >( obj ) ),
     memberFunction( member )
   {
+    DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
   }
 
   /**
@@ -99,7 +99,6 @@ public:
    */
   virtual void Process( BufferIndex /*bufferIndex*/ )
   {
-    DALI_ASSERT_DEBUG( object && "Message does not have an object" );
     (object->*memberFunction)();
   }
 
@@ -120,8 +119,7 @@ template< typename T, typename P >
 class MessageValue1 : public MessageBase
 {
 public:
-
-  typedef void(T::*MemberFunction)( typename ParameterType< P >::PassingType );
+  using MemberFunction = void ( T::* )( typename ParameterType<P>::PassingType );
 
   /**
    * Create a message.
@@ -139,6 +137,7 @@ public:
     memberFunction( member ),
     param1( p1 )
   {
+    DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
   }
 
   /**
@@ -153,8 +152,7 @@ public:
    */
   virtual void Process( BufferIndex /*bufferIndex*/ )
   {
-    DALI_ASSERT_DEBUG( object && "Message does not have an object" );
-    (object->*memberFunction)( ParameterType< P >::PassObject( param1 ) );
+    (object->*memberFunction)( param1 );
   }
 
 private:
@@ -176,10 +174,7 @@ template< typename T, typename P1, typename P2 >
 class MessageValue2 : public MessageBase
 {
 public:
-
-  typedef void(T::*MemberFunction)(
-      typename ParameterType< P1 >::PassingType,
-      typename ParameterType< P2 >::PassingType );
+  using MemberFunction = void ( T::* )( typename ParameterType<P1>::PassingType, typename ParameterType<P2>::PassingType );
 
   /**
    * Create a message.
@@ -200,6 +195,7 @@ public:
     param1( p1 ),
     param2( p2 )
   {
+    DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
   }
 
   /**
@@ -214,10 +210,7 @@ public:
    */
   virtual void Process( BufferIndex /*bufferIndex*/ )
   {
-    DALI_ASSERT_DEBUG( object && "Message does not have an object" );
-    (object->*memberFunction)(
-        ParameterType< P1 >::PassObject( param1 ),
-        ParameterType< P2 >::PassObject( param2 ) );
+    (object->*memberFunction)( param1, param2 );
   }
 
 private:
@@ -239,11 +232,7 @@ template< typename T, typename P1, typename P2, typename P3 >
 class MessageValue3 : public MessageBase
 {
 public:
-
-  typedef void(T::*MemberFunction)(
-      typename ParameterType< P1 >::PassingType,
-      typename ParameterType< P2 >::PassingType,
-      typename ParameterType< P3 >::PassingType );
+  using MemberFunction = void ( T::* )( typename ParameterType<P1>::PassingType, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType );
 
   /**
    * Create a message.
@@ -267,6 +256,7 @@ public:
     param2( p2 ),
     param3( p3 )
   {
+    DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
   }
 
   /**
@@ -281,11 +271,7 @@ public:
    */
   virtual void Process( BufferIndex /*bufferIndex*/ )
   {
-    DALI_ASSERT_DEBUG( object && "Message does not have an object" );
-    (object->*memberFunction)(
-        ParameterType< P1 >::PassObject( param1 ),
-        ParameterType< P2 >::PassObject( param2 ),
-        ParameterType< P3 >::PassObject( param3 ) );
+    (object->*memberFunction)( param1, param2, param3 );
   }
 
 private:
@@ -308,12 +294,7 @@ template< typename T, typename P1, typename P2, typename P3, typename P4 >
 class MessageValue4 : public MessageBase
 {
 public:
-
-  typedef void(T::*MemberFunction)(
-      typename ParameterType< P1 >::PassingType,
-      typename ParameterType< P2 >::PassingType,
-      typename ParameterType< P3 >::PassingType,
-      typename ParameterType< P4 >::PassingType );
+  using MemberFunction = void ( T::* )( typename ParameterType<P1>::PassingType, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType, typename ParameterType<P4>::PassingType );
 
   /**
    * Create a message.
@@ -340,6 +321,7 @@ public:
     param3( p3 ),
     param4( p4 )
   {
+    DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
   }
 
   /**
@@ -354,12 +336,7 @@ public:
    */
   virtual void Process( BufferIndex /*bufferIndex*/ )
   {
-    DALI_ASSERT_DEBUG( object && "Message does not have an object" );
-    (object->*memberFunction)(
-        ParameterType< P1 >::PassObject( param1 ),
-        ParameterType< P2 >::PassObject( param2 ),
-        ParameterType< P3 >::PassObject( param3 ),
-        ParameterType< P4 >::PassObject( param4 ) );
+    (object->*memberFunction)( param1, param2, param3, param4 );
   }
 
 private:
@@ -383,13 +360,7 @@ template< typename T, typename P1, typename P2, typename P3, typename P4, typena
 class MessageValue5 : public MessageBase
 {
 public:
-
-  typedef void(T::*MemberFunction)(
-      typename ParameterType< P1 >::PassingType,
-      typename ParameterType< P2 >::PassingType,
-      typename ParameterType< P3 >::PassingType,
-      typename ParameterType< P4 >::PassingType,
-      typename ParameterType< P5 >::PassingType );
+  using MemberFunction = void ( T::* )( typename ParameterType<P1>::PassingType, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType, typename ParameterType<P4>::PassingType, typename ParameterType<P5>::PassingType );
 
   /**
    * Create a message.
@@ -419,6 +390,7 @@ public:
     param4( p4 ),
     param5( p5 )
   {
+    DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
   }
 
   /**
@@ -433,14 +405,7 @@ public:
    */
   virtual void Process( BufferIndex /*bufferIndex*/ )
   {
-    DALI_ASSERT_DEBUG( object && "Message does not have an object" );
-    (object->*memberFunction)(
-        ParameterType< P1 >::PassObject( param1 ),
-        ParameterType< P2 >::PassObject( param2 ),
-        ParameterType< P3 >::PassObject( param3 ),
-        ParameterType< P4 >::PassObject( param4 ),
-        ParameterType< P5 >::PassObject( param5 ) );
-
+    (object->*memberFunction)( param1, param2, param3, param4, param5 );
   }
 
 private:
@@ -465,14 +430,7 @@ template< typename T, typename P1, typename P2, typename P3, typename P4, typena
 class MessageValue6 : public MessageBase
 {
 public:
-
-  typedef void(T::*MemberFunction)(
-      typename ParameterType< P1 >::PassingType,
-      typename ParameterType< P2 >::PassingType,
-      typename ParameterType< P3 >::PassingType,
-      typename ParameterType< P4 >::PassingType,
-      typename ParameterType< P5 >::PassingType,
-      typename ParameterType< P6 >::PassingType );
+  using MemberFunction = void ( T::* )( typename ParameterType<P1>::PassingType, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType, typename ParameterType<P4>::PassingType, typename ParameterType<P5>::PassingType, typename ParameterType<P6>::PassingType );
 
   /**
    * Create a message.
@@ -505,6 +463,7 @@ public:
     param5( p5 ),
     param6( p6 )
   {
+    DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
   }
 
   /**
@@ -519,15 +478,7 @@ public:
    */
   virtual void Process( BufferIndex /*bufferIndex*/ )
   {
-    DALI_ASSERT_DEBUG( object && "Message does not have an object" );
-    (object->*memberFunction)(
-        ParameterType< P1 >::PassObject( param1 ),
-        ParameterType< P2 >::PassObject( param2 ),
-        ParameterType< P3 >::PassObject( param3 ),
-        ParameterType< P4 >::PassObject( param4 ),
-        ParameterType< P5 >::PassObject( param5 ),
-        ParameterType< P6 >::PassObject( param6 ) );
-
+    (object->*memberFunction)( param1, param2, param3, param4, param5, param6 );
   }
 
 private:
@@ -545,6 +496,54 @@ private:
 
 /**
  * Templated message which calls a member function of an object.
+ * This overload passes just the buffer index to the method, no parameters.
+ */
+template< typename T >
+class MessageDoubleBuffered0 : public MessageBase
+{
+public:
+  using MemberFunction = void ( T::* )( BufferIndex );
+
+  /**
+   * Create a message.
+   * @note The object is expected to be const in the thread which sends this message.
+   * However it can be modified when Process() is called in a different thread.
+   * @param[in] obj The object.
+   * @param[in] member The member function of the object.
+   */
+  MessageDoubleBuffered0( const T* obj, MemberFunction member )
+  : MessageBase(),
+    object( const_cast< T* >( obj ) ),
+    memberFunction( member )
+  {
+    DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
+  }
+
+  /**
+   * Virtual destructor
+   */
+  virtual ~MessageDoubleBuffered0()
+  {
+  }
+
+  /**
+   * @copydoc MessageBase::Process
+   */
+  virtual void Process( BufferIndex bufferIndex )
+  {
+    (object->*memberFunction)( bufferIndex );
+  }
+
+private:
+
+  T* object;
+  MemberFunction memberFunction;
+
+};
+
+
+/**
+ * Templated message which calls a member function of an object.
  * This overload passes a value-type to set a double-buffered property.
  * Template parameters need to match the MemberFunction!
  * The message will contain copy of the value (in case of & or const&)
@@ -553,10 +552,7 @@ template< typename T, typename P >
 class MessageDoubleBuffered1 : public MessageBase
 {
 public:
-
-  typedef void(T::*MemberFunction)(
-      BufferIndex,
-      typename ParameterType< P >::PassingType );
+  using MemberFunction = void ( T::* )( BufferIndex, typename ParameterType<P>::PassingType );
 
   /**
    * Create a message.
@@ -574,6 +570,7 @@ public:
     memberFunction( member ),
     param( p )
   {
+    DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
   }
 
   /**
@@ -588,10 +585,7 @@ public:
    */
   virtual void Process( BufferIndex bufferIndex )
   {
-    DALI_ASSERT_DEBUG( object && "Message does not have an object" );
-    (object->*memberFunction)(
-        bufferIndex,
-        ParameterType< P >::PassObject( param ) );
+    (object->*memberFunction)( bufferIndex,  param );
   }
 
 private:
@@ -612,11 +606,7 @@ template< typename T, typename P2, typename P3 >
 class MessageDoubleBuffered2 : public MessageBase
 {
 public:
-
-  typedef void(T::*MemberFunction)(
-      BufferIndex,
-      typename ParameterType< P2 >::PassingType,
-      typename ParameterType< P3 >::PassingType );
+  using MemberFunction = void ( T::* )( BufferIndex, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType );
 
   /**
    * Create a message.
@@ -637,6 +627,7 @@ public:
     param2( p2 ),
     param3( p3 )
   {
+    DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
   }
 
   /**
@@ -651,11 +642,7 @@ public:
    */
   virtual void Process( BufferIndex bufferIndex )
   {
-    DALI_ASSERT_DEBUG( object && "Message does not have an object" );
-    (object->*memberFunction)(
-        bufferIndex,
-        ParameterType< P2 >::PassObject( param2 ),
-        ParameterType< P3 >::PassObject( param3 ) );
+    (object->*memberFunction)( bufferIndex, param2, param3 );
   }
 
 private:
@@ -678,12 +665,7 @@ template< typename T, typename P2, typename P3, typename P4 >
 class MessageDoubleBuffered3 : public MessageBase
 {
 public:
-
-  typedef void(T::*MemberFunction)(
-      BufferIndex,
-      typename ParameterType< P2 >::PassingType,
-      typename ParameterType< P3 >::PassingType,
-      typename ParameterType< P4 >::PassingType );
+  using MemberFunction = void ( T::* )( BufferIndex, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType, typename ParameterType<P4>::PassingType );
 
   /**
    * Create a message.
@@ -707,6 +689,7 @@ public:
     param3( p3 ),
     param4( p4 )
   {
+    DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
   }
 
   /**
@@ -721,12 +704,7 @@ public:
    */
   virtual void Process( BufferIndex bufferIndex )
   {
-    DALI_ASSERT_DEBUG( object && "Message does not have an object" );
-    (object->*memberFunction)(
-        bufferIndex,
-        ParameterType< P2 >::PassObject( param2 ),
-        ParameterType< P3 >::PassObject( param3 ),
-        ParameterType< P4 >::PassObject( param4 ) );
+    (object->*memberFunction)( bufferIndex, param2, param3, param4 );
   }
 
 private:
@@ -749,13 +727,7 @@ template< typename T, typename P2, typename P3, typename P4, typename P5 >
 class MessageDoubleBuffered4 : public MessageBase
 {
 public:
-
-  typedef void(T::*MemberFunction)(
-      BufferIndex,
-      typename ParameterType< P2 >::PassingType,
-      typename ParameterType< P3 >::PassingType,
-      typename ParameterType< P4 >::PassingType,
-      typename ParameterType< P5 >::PassingType );
+  using MemberFunction = void ( T::* )( BufferIndex, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType, typename ParameterType<P4>::PassingType, typename ParameterType<P5>::PassingType );
 
   /**
    * Create a message.
@@ -782,6 +754,7 @@ public:
     param4( p4 ),
     param5( p5 )
   {
+    DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
   }
 
   /**
@@ -796,13 +769,7 @@ public:
    */
   virtual void Process( BufferIndex bufferIndex )
   {
-    DALI_ASSERT_DEBUG( object && "Message does not have an object" );
-    (object->*memberFunction)(
-        bufferIndex,
-        ParameterType< P2 >::PassObject( param2 ),
-        ParameterType< P3 >::PassObject( param3 ),
-        ParameterType< P4 >::PassObject( param4 ),
-        ParameterType< P5 >::PassObject( param5 ) );
+    (object->*memberFunction)( bufferIndex, param2, param3, param4, param5 );
   }
 
 private:
@@ -820,4 +787,4 @@ private:
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_MESSAGE_H__
+#endif // DALI_INTERNAL_MESSAGE_H