Merge "Clean up the code to build successfully on macOS" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / common / property-metadata.h
index 3517b85..3dbf675 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_PROPERTY_METADATA_H__
-#define __DALI_INTERNAL_PROPERTY_METADATA_H__
+#ifndef DALI_INTERNAL_PROPERTY_METADATA_H
+#define DALI_INTERNAL_PROPERTY_METADATA_H
 
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
@@ -25,6 +25,7 @@
 // INTERNAL INCLUDES
 #include <dali/public-api/common/constants.h>
 #include <dali/public-api/object/property.h>
+#include <dali/public-api/object/property-value.h>
 
 namespace Dali
 {
@@ -38,7 +39,8 @@ class PropertyBase;
 }
 
 /**
- * An entry in a property metadata lookup.
+ * @brief Base class for the Metadata required by custom and registered animatable properties.
+ *
  * The value type field should be queried, before accessing the scene-graph property:
  *
  * @code
@@ -57,134 +59,179 @@ class PropertyMetadata
 public:
 
   /**
-   * Constructor for an uninitalized property metadata
+   * @brief Virtual Destructor.
    */
-  PropertyMetadata()
-  : value(),
-    componentIndex(Property::INVALID_COMPONENT_INDEX),
-    mProperty(NULL)
-  {
-  }
+  virtual ~PropertyMetadata() = default;
 
   /**
-   * Constructor for property metadata
-   * @param [in] newProperty A pointer to the property metadata.
+   * @brief Returns whether the property is animatable (i.e. if its a scene graph property).
+   * @return True if animatable, false otherwise
    */
-  PropertyMetadata(const SceneGraph::PropertyBase* newProperty)
-  : value(), // value is held by newProperty
-    componentIndex(Property::INVALID_COMPONENT_INDEX),
-    mProperty(newProperty)
+  bool IsAnimatable( void ) const
   {
-    DALI_ASSERT_DEBUG(mProperty && "Uninitialized scenegraph property");
+    return nullptr != mSceneGraphProperty;
   }
 
   /**
-   * Constructor for property metadata
-   * @param [in] newValue The value of the scene-graph owned property.
+   * @brief Whether the property can be written to.
+   * @return True if the property can be written to, false otherwise
    */
-  PropertyMetadata(Property::Value newValue)
-  : value(newValue),
-    componentIndex(Property::INVALID_COMPONENT_INDEX),
-    mProperty(NULL)
+  bool IsWritable( void ) const
   {
+    return mWritable;
   }
 
   /**
-   * Destructor for property metadata
+   * @brief Retrieves the scene-graph property.
+   * @return The scene graph property
+   *
+   * @note Should only be called if the scene-graph property was passed in originally. Will debug assert if the stored property is NULL.
    */
-  virtual ~PropertyMetadata()
+  const SceneGraph::PropertyBase* GetSceneGraphProperty() const
   {
+    DALI_ASSERT_DEBUG( mSceneGraphProperty && "Accessing uninitialized SceneGraph property" );
+    return mSceneGraphProperty;
   }
 
   /**
-   * @return true if the property is animatable (i.e. if its a scene graph property)
+   * @brief Retrieve the type of the property.
+   * @return Type of the held property value
    */
-  bool IsAnimatable(void) const
+  inline Property::Type GetType() const
   {
-    return NULL != mProperty;
+    return value.GetType();
   }
 
   /**
-   * @return true if the property can be written to
+   * Set the cached value of the property.
+   * @param[in] value The propertyValue to set.
    */
-  virtual bool IsWritable(void) const = 0;
+  void SetPropertyValue( const Property::Value& propertyValue );
 
   /**
-   * @return the scene graph property
+   * Get the cached value of a the property.
+   * @return The cached value of the property.
    */
-  const SceneGraph::PropertyBase* GetSceneGraphProperty() const
+  Property::Value GetPropertyValue() const;
+
+  /**
+   * Modifies the stored value by the relativeValue.
+   * @param[in] relativeValue The value to change by.
+   */
+  void AdjustPropertyValueBy( const Property::Value& relativeValue );
+
+protected:
+
+  /**
+   * @brief Constructor to create Metadata for a property.
+   * @param[in] propertyValue       The value of the property (this is used by the event thread)
+   * @param[in] sceneGraphProperty  A pointer to the scene-graph owned property
+   * @param[in] writable            Whether the property is writable
+   */
+  PropertyMetadata( Property::Value propertyValue,
+                    const SceneGraph::PropertyBase* sceneGraphProperty,
+                    bool writable )
+  : value( mStoredValue ),
+    componentIndex( Property::INVALID_COMPONENT_INDEX ),
+    mStoredValue( std::move(propertyValue) ),
+    mSceneGraphProperty( sceneGraphProperty ),
+    mWritable( writable )
   {
-    DALI_ASSERT_DEBUG(mProperty && "Accessing uninitialized SceneGraph property");
-    return mProperty;
   }
 
-  /*
-   * @return type of the held property value
+  /**
+   * @brief Constructor to create Metadata for a component of another property.
+   * @param[in] sceneGraphProperty      A pointer to the scene-graph owned property
+   * @param[in] writable                Whether the property is writable
+   * @param[in] baseValueRef            A reference to the metadata of the base animatable property
+   * @param[in] propertyComponentIndex  The component index of the property
    */
-  inline Property::Type GetType() const { return value.GetType(); }
-
-  Property::Value value;  ///< The property value for a non animatable and custom property
-  int componentIndex;     ///< The index of the property component
+  PropertyMetadata( const SceneGraph::PropertyBase* sceneGraphProperty, bool writable, Property::Value& baseValueRef, int32_t propertyComponentIndex )
+  : value( baseValueRef ),
+    componentIndex( propertyComponentIndex ),
+    mStoredValue(),
+    mSceneGraphProperty( sceneGraphProperty ),
+    mWritable( writable )
+  {
+  }
 
-protected:
+private:
 
   // Not implemented
   PropertyMetadata( const PropertyMetadata& );
   PropertyMetadata& operator=( const PropertyMetadata& );
 
-  const SceneGraph::PropertyBase* mProperty; ///< A pointer to a scene-graph property; should not be modified from actor-thread.
-};
+public: // Data
 
+  /**
+   * @brief The value of this property used to read/write by the event thread.
+   *
+   * If this PropertyMetadata is for property component, then refers to the value in the PropertyMetadata of the base property
+   * to ensure the components are kept in sync with the overall value on the event thread.
+   * Otherwise, this refers to mStoredValue.
+   */
+  Property::Value& value;
+
+  /**
+   * @brief The index of the property component.
+   */
+  int32_t componentIndex;
+
+private:
+
+  Property::Value mStoredValue;                         ///< The cached property value used to read/write by the event thread
+  const SceneGraph::PropertyBase* mSceneGraphProperty;  ///< A pointer to a scene-graph property; should not be modified from actor-thread
+  bool mWritable:1;                                     ///< Whether the property is writable
+};
 
 /**
- * An entry in an animatable property metadata lookup.
- * The value type field should be queried, before accessing the animatable property:
+ * @brief Metadata for a registered animatable property.
  */
 class AnimatablePropertyMetadata : public PropertyMetadata
 {
 public:
 
   /**
-   * Constructor for metadata of animatable property
-   * @param [in] newIndex The index of the animatable property.
-   * @param [in] newType The type ID of the animatable property.
-   * @param [in] newProperty A pointer to the scene-graph owned property.
+   * @brief Constructs metadata for a registered animatable property.
+   * @param[in] propertyIndex           The index of the animatable property
+   * @param[in] propertyComponentIndex  The component index of the animatable property
+   * @param[in] propertyValue           The value of the property (this is used by the event thread)
+   * @param[in] sceneGraphProperty      A pointer to the scene-graph owned property
+   *
+   * @note The base animatable property MUST be created before the component animatable property.
    */
-  AnimatablePropertyMetadata( Property::Index newIndex,
-                        int newComponentIndex,
-                        Property::Type newType,
-                        const SceneGraph::PropertyBase* newProperty )
-  : index(newIndex)
+  AnimatablePropertyMetadata( Property::Index propertyIndex,
+                              const Property::Value& propertyValue,
+                              const SceneGraph::PropertyBase* sceneGraphProperty )
+  : PropertyMetadata( propertyValue, sceneGraphProperty, true ),
+    index( propertyIndex )
   {
-    componentIndex = newComponentIndex;
-    value = Property::Value(newType);
-    mProperty = newProperty;
-    DALI_ASSERT_DEBUG(mProperty && "Uninitialized scenegraph property");
+    DALI_ASSERT_DEBUG( sceneGraphProperty && "Uninitialized scene-graph property" );
   }
 
   /**
-   * Constructor for metadata of animatable property
-   * @param [in] newIndex The index of the animatable property.
-   * @param [in] newValue The value of the scene-graph owned property.
+   * @brief Constructs metadata for a registered animatable component of another property.
+   * @param[in] propertyIndex           The index of the animatable property
+   * @param[in] propertyComponentIndex  The component index of the animatable property
+   * @param[in] baseValueRef            A reference to the metadata of the base animatable property
+   * @param[in] sceneGraphProperty      A pointer to the scene-graph owned property
+   *
+   * @note The base animatable property MUST be created before the component animatable property.
    */
-  AnimatablePropertyMetadata( Property::Index newIndex,
-                        int newComponentIndex,
-                        Property::Value newValue )
-  : index(newIndex)
+  AnimatablePropertyMetadata( Property::Index propertyIndex,
+                              int propertyComponentIndex,
+                              Property::Value& baseValueRef,
+                              const SceneGraph::PropertyBase* sceneGraphProperty )
+  : PropertyMetadata( sceneGraphProperty, true, baseValueRef, propertyComponentIndex ),
+    index( propertyIndex )
   {
-    componentIndex = newComponentIndex;
-    value = newValue;
+    DALI_ASSERT_DEBUG( sceneGraphProperty && "Uninitialized scene-graph property" );
   }
 
   /**
-   * @return true if the property can be written to
+   * @brief Destructor.
    */
-  virtual bool IsWritable(void) const
-  {
-    return true;
-  }
-
-  Property::Index index;       ///< The index of the property
+  ~AnimatablePropertyMetadata() override = default;
 
 private:
 
@@ -192,6 +239,10 @@ private:
   AnimatablePropertyMetadata();
   AnimatablePropertyMetadata( const AnimatablePropertyMetadata& );
   AnimatablePropertyMetadata& operator=( const AnimatablePropertyMetadata& );
+
+public: // Data
+
+  Property::Index   index;    ///< The index of the property.
 };
 
 class CustomPropertyMetadata : public PropertyMetadata
@@ -199,47 +250,49 @@ class CustomPropertyMetadata : public PropertyMetadata
 public:
 
   /**
-   * Constructor for metadata of scene graph based properties
-   * @param [in] newName The name of the custom property.
-   * @param [in] newType The type ID of the custom property.
-   * @param [in] newProperty A pointer to the scene-graph owned property.
+   * Constructs Metadata for scene-graph-based custom properties, i.e. animatable custom properties.
+   * @param[in] propertyName        The name of the custom property
+   * @param[in] propertyKey         The key of the custom property
+   * @param[in] propertyValue       The value of the property (this is used by the event thread)
+   * @param[in] sceneGraphProperty  A pointer to the scene-graph owned property
+   *
+   * @note A valid sceneGraphProperty is mandatory otherwise this will debug assert.
    */
-  CustomPropertyMetadata( const std::string& newName,
-                          Property::Type newType,
-                          const SceneGraph::PropertyBase* newProperty)
-  : name(newName),
-    mAccessMode(Property::ANIMATABLE)
+  CustomPropertyMetadata( std::string propertyName,
+                          Property::Index propertyKey,
+                          Property::Value propertyValue,
+                          const SceneGraph::PropertyBase* sceneGraphProperty )
+  : PropertyMetadata( std::move(propertyValue), sceneGraphProperty, true ),
+    name( std::move(propertyName) ),
+    key( propertyKey ),
+    childPropertyIndex( Property::INVALID_INDEX )
   {
-    value = Property::Value(newType);
-    mProperty = newProperty;
-    DALI_ASSERT_DEBUG(mProperty && "Uninitialized scenegraph property");
+    DALI_ASSERT_DEBUG( sceneGraphProperty && "Uninitialized scene-graph property" );
   }
 
   /**
-   * Constructor for metadata of event side only properties
-   * @param [in] newName The name of the custom property.
-   * @param [in] newValue The value of the custom property.
-   * @param [in] accessMode The access mode of the custom property (writable, animatable etc).
+   * Constructs metadata for event side only custom properties.
+   * @param[in] propertyName   The name of the custom property
+   * @param[in] propertyValue  The value of the property (this is used by the event thread)
+   * @param[in] accessMode     The access mode of the custom property (writable, animatable etc)
+   *
+   * @note The access mode MUST NOT be animatable otherwise this will debug assert.
    */
-  CustomPropertyMetadata( const std::string& newName,
-                          Property::Value newValue,
+  CustomPropertyMetadata( std::string propertyName,
+                          Property::Value propertyValue,
                           Property::AccessMode accessMode )
-  : name(newName),
-    mAccessMode(accessMode)
+  : PropertyMetadata( std::move(propertyValue), nullptr, ( accessMode != Property::READ_ONLY ) ),
+    name( std::move(propertyName) ),
+    key( Property::INVALID_KEY ),
+    childPropertyIndex( Property::INVALID_INDEX )
   {
-    value = newValue;
-    DALI_ASSERT_DEBUG(accessMode != Property::ANIMATABLE && "Animatable must have scenegraph property");
+    DALI_ASSERT_DEBUG( accessMode != Property::ANIMATABLE && "Event side only properties should not be animatable" );
   }
 
   /**
-   * @return true if the property can be written to
+   * @brief Destructor.
    */
-  virtual bool IsWritable(void) const
-  {
-    return (mAccessMode == Property::ANIMATABLE) || (mAccessMode == Property::READ_WRITE);
-  }
-
-  std::string name;       ///< The name of the property
+  ~CustomPropertyMetadata() override = default;
 
 private:
 
@@ -248,12 +301,15 @@ private:
   CustomPropertyMetadata( const CustomPropertyMetadata& );
   CustomPropertyMetadata& operator=( const CustomPropertyMetadata& );
 
-private:
-  Property::AccessMode mAccessMode; ///< The mode of the property
+public: // Data
+
+  std::string       name;                 ///< The name of the property.
+  Property::Index   key;                  ///< The key of the property.
+  Property::Index   childPropertyIndex;   ///< The index as a child property.
 };
 
 } // namespace Internal
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_PROPERTY_METADATA_H__
+#endif // DALI_INTERNAL_PROPERTY_METADATA_H