Cleaning up the property framework; removal of duplicate methods and incorrect assers
[platform/core/uifw/dali-core.git] / dali / internal / event / common / custom-property.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_CUSTOM_PROPERTY_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_CUSTOM_PROPERTY_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <algorithm>
23 #include <utility>
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/common/constants.h>
27 #include <dali/public-api/object/property.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace SceneGraph
36 {
37 class PropertyBase;
38 }
39
40 /**
41  * An entry in a scene-graph property lookup.
42  * The type field should be queried, before accessing the scene-graph property:
43  *
44  * @code
45  * void Example(PropertyEntry entry)
46  * {
47  *   if (entry.type == Property::VECTOR3)
48  *   {
49  *     SceneGraph::AnimatableProperty<Vector3>* property = dynamic_cast< SceneGraph::AnimatableProperty<Vector3>* >( entry.property );
50  *     ...
51  *   }
52  * @endcode
53  *
54  */
55 class CustomProperty
56 {
57 public:
58
59   /**
60    * Constructor for scene graph based properties
61    * @param [in] newName The name of the custom property.
62    * @param [in] newType The type ID of the custom property.
63    * @param [in] newProperty A pointer to the scene-graph owned property.
64    */
65   CustomProperty( const std::string& newName,
66                   Property::Type newType,
67                   const SceneGraph::PropertyBase* newProperty)
68   : name(newName),
69     type(newType),
70     value(), // value is held by newProperty
71     mProperty(newProperty),
72     mAccessMode(Property::ANIMATABLE)
73   {
74     DALI_ASSERT_DEBUG(mProperty && "Uninitialized scenegraph property") ;
75   }
76
77   /**
78    * Constructor for event side only properties
79    * @param [in] newName The name of the custom property.
80    * @param [in] newIndex The index of the custom property.
81    * @param [in] newType The type ID of the custom property.
82    * @param [in] newProperty A pointer to the scene-graph owned property.
83    */
84   CustomProperty( const std::string& newName,
85                   Property::Value newValue,
86                   Property::AccessMode accessMode )
87   : name(newName),
88     type(newValue.GetType()),
89     value(newValue),
90     mProperty(NULL),
91     mAccessMode(accessMode)
92   {
93     DALI_ASSERT_DEBUG(accessMode != Property::ANIMATABLE && "Animatable must have scenegraph property") ;
94   }
95
96   /**
97    * @return true if the property is animatable (i.e. if its a scene graph property)
98    */
99   bool IsAnimatable(void) const
100   {
101     return NULL != mProperty;
102   }
103
104   /**
105    * @return true if the property can be written to
106    */
107   bool IsWritable(void) const
108   {
109     return (mAccessMode == Property::ANIMATABLE) || (mAccessMode == Property::READ_WRITE) ;
110   }
111
112   /**
113    * @return the scene graph property
114    */
115   const SceneGraph::PropertyBase* GetSceneGraphProperty() const
116   {
117     DALI_ASSERT_DEBUG(mProperty && "Accessing uninitialized SceneGraph property") ;
118     return mProperty;
119   }
120
121   std::string name;       ///< The name of the property
122   Property::Type type;    ///< The type of the property
123   Property::Value value;  ///< The property value for a non animatable and custom property
124
125 private:
126
127   // Not implemented
128   CustomProperty();
129   CustomProperty( const CustomProperty& );
130   CustomProperty& operator=( const CustomProperty& );
131
132 private:
133   const SceneGraph::PropertyBase* mProperty; ///< A pointer to a scene-graph property; should not be modified from actor-thread.
134   Property::AccessMode mAccessMode; ///< The mode of the property
135 };
136
137 } // namespace Internal
138
139 } // namespace Dali
140
141 #endif // __DALI_INTERNAL_SCENE_GRAPH_CUSTOM_PROPERTY_H__