Adding Handle::ReserveCustomProperties method
[platform/core/uifw/dali-core.git] / dali / public-api / object / handle.cpp
index e71b093..002b7be 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
 #include <dali/public-api/object/handle.h>
 
 // INTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+#include <dali/internal/event/animation/constraint-impl.h>
+#include <dali/internal/event/common/object-impl.h>
 #include <dali/public-api/animation/constraint.h>
 #include <dali/public-api/object/property-conditions.h>
 #include <dali/public-api/object/property-notification.h>
-#include <dali/internal/event/animation/constraint-impl.h>
-#include <dali/internal/event/common/object-impl.h>
-#include <dali/internal/event/object/custom-object-internal.h>
-#include <dali/integration-api/debug.h>
 
 namespace Dali
 {
-
-Handle::Handle( Dali::Internal::Object* handle )
+Handle::Handle(Dali::Internal::Object* handle)
 : BaseHandle(handle)
 {
 }
 
+Handle::Handle() = default;
 
-Handle::Handle()
+Handle Handle::New()
 {
+  return Handle(Internal::Object::New().Get());
 }
 
-Handle Handle::New()
+Handle::~Handle() = default;
+
+Handle::Handle(const Handle& handle) = default;
+
+Handle& Handle::operator=(const Handle& rhs) = default;
+
+Handle::Handle(Handle&& rhs) = default;
+
+Handle& Handle::operator=(Handle&& rhs) = default;
+
+Handle Handle::DownCast(BaseHandle handle)
+{
+  return Handle(dynamic_cast<Dali::Internal::Object*>(handle.GetObjectPtr()));
+}
+
+bool Handle::Supports(Capability capability) const
 {
-  return Handle( Internal::CustomObject::New() );
+  return GetImplementation(*this).Supports(capability);
 }
 
-Handle::~Handle()
+uint32_t Handle::GetPropertyCount() const
 {
+  return GetImplementation(*this).GetPropertyCount();
 }
 
-Handle::Handle( const Handle& handle )
-: BaseHandle( handle )
+std::string Handle::GetPropertyName(Property::Index index) const
 {
+  return std::string(GetImplementation(*this).GetPropertyName(index));
 }
 
-Handle& Handle::operator=( const Handle& rhs )
+Property::Index Handle::GetPropertyIndex(Property::Key key) const
 {
-  if( this != &rhs )
-  {
-    BaseHandle::operator=(rhs);
-  }
+  return GetImplementation(*this).GetPropertyIndex(key);
+}
 
-  return *this;
+bool Handle::IsPropertyWritable(Property::Index index) const
+{
+  return GetImplementation(*this).IsPropertyWritable(index);
 }
 
-Handle Handle::DownCast( BaseHandle handle )
+bool Handle::IsPropertyAnimatable(Property::Index index) const
 {
-  return Handle( dynamic_cast<Dali::Internal::Object*>(handle.GetObjectPtr()) );
+  return GetImplementation(*this).IsPropertyAnimatable(index);
 }
 
+bool Handle::IsPropertyAConstraintInput(Property::Index index) const
+{
+  return GetImplementation(*this).IsPropertyAConstraintInput(index);
+}
 
-bool Handle::Supports( Capability capability ) const
+Property::Type Handle::GetPropertyType(Property::Index index) const
 {
-  return GetImplementation(*this).Supports( capability );
+  return GetImplementation(*this).GetPropertyType(index);
 }
 
-unsigned int Handle::GetPropertyCount() const
+void Handle::SetProperty(Property::Index index, Property::Value propertyValue)
 {
-  return GetImplementation(*this).GetPropertyCount();
+  GetImplementation(*this).SetProperty(index, std::move(propertyValue));
 }
 
-std::string Handle::GetPropertyName( Property::Index index ) const
+void Handle::ReserveCustomProperties(int propertyCount)
 {
-  return GetImplementation(*this).GetPropertyName( index );
+  GetImplementation(*this).ReserveCustomProperties(propertyCount);
 }
 
-Property::Index Handle::GetPropertyIndex( const std::string& name ) const
+Property::Index Handle::RegisterProperty(std::string_view name, Property::Value propertyValue)
 {
-  return GetImplementation(*this).GetPropertyIndex( name );
+  return GetImplementation(*this).RegisterProperty(name, std::move(propertyValue));
 }
 
-bool Handle::IsPropertyWritable( Property::Index index ) const
+Property::Index Handle::RegisterProperty(Property::Index key, std::string_view name, Property::Value propertyValue)
 {
-  return GetImplementation(*this).IsPropertyWritable( index );
+  return GetImplementation(*this).RegisterProperty(name, key, std::move(propertyValue), true);
 }
 
-bool Handle::IsPropertyAnimatable( Property::Index index ) const
+Property::Index Handle::RegisterProperty(std::string_view name, Property::Value propertyValue, Property::AccessMode accessMode)
 {
-  return GetImplementation(*this).IsPropertyAnimatable( index );
+  return GetImplementation(*this).RegisterProperty(name, std::move(propertyValue), accessMode);
 }
 
-bool Handle::IsPropertyAConstraintInput( Property::Index index ) const
+Property::Index Handle::RegisterUniqueProperty(std::string_view name, Property::Value propertyValue)
 {
-  return GetImplementation(*this).IsPropertyAConstraintInput( index );
+  return GetImplementation(*this).RegisterProperty(name, Property::INVALID_KEY, std::move(propertyValue), false);
 }
 
-Property::Type Handle::GetPropertyType( Property::Index index ) const
+Property::Index Handle::RegisterUniqueProperty(Property::Index key, std::string_view name, Property::Value propertyValue)
 {
-  return GetImplementation(*this).GetPropertyType( index );
+  return GetImplementation(*this).RegisterProperty(name, key, std::move(propertyValue), false);
 }
 
-void Handle::SetProperty( Property::Index index, const Property::Value& propertyValue )
+Property::Value Handle::GetProperty(Property::Index index) const
 {
-  GetImplementation(*this).SetProperty( index, propertyValue );
+  return GetImplementation(*this).GetProperty(index);
 }
 
-Property::Index Handle::RegisterProperty( const std::string& name, const Property::Value& propertyValue )
+Property::Value Handle::GetCurrentProperty(Property::Index index) const
 {
-  return GetImplementation(*this).RegisterProperty( name, propertyValue );
+  return GetImplementation(*this).GetCurrentProperty(index);
 }
 
-Property::Index Handle::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode )
+void Handle::SetProperties(const Property::Map& properties)
 {
-  return GetImplementation(*this).RegisterProperty( name, propertyValue, accessMode );
+  GetImplementation(*this).SetProperties(properties);
 }
 
-Property::Value Handle::GetProperty( Property::Index index ) const
+void Handle::GetProperties(Property::Map& properties)
 {
-  return GetImplementation(*this).GetProperty( index );
+  GetImplementation(*this).GetProperties(properties);
 }
 
-void Handle::GetPropertyIndices( Property::IndexContainer& indices ) const
+void Handle::GetPropertyIndices(Property::IndexContainer& indices) const
 {
-  GetImplementation(*this).GetPropertyIndices( indices );
+  GetImplementation(*this).GetPropertyIndices(indices);
 }
 
-Dali::PropertyNotification Handle::AddPropertyNotification( Property::Index index,
-                                                            const PropertyCondition& condition )
+bool Handle::DoesCustomPropertyExist(Property::Index index)
 {
-  return GetImplementation(*this).AddPropertyNotification( index, -1, condition );
+  return GetImplementation(*this).DoesCustomPropertyExist(index);
 }
 
-Dali::PropertyNotification Handle::AddPropertyNotification( Property::Index index,
-                                                            int componentIndex,
-                                                            const PropertyCondition& condition )
+Dali::PropertyNotification Handle::AddPropertyNotification(Property::Index          index,
+                                                           const PropertyCondition& condition)
 {
-  return GetImplementation(*this).AddPropertyNotification( index, componentIndex, condition );
+  return GetImplementation(*this).AddPropertyNotification(index, -1, condition);
 }
 
-void Handle::RemovePropertyNotification( Dali::PropertyNotification propertyNotification )
+Dali::PropertyNotification Handle::AddPropertyNotification(Property::Index          index,
+                                                           int                      componentIndex,
+                                                           const PropertyCondition& condition)
 {
-  GetImplementation(*this).RemovePropertyNotification( propertyNotification );
+  return GetImplementation(*this).AddPropertyNotification(index, componentIndex, condition);
+}
+
+void Handle::RemovePropertyNotification(Dali::PropertyNotification propertyNotification)
+{
+  GetImplementation(*this).RemovePropertyNotification(propertyNotification);
 }
 
 void Handle::RemovePropertyNotifications()
@@ -163,31 +188,37 @@ void Handle::RemoveConstraints()
   GetImplementation(*this).RemoveConstraints();
 }
 
-void Handle::RemoveConstraints( unsigned int tag )
+void Handle::RemoveConstraints(uint32_t tag)
 {
-  GetImplementation(*this).RemoveConstraints( tag );
+  GetImplementation(*this).RemoveConstraints(tag);
 }
 
-void Handle::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName )
+IndirectValue Handle::operator[](Property::Index index)
 {
-  GetImplementation(*this).AddUniformMapping( propertyIndex, uniformName );
+  // Will assert on access if handle is empty
+  return IndirectValue(*this, index);
 }
 
-void Handle::RemoveUniformMapping( const std::string uniformName )
+IndirectValue Handle::operator[](const std::string& name)
 {
-  GetImplementation(*this).RemoveUniformMapping( uniformName );
+  // Will assert immediately when GetPropertyIndex is called if handle is empty
+  return IndirectValue(*this, GetPropertyIndex(name));
 }
 
-namespace WeightObject
+Handle::PropertySetSignalType& Handle::PropertySetSignal()
 {
+  return GetImplementation(*this).PropertySetSignal();
+}
 
+namespace WeightObject
+{
 const Property::Index WEIGHT = PROPERTY_CUSTOM_START_INDEX;
 
 Handle New()
 {
   Handle handle = Handle::New();
 
-  handle.RegisterProperty( "weight", 0.0f );
+  handle.RegisterProperty("weight", 0.0f);
 
   return handle;
 }