/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 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.
const int INVALID_CALLBACK_INDEX = -1;
-// Predicate for std::remove_if algorithm
-bool IsNullPredicate(void* ptr)
-{
- return ptr == NULL;
-}
-
} // unnamed namespace
namespace Dali
// The signal is being destroyed. We have to inform any slots
// that are connected, that the signal is dead.
- for( std::size_t i=0; i < mSignalConnections.size(); i++ )
+ const std::size_t count( mSignalConnections.Count() );
+ for( std::size_t i=0; i < count; i++ )
{
SignalConnection* connection = mSignalConnections[ i ];
}
}
- mSignalConnections.clear();
+ mSignalConnections.Clear();
}
bool BaseSignal::Empty() const
{
std::size_t count( 0 );
- const std::size_t size( mSignalConnections.size() );
+ const std::size_t size( mSignalConnections.Count() );
for( std::size_t i = 0; i < size; ++i )
{
// Note that values are set to NULL in DeleteConnection
}
// If more connections are added by callbacks, these are ignore until the next Emit()
- // Note that mSignalConnections.size() count cannot be reduced while iterating
- const std::size_t initialCount( mSignalConnections.size() );
+ // Note that mSignalConnections.Count() count cannot be reduced while iterating
+ const std::size_t initialCount( mSignalConnections.Count() );
for( std::size_t i = 0; i < initialCount; ++i )
{
// create a new signal connection object, to allow the signal to track the connection.
SignalConnection* connection = new SignalConnection( callback );
- mSignalConnections.push_back( connection );
+ mSignalConnections.PushBack( connection );
}
else
{
// create a new signal connection object, to allow the signal to track the connection.
SignalConnection* connection = new SignalConnection( tracker, callback );
- mSignalConnections.push_back( connection );
+ mSignalConnections.PushBack( connection );
// Let the connection tracker know that a connection between a signal and a slot has been made.
tracker->SignalConnected( this, callback );
// for SlotObserver::SlotDisconnected
void BaseSignal::SlotDisconnected( CallbackBase* callback )
{
- for( std::size_t i=0; i < mSignalConnections.size(); ++i )
+ const std::size_t count( mSignalConnections.Count() );
+ for( std::size_t i=0; i < count; ++i )
{
const CallbackBase* connectionCallback = GetCallback( i );
CallbackBase* BaseSignal::GetCallback( std::size_t connectionIndex ) const
{
- DALI_ASSERT_ALWAYS( connectionIndex < mSignalConnections.size() && "GetCallback called with invalid index" );
+ DALI_ASSERT_ALWAYS( connectionIndex < mSignalConnections.Count() && "GetCallback called with invalid index" );
CallbackBase* callback( NULL );
// 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)
-
- for( std::size_t i=0; i < mSignalConnections.size(); ++i )
+ const std::size_t count( mSignalConnections.Count() );
+ for( std::size_t i=0; i < count; ++i )
{
const CallbackBase* connectionCallback = GetCallback( i );
void BaseSignal::DeleteConnection( std::size_t connectionIndex )
{
- DALI_ASSERT_ALWAYS( connectionIndex < mSignalConnections.size() && "DeleteConnection called with invalid index" );
+ DALI_ASSERT_ALWAYS( connectionIndex < mSignalConnections.Count() && "DeleteConnection called with invalid index" );
// delete the object
SignalConnection* connection( mSignalConnections[ connectionIndex ] );
void BaseSignal::CleanupConnections()
{
- // Move NULL pointers to the end...
- std::vector< SignalConnection* >::iterator endIter = remove_if( mSignalConnections.begin(), mSignalConnections.end(), IsNullPredicate );
-
- // ...and remove them
- mSignalConnections.erase( endIter, mSignalConnections.end() );
+ const std::size_t total = mSignalConnections.Count();
+ // only do something if there are items
+ if( total > 0 )
+ {
+ std::size_t index = 0;
+ // process the whole vector
+ for( std::size_t i = 0; i < total; ++i )
+ {
+ if( mSignalConnections[ index ] == NULL )
+ {
+ // items will be moved so don't increase index (erase will decrease the count of vector)
+ mSignalConnections.Erase( mSignalConnections.Begin() + index );
+ }
+ else
+ {
+ // increase to next element
+ ++index;
+ }
+ }
+ }
}
// BaseSignal::EmitGuard
else
{
// mFlag is NULL when Emit() is called during Emit()
- DALI_LOG_ERROR( "Cannot call Emit() from inside Emit()" );
+ DALI_LOG_ERROR( "Cannot call Emit() from inside Emit()\n" );
}
}