9e68bd2ead9794fbaa9c3b79e8e22c95d3e7d605
[platform/core/uifw/dali-core.git] / dali / internal / update / common / property-owner.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // EXTERNAL INCLUDES
21 #include <set>
22
23 // INTERNAL INCLUDES
24 #include <dali/public-api/common/dali-vector.h>
25 #include <dali/internal/common/message.h>
26 #include <dali/internal/common/owner-container.h>
27 #include <dali/internal/update/common/property-base.h>
28 #include <dali/internal/update/common/scene-graph-buffers.h>
29 #include <dali/internal/update/animation/scene-graph-constraint-declarations.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace SceneGraph
38 {
39
40 class PropertyOwner;
41
42 typedef std::set<PropertyOwner*>   PropertyOwnerSet;
43 typedef PropertyOwnerSet::iterator PropertyOwnerIter;
44
45 typedef OwnerContainer< PropertyBase* > OwnedPropertyContainer;
46 typedef OwnedPropertyContainer::Iterator  OwnedPropertyIter;
47
48 /**
49  * Base for scene-graph objects which own properties.
50  * This allows observers to track the lifetime of the object & its properties.
51  */
52 class PropertyOwner
53 {
54 public:
55
56   class Observer
57   {
58   public:
59
60     /**
61      * Called shortly before the observable object is destroyed.
62      */
63     virtual void PropertyOwnerDestroyed( PropertyOwner& owner ) = 0;
64   };
65
66   /**
67    * Virtual destructor; this is intended as a base class.
68    */
69   virtual ~PropertyOwner();
70
71   /**
72    * Add an observer.
73    * The observer is responsible for calling RemoveObserver(*this) during its own destruction.
74    * Connecting an actor-side object as an observer is not allowed, due to thread-safety issues.
75    * @param[in] observer The observer.
76    */
77   void AddObserver(Observer& observer);
78
79   /**
80    * Remove an observer.
81    * @param[in] observer The observer.
82    */
83   void RemoveObserver(Observer& observer);
84
85   /**
86    * This method can be used to determine if there is an animation or
87    * constraint that is using this property owner.
88    * @return true if there are observers.
89    */
90   bool IsObserved();
91
92   /**
93    * Disconnect all observers and remove constraints.
94    * This occurs when the object is disconnected from the scene-graph during UpdateManager::Update().
95    */
96   void DisconnectFromSceneGraph();
97
98   /**
99    * Install a custom property.
100    * @post The PropertyOwner takes ownership of the property.
101    * @param[in] property A pointer to a newly allocated property.
102    */
103   void InstallCustomProperty(PropertyBase* property);
104
105   /**
106    * Retrieve the custom properties owned by the object.
107    * @return A container of properties.
108    */
109   OwnedPropertyContainer& GetCustomProperties()
110   {
111     return mCustomProperties;
112   }
113
114   /**
115    * Retrieve the custom properties owned by the object.
116    * @return A container of properties.
117    */
118   const OwnedPropertyContainer& GetCustomProperties() const
119   {
120     return mCustomProperties;
121   }
122
123   /**
124    * Reset animatable properties to the corresponding base values.
125    * @param[in] currentBufferIndex The buffer to reset.
126    * @post The ResetDefaultProperties method is called, during which derived classes can reset default properties.
127    */
128   void ResetToBaseValues( BufferIndex updateBufferIndex );
129
130   // Constraints
131
132   /**
133    * Apply a constraint.
134    * @param[in] constraint The constraint to apply.
135    */
136   void ApplyConstraint( ConstraintBase* constraint );
137
138   /**
139    * Begin removal of constraints.
140    * @param[in] constraint The constraint to remove.
141    */
142   void RemoveConstraint( ConstraintBase* constraint );
143
144   /**
145    * Retrieve the constraints that are currently applied.
146    * @return A container of constraints.
147    */
148   ConstraintOwnerContainer& GetConstraints();
149
150 protected:
151
152   /**
153    * Protected constructor.
154    */
155   PropertyOwner();
156
157 private:
158
159   // Undefined
160   PropertyOwner(const PropertyOwner&);
161
162   // Undefined
163   PropertyOwner& operator=(const PropertyOwner& rhs);
164
165   /**
166    * Called after ResetToBaseValues; derived classes should reset any default properties.
167    * @param[in] currentBufferIndex The buffer to reset.
168    */
169   virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ) = 0;
170
171 protected:
172
173   OwnedPropertyContainer mCustomProperties; ///< Properties provided with InstallCustomProperty()
174
175 private:
176
177   typedef Dali::Vector<PropertyOwner::Observer*> ObserverContainer;
178   typedef ObserverContainer::Iterator ObserverIter;
179   typedef ObserverContainer::ConstIterator ConstObserverIter;
180
181   ObserverContainer mObservers; ///< Container of observer raw-pointers (not owned)
182
183   ConstraintOwnerContainer mConstraints; ///< Container of owned constraints
184
185 };
186
187 } // namespace SceneGraph
188
189 } // namespace Internal
190
191 } // namespace Dali
192
193 #endif // __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__