Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / update / common / property-owner.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // CLASS HEADER
18 #include <dali/internal/update/common/property-owner.h>
19
20 // EXTERNAL INCLUDES
21 #include <algorithm>
22
23 // INTERNAL INCLUDES
24 #include <dali/public-api/common/dali-common.h>
25 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace SceneGraph
34 {
35
36 PropertyOwner* PropertyOwner::New()
37 {
38   return new PropertyOwner();
39 }
40
41 PropertyOwner::~PropertyOwner()
42 {
43   DisconnectFromSceneGraph();
44 }
45
46 void PropertyOwner::AddObserver(Observer& observer)
47 {
48   //Check for duplicates in debug builds
49   DALI_ASSERT_DEBUG( mObservers.End() == std::find( mObservers.Begin(), mObservers.End(), &observer ) );
50
51   mObservers.PushBack( &observer );
52 }
53
54 void PropertyOwner::RemoveObserver(Observer& observer)
55 {
56   // Find the observer...
57   const ConstObserverIter endIter =  mObservers.End();
58   for( ObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
59   {
60     if( (*iter) == &observer)
61     {
62       // erase it
63       mObservers.Erase(iter);
64       break;
65     }
66   }
67 }
68
69 bool PropertyOwner::IsObserved()
70 {
71   return mObservers.Count() != 0u;
72 }
73
74 void PropertyOwner::DisconnectFromSceneGraph()
75 {
76   // Notification for observers
77   const ConstObserverIter endIter = mObservers.End();
78   for( ConstObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
79   {
80     (*iter)->PropertyOwnerDestroyed(*this);
81   }
82
83   mObservers.Clear();
84
85   // Remove all constraints when disconnected from scene-graph
86   mConstraints.Clear();
87 }
88
89 void PropertyOwner::InstallCustomProperty(PropertyBase* property)
90 {
91   DALI_ASSERT_DEBUG( NULL != property );
92
93   mCustomProperties.PushBack( property );
94 }
95
96 void PropertyOwner::ResetToBaseValues( BufferIndex updateBufferIndex )
97 {
98   // Reset custom properties
99   const OwnedPropertyIter endIter = mCustomProperties.End();
100   for ( OwnedPropertyIter iter = mCustomProperties.Begin(); endIter != iter; ++iter )
101   {
102     (*iter)->ResetToBaseValue( updateBufferIndex );
103   }
104
105   // Reset constraint weights
106   const ConstraintIter constraintEndIter = mConstraints.End();
107   for( ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter )
108   {
109     (*iter)->mWeight.ResetToBaseValue( updateBufferIndex );
110   }
111
112   // Notification for derived classes, to reset default properties
113   ResetDefaultProperties( updateBufferIndex );
114 }
115
116 ConstraintOwnerContainer& PropertyOwner::GetConstraints()
117 {
118   return mConstraints;
119 }
120
121 void PropertyOwner::ApplyConstraint( ConstraintBase* constraint )
122 {
123   mConstraints.PushBack( constraint );
124
125   constraint->OnConnect();
126 }
127
128 void PropertyOwner::RemoveConstraint( ConstraintBase* constraint )
129 {
130   // Reset constraint weights
131   const ConstraintIter constraintEndIter = mConstraints.End();
132   for( ConstraintIter iter = mConstraints.Begin(); constraintEndIter != iter; ++iter )
133   {
134     if ( *iter == constraint )
135     {
136       mConstraints.Erase( iter );
137       return; // We're finished
138     }
139   }
140
141   // Should not come here
142   DALI_ASSERT_DEBUG( false && "Constraint missing in RemoveConstraint" );
143 }
144
145 PropertyOwner::PropertyOwner()
146 {
147 }
148
149 } // namespace SceneGraph
150
151 } // namespace Internal
152
153 } // namespace Dali