use modern construct 'nullptr' instead of 'NULL' or '0'
[platform/core/uifw/dali-core.git] / dali / public-api / signals / base-signal.cpp
index c84393a..a26a0c8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -27,7 +27,7 @@
 namespace
 {
 
-const int INVALID_CALLBACK_INDEX = -1;
+const int32_t INVALID_CALLBACK_INDEX = -1;
 
 } // unnamed namespace
 
@@ -78,7 +78,7 @@ std::size_t BaseSignal::GetConnectionCount() const
   for( std::size_t i = 0; i < size; ++i )
   {
     // Note that values are set to NULL in DeleteConnection
-    if ( NULL != mSignalConnections[i] )
+    if ( nullptr != mSignalConnections[i] )
     {
       ++count;
     }
@@ -118,9 +118,9 @@ void BaseSignal::Emit()
 
 void BaseSignal::OnConnect( CallbackBase* callback )
 {
-  DALI_ASSERT_ALWAYS( NULL != callback && "Invalid member function pointer passed to Connect()" );
+  DALI_ASSERT_ALWAYS( nullptr != callback && "Invalid member function pointer passed to Connect()" );
 
-  int index = FindCallback( callback );
+  int32_t index = FindCallback( callback );
 
   // Don't double-connect the same callback
   if( INVALID_CALLBACK_INDEX == index )
@@ -139,9 +139,9 @@ void BaseSignal::OnConnect( CallbackBase* callback )
 
 void BaseSignal::OnDisconnect( CallbackBase* callback )
 {
-  DALI_ASSERT_ALWAYS( NULL != callback && "Invalid member function pointer passed to Disconnect()" );
+  DALI_ASSERT_ALWAYS( nullptr != callback && "Invalid member function pointer passed to Disconnect()" );
 
-  int index = FindCallback( callback );
+  int32_t index = FindCallback( callback );
 
   if( index > INVALID_CALLBACK_INDEX )
   {
@@ -154,10 +154,10 @@ void BaseSignal::OnDisconnect( CallbackBase* callback )
 
 void BaseSignal::OnConnect( ConnectionTrackerInterface* tracker, CallbackBase* callback )
 {
-  DALI_ASSERT_ALWAYS( NULL != tracker  && "Invalid ConnectionTrackerInterface pointer passed to Connect()" );
-  DALI_ASSERT_ALWAYS( NULL != callback && "Invalid member function pointer passed to Connect()" );
+  DALI_ASSERT_ALWAYS( nullptr != tracker  && "Invalid ConnectionTrackerInterface pointer passed to Connect()" );
+  DALI_ASSERT_ALWAYS( nullptr != callback && "Invalid member function pointer passed to Connect()" );
 
-  int index = FindCallback( callback );
+  int32_t index = FindCallback( callback );
 
   // Don't double-connect the same callback
   if( INVALID_CALLBACK_INDEX == index )
@@ -179,10 +179,10 @@ void BaseSignal::OnConnect( ConnectionTrackerInterface* tracker, CallbackBase* c
 
 void BaseSignal::OnDisconnect( ConnectionTrackerInterface* tracker, CallbackBase* callback )
 {
-  DALI_ASSERT_ALWAYS( NULL != tracker  && "Invalid ConnectionTrackerInterface pointer passed to Disconnect()" );
-  DALI_ASSERT_ALWAYS( NULL != callback && "Invalid member function pointer passed to Disconnect()" );
+  DALI_ASSERT_ALWAYS( nullptr != tracker  && "Invalid ConnectionTrackerInterface pointer passed to Disconnect()" );
+  DALI_ASSERT_ALWAYS( nullptr != callback && "Invalid member function pointer passed to Disconnect()" );
 
-  int index = FindCallback( callback );
+  int32_t index = FindCallback( callback );
 
   if( index > INVALID_CALLBACK_INDEX )
   {
@@ -226,7 +226,7 @@ CallbackBase* BaseSignal::GetCallback( std::size_t connectionIndex ) const
 {
   DALI_ASSERT_ALWAYS( connectionIndex < mSignalConnections.Count() && "GetCallback called with invalid index" );
 
-  CallbackBase* callback( NULL );
+  CallbackBase* callback( nullptr );
 
   SignalConnection* connection( mSignalConnections[ connectionIndex ] );
 
@@ -239,23 +239,22 @@ CallbackBase* BaseSignal::GetCallback( std::size_t connectionIndex ) const
   return callback;
 }
 
-int BaseSignal::FindCallback( CallbackBase* callback )
+int32_t BaseSignal::FindCallback( CallbackBase* callback )
 {
-  int index( INVALID_CALLBACK_INDEX );
+  int32_t index( INVALID_CALLBACK_INDEX );
 
   // A signal can have multiple slots connected to it.
   // We need to search for the slot which has the same call back function (if it's static)
   // Or the same object / member function (for non-static)
-  const std::size_t count( mSignalConnections.Count() );
-  for( std::size_t i=0; i < count; ++i )
+  const std::size_t count = mSignalConnections.Count();
+  for( std::size_t i = 0; i < count; ++i )
   {
     const CallbackBase* connectionCallback = GetCallback( i );
 
     // Note that values are set to NULL in DeleteConnection
-    if( connectionCallback &&
-        ( *connectionCallback == *callback ) )
+    if( connectionCallback && ( *connectionCallback == *callback ) )
     {
-      index = i;
+      index = static_cast<int>( i ); // only 2,147,483,647 connections supported, no error check
       break;
     }
   }
@@ -276,7 +275,7 @@ void BaseSignal::DeleteConnection( std::size_t connectionIndex )
     // IMPORTANT - do not remove from items from mSignalConnections, set to NULL instead.
     // Signal Emit() methods require that connection count is not reduced while iterating
     // i.e. DeleteConnection can be called from within callbacks, while iterating through mSignalConnections.
-    mSignalConnections[ connectionIndex ] = NULL;
+    mSignalConnections[ connectionIndex ] = nullptr;
   }
   else
   {
@@ -296,7 +295,7 @@ void BaseSignal::CleanupConnections()
     // process the whole vector
     for( std::size_t i = 0; i < total; ++i )
     {
-      if( mSignalConnections[ index ] == NULL )
+      if( mSignalConnections[ index ] == nullptr )
       {
         // items will be moved so don't increase index (erase will decrease the count of vector)
         mSignalConnections.Erase( mSignalConnections.Begin() + index );
@@ -313,7 +312,7 @@ void BaseSignal::CleanupConnections()
 // BaseSignal::EmitGuard
 
 BaseSignal::EmitGuard::EmitGuard( bool& flag )
-: mFlag( NULL )
+: mFlag( nullptr )
 {
   if( !flag )
   {
@@ -338,7 +337,7 @@ BaseSignal::EmitGuard::~EmitGuard()
 bool BaseSignal::EmitGuard::ErrorOccurred()
 {
   // mFlag is NULL when Emit() is called during Emit()
-  return (NULL == mFlag);
+  return (nullptr == mFlag);
 }
 
 } // namespace Dali