Merge "Clean up the code to build successfully on macOS" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / common / object-registry-impl.cpp
index 906a200..a12f485 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
 
 // EXTERNAL INCLUDES
 #include <algorithm>
+#include <cstring> // for strcmp
 
 // INTERNAL INCLUDES
 #include <dali/internal/event/common/thread-local-storage.h>
 #include <dali/public-api/object/object-registry.h>
+#include <dali/public-api/object/type-registry.h>
 
 namespace Dali
 {
@@ -31,55 +33,57 @@ namespace Dali
 namespace Internal
 {
 
-ObjectRegistryPtr ObjectRegistry::New()
+namespace
 {
-  return ObjectRegistryPtr(new ObjectRegistry());
-}
 
-ObjectRegistry::ObjectRegistry()
-{
+// Signals
+
+const char* const SIGNAL_OBJECT_CREATED =   "objectCreated";
+const char* const SIGNAL_OBJECT_DESTROYED = "objectDestroyed";
+
+TypeRegistration mType( typeid( Dali::ObjectRegistry ), typeid( Dali::BaseHandle ), nullptr );
+
+SignalConnectorType signalConnector1( mType, SIGNAL_OBJECT_CREATED,   &ObjectRegistry::DoConnectSignal );
+SignalConnectorType signalConnector2( mType, SIGNAL_OBJECT_DESTROYED, &ObjectRegistry::DoConnectSignal );
+
 }
 
-ObjectRegistry::~ObjectRegistry()
+ObjectRegistryPtr ObjectRegistry::New()
 {
+  return ObjectRegistryPtr( new ObjectRegistry() );
 }
 
-void ObjectRegistry::RegisterObject( Dali::BaseObject* object )
-{
-  // Assert than an object is only registered once
-  DALI_ASSERT_DEBUG( mDebugRegistry.end() == mDebugRegistry.find( object ) );
+ObjectRegistry::ObjectRegistry() = default;
 
-#ifdef DEBUG_ENABLED
-  // This allows us to assert that an object is only registered once (debug builds only)
-  mDebugRegistry.insert( object );
-#endif // DEBUG_ENABLED
+ObjectRegistry::~ObjectRegistry() = default;
 
-  if ( !mObjectCreatedSignalV2.Empty() )
+void ObjectRegistry::RegisterObject( Dali::BaseObject* object )
+{
+  if ( !mObjectCreatedSignal.Empty() )
   {
     Dali::BaseHandle handle( object );
-    mObjectCreatedSignalV2.Emit( handle );
+    mObjectCreatedSignal.Emit( handle );
   }
 }
 
 void ObjectRegistry::UnregisterObject( Dali::BaseObject* object )
 {
-#ifdef DEBUG_ENABLED
-  // This allows us to assert that an object is only registered once (debug builds only)
-  mDebugRegistry.erase( object );
-#endif // DEBUG_ENABLED
-
-  mObjectDestroyedSignalV2.Emit( object );
+  mObjectDestroyedSignal.Emit( object );
 }
 
 bool ObjectRegistry::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
 {
   bool connected( true );
-  ObjectRegistry* objectRegistry = dynamic_cast<ObjectRegistry*>(object);
+  ObjectRegistry* objectRegistry = static_cast< ObjectRegistry* >( object ); // TypeRegistry guarantees that this is the correct type.
 
-  if(Dali::ObjectRegistry::SIGNAL_OBJECT_CREATED == signalName)
+  if( 0 == strcmp( signalName.c_str(), SIGNAL_OBJECT_CREATED ) )
   {
     objectRegistry->ObjectCreatedSignal().Connect( tracker, functor );
   }
+  else if( 0 == strcmp( signalName.c_str(), SIGNAL_OBJECT_DESTROYED ) )
+  {
+    objectRegistry->ObjectDestroyedSignal().Connect( tracker, functor );
+  }
   else
   {
     // signalName does not match any signal