Merge "Include the algorithm header file" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / update / common / property-owner.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/update/common/property-owner.h>
20
21 // EXTERNAL INCLUDES
22 #include <algorithm>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 namespace SceneGraph
35 {
36
37 PropertyOwner* PropertyOwner::New()
38 {
39   return new PropertyOwner();
40 }
41
42 PropertyOwner::~PropertyOwner()
43 {
44   Destroy();
45 }
46
47 void PropertyOwner::AddObserver(Observer& observer)
48 {
49   //Check for duplicates in debug builds
50   DALI_ASSERT_DEBUG( mObservers.End() == std::find( mObservers.Begin(), mObservers.End(), &observer ) );
51
52   mObservers.PushBack( &observer );
53 }
54
55 void PropertyOwner::RemoveObserver(Observer& observer)
56 {
57   // Find the observer...
58   const ConstObserverIter endIter =  mObservers.End();
59   for( ObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
60   {
61     if( (*iter) == &observer)
62     {
63       // erase it
64       mObservers.Erase(iter);
65       break;
66     }
67   }
68 }
69
70 bool PropertyOwner::IsObserved()
71 {
72   return mObservers.Count() != 0u;
73 }
74
75 void PropertyOwner::Destroy()
76 {
77   // Notification for observers
78   const ConstObserverIter endIter = mObservers.End();
79   for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
80   {
81     (*iter)->PropertyOwnerDestroyed(*this);
82   }
83
84   mObservers.Clear();
85
86   // Remove all constraints when disconnected from scene-graph
87   mConstraints.Clear();
88 }
89
90 void PropertyOwner::ConnectToSceneGraph()
91 {
92   mIsConnectedToSceneGraph = true;
93
94   // Notification for observers
95   const ConstObserverIter endIter = mObservers.End();
96   for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
97   {
98     (*iter)->PropertyOwnerConnected( *this );
99   }
100 }
101
102 void PropertyOwner::DisconnectFromSceneGraph( BufferIndex updateBufferIndex )
103 {
104   mIsConnectedToSceneGraph = false;
105
106   // Notification for observers
107   const ConstObserverIter endIter = mObservers.End();
108   for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
109   {
110     (*iter)->PropertyOwnerDisconnected( updateBufferIndex, *this );
111   }
112
113   // Remove all constraints when disconnected from scene-graph
114   mConstraints.Clear();
115 }
116
117 void PropertyOwner::InstallCustomProperty( OwnerPointer<PropertyBase>& property )
118 {
119   mCustomProperties.PushBack( property.Release() );
120 }
121
122
123 ConstraintOwnerContainer& PropertyOwner::GetConstraints()
124 {
125   return mConstraints;
126 }
127
128 void PropertyOwner::ApplyConstraint( OwnerPointer<ConstraintBase>& constraint )
129 {
130   constraint->OnConnect();
131   mConstraints.PushBack( constraint.Release() );
132 }
133
134 void PropertyOwner::RemoveConstraint( ConstraintBase* constraint )
135 {
136   const ConstraintIter constraintEndIter = mConstraints.End();
137   for( ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter )
138   {
139     if ( *iter == constraint )
140     {
141       mConstraints.Erase( iter );
142       return; // We're finished
143     }
144   }
145
146   //it may be that the constraint has already been removed e.g. from disconnection from scene graph, so nothing needs to be done
147 }
148
149 PropertyOwner::PropertyOwner()
150 : mUpdated(false),
151   mIsConnectedToSceneGraph(false)
152 {
153 }
154
155 void PropertyOwner::AddUniformMapping( OwnerPointer< UniformPropertyMapping >& map )
156 {
157   mUniformMaps.Add( map.Release() );
158 }
159
160 void PropertyOwner::RemoveUniformMapping( const std::string& uniformName )
161 {
162   mUniformMaps.Remove( uniformName );
163 }
164
165 const UniformMap& PropertyOwner::GetUniformMap() const
166 {
167   return mUniformMaps;
168 }
169
170 void PropertyOwner::AddUniformMapObserver( UniformMap::Observer& observer )
171 {
172   mUniformMaps.AddObserver( observer );
173 }
174
175 void PropertyOwner::RemoveUniformMapObserver( UniformMap::Observer& observer )
176 {
177   mUniformMaps.RemoveObserver( observer );
178 }
179
180
181
182 } // namespace SceneGraph
183
184 } // namespace Internal
185
186 } // namespace Dali