refactor Object,TypeInfo and PropertyMetaData to use ConstString
[platform/core/uifw/dali-core.git] / dali / internal / event / common / object-impl.h
index ac62d37..3a65844 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_OBJECT_H__
-#define __DALI_INTERNAL_OBJECT_H__
+#ifndef DALI_INTERNAL_OBJECT_H
+#define DALI_INTERNAL_OBJECT_H
 
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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 <cstdint> // uint32_t
 
 // INTERNAL INCLUDES
+#include <dali/devel-api/common/owner-container.h>
+#include <dali/devel-api/object/handle-devel.h>
+#include <dali/internal/common/const-string.h>
+#include <dali/internal/event/animation/animation-impl.h>
+#include <dali/internal/event/common/event-thread-services.h>
+#include <dali/internal/event/common/property-input-impl.h>
+#include <dali/internal/event/common/property-metadata.h>
+#include <dali/internal/update/common/property-base.h>
 #include <dali/public-api/animation/constraint.h>
 #include <dali/public-api/common/dali-vector.h>
 #include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/object/base-object.h>
 #include <dali/public-api/object/handle.h>
-#include <dali/public-api/object/property.h>
 #include <dali/public-api/object/property-index-ranges.h>
 #include <dali/public-api/object/property-input.h>
+#include <dali/public-api/object/property-map.h>
 #include <dali/public-api/object/property-notification.h>
-#include <dali/devel-api/common/owner-container.h>
-#include <dali/devel-api/object/handle-devel.h>
-#include <dali/internal/event/animation/animation-impl.h>
-#include <dali/internal/event/common/event-thread-services.h>
-#include <dali/internal/event/common/property-input-impl.h>
-#include <dali/internal/event/common/property-metadata.h>
-#include <dali/internal/update/common/property-base.h>
+#include <dali/public-api/object/property.h>
 
 namespace Dali
 {
@@ -63,6 +65,36 @@ using ConstraintContainer = std::vector< Dali::Constraint >;
 using ConstraintIter = ConstraintContainer::iterator;
 using ConstraintConstIter = ConstraintContainer::const_iterator;
 
+class KeyRef
+{
+public:
+  KeyRef(const Property::Key& key)
+  : mType(key.type)
+  {
+    if(mType == Property::Key::STRING)
+    {
+      mString = ConstString(key.stringKey);
+    }
+    else
+    {
+      mIndex = key.indexKey;
+    }
+  }
+  KeyRef(ConstString str)
+  : mType(Property::Key::STRING)
+  {
+    mString = str;
+  }
+  KeyRef(Property::Index index)
+  : mType(Property::Key::INDEX)
+  {
+    mIndex = index;
+  }
+  Property::Key::Type mType;
+  Property::Index     mIndex{Property::INVALID_INDEX};
+  ConstString         mString;
+};
+
 /**
  * A base class for objects which optionally provide properties.
  * The concrete derived class is responsible for implementing the property system methods.
@@ -108,7 +140,7 @@ public:
     /**
      * Virtual destructor
      */
-    virtual ~Observer(){}
+    virtual ~Observer() = default;
   };
 
   /**
@@ -144,22 +176,12 @@ public:
   /**
    * @copydoc Dali::Handle::GetPropertyName()
    */
-  std::string GetPropertyName( Property::Index index ) const;
-
-  /**
-   * @copydoc Dali::Handle::GetPropertyIndex()
-   */
-  Property::Index GetPropertyIndex( const std::string& name ) const;
-
-  /**
-   * @copydoc Dali::Handle::GetPropertyIndex()
-   */
-  Property::Index GetPropertyIndex( Property::Index key ) const;
+  std::string_view GetPropertyName(Property::Index index) const;
 
   /**
    * @copydoc Dali::Handle::GetPropertyIndex()
    */
-  Property::Index GetPropertyIndex( Property::Key key ) const;
+  Property::Index GetPropertyIndex(KeyRef key) const;
 
   /**
    * @copydoc Dali::Handle::IsPropertyWritable()
@@ -184,7 +206,7 @@ public:
   /**
    * @copydoc Dali::Handle::SetProperty()
    */
-  void SetProperty( Property::Index index, const Property::Value& propertyValue );
+  void SetProperty(Property::Index index, Property::Value propertyValue);
 
   /**
    * @copydoc Dali::Handle::GetProperty()
@@ -206,22 +228,35 @@ public:
   /**
    * @copydoc Dali::Handle::RegisterProperty()
    */
-  Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
+  Property::Index RegisterProperty(std::string_view name, Property::Value propertyValue);
 
   /**
    * @copydoc Dali::Handle::RegisterProperty()
    */
-  Property::Index RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue );
+  Property::Index RegisterProperty(std::string_view name, Property::Index key, Property::Value propertyValue);
+
+  /**
+   * @copydoc Dali::DevelHandle::SetProperties()
+   */
+  void SetProperties( const Property::Map& properties );
+
+  /**
+   * @copydoc Dali::DevelHandle::GetProperties()
+   */
+  void GetProperties( Property::Map& properties );
 
   /**
    * @copydoc Dali::Handle::RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode)
    */
-  Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );
+  Property::Index RegisterProperty(std::string_view name, Property::Value propertyValue, Property::AccessMode accessMode);
 
   /**
    * @brief Implementing method for this override
    */
-  Property::Index RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue, Property::AccessMode accessMode );
+  Property::Index RegisterProperty(std::string_view     name,
+                                   Property::Index      key,
+                                   Property::Value      propertyValue,
+                                   Property::AccessMode accessMode);
 
   /**
    * @brief returns true if the custom property exists on this object.
@@ -269,7 +304,7 @@ public:
    * @param propertyIndex index of the property
    * @param uniformName name of the uniform (same as property name)
    */
-  void AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const;
+  void AddUniformMapping(Property::Index propertyIndex, ConstString uniformName) const;
 
   /**
    * Removes uniform mapping for given property
@@ -348,9 +383,18 @@ public:
   virtual int32_t GetPropertyComponentIndex( Property::Index index ) const;
 
   /**
+   * Query whether playing an animation is possible or not.
+   * @return true if playing an animation is possible.
+   */
+  virtual bool IsAnimationPossible() const
+  {
+    return true;
+  }
+
+  /**
    * @copydoc Dali::Handle::PropertySetSignal()
    */
-  DevelHandle::PropertySetSignalType& PropertySetSignal();
+  Handle::PropertySetSignalType& PropertySetSignal();
 
 protected:
 
@@ -364,7 +408,7 @@ protected:
   /**
    * A reference counted object may only be deleted by calling Unreference()
    */
-  virtual ~Object();
+  ~Object() override;
 
   /**
    * Called immediately by derived classes, after the scene-object has been created & passed to the scene-graph.
@@ -391,7 +435,7 @@ protected:
    * @param [in] index The index of the property.
    * @param [in] propertyValue The value of the property.
    */
-  virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) {}
+  virtual void OnPropertySet( Property::Index index, const Property::Value& propertyValue ) {}
 
   /**
    * Retrieves the TypeInfo for this object. Only retrieves it from the type-registry once and then stores a pointer
@@ -422,7 +466,7 @@ protected:
    * @param [in] value The value of the property.
    * @return The index of the registered property or Property::INVALID_INDEX if registration failed.
    */
-  Property::Index RegisterSceneGraphProperty( const std::string& name, Property::Index key, Property::Index index, const Property::Value& propertyValue ) const;
+  Property::Index RegisterSceneGraphProperty(ConstString name, Property::Index key, Property::Index index, Property::Value propertyValue) const;
 
   /**
    * Registers animatable scene property
@@ -521,7 +565,7 @@ protected:
    */
   inline EventThreadServices& GetEventThreadServices()
   {
-    DALI_ASSERT_DEBUG( EventThreadServices::IsCoreRunning() );
+    DALI_ASSERT_ALWAYS( EventThreadServices::IsCoreRunning() );
     return mEventThreadServices;
   }
 
@@ -534,7 +578,7 @@ protected:
    */
   inline const EventThreadServices& GetEventThreadServices() const
   {
-    DALI_ASSERT_DEBUG( EventThreadServices::IsCoreRunning() );
+    DALI_ASSERT_ALWAYS( EventThreadServices::IsCoreRunning() );
     return mEventThreadServices;
   }
 
@@ -560,8 +604,8 @@ private:
 
   using PropertyNotificationContainer = std::vector< Dali::PropertyNotification >;
   PropertyNotificationContainer* mPropertyNotifications; ///< Container of owned property notifications.
-  DevelHandle::PropertySetSignalType mPropertySetSignal;
 
+  Handle::PropertySetSignalType mPropertySetSignal;
 };
 
 } // namespace Internal
@@ -588,4 +632,4 @@ inline const Internal::Object& GetImplementation(const Dali::Handle& object)
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_OBJECT_H__
+#endif // DALI_INTERNAL_OBJECT_H