Dali 3D User Interface Engine
constrainer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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
20 
21 // INTERNAL INCLUDES
24 
25 namespace Dali
26 {
27 
28 namespace Internal
29 {
30 
32 :Object()
33 {
34 }
35 
37 {
38  //Remove all the constraints created by the object
39  size_t tag = reinterpret_cast<size_t>( this );
40  const ObjectIter end = mObservedObjects.End();
41  for( ObjectIter iter = mObservedObjects.Begin(); iter != end; ++iter )
42  {
43  //Remove Constrainer from the observers list of the object
44  (*iter)->RemoveObserver( *this );
45 
46  //Remove constraints
47  (*iter)->RemoveConstraints( tag );
48  }
49 }
50 
52 {
53  //Remove object from the list of observed
54  const ObjectIter end = mObservedObjects.End();
55  for( ObjectIter iter = mObservedObjects.Begin(); iter != end; ++iter )
56  {
57  if( *iter == &object )
58  {
59  mObservedObjects.Erase(iter);
60  return;
61  }
62  }
63 }
64 
66 {
67  size_t tag = reinterpret_cast<size_t>( this );
68  Object& object = GetImplementation(target);
69  const ObjectIter end = mObservedObjects.End();
70  for( ObjectIter iter = mObservedObjects.Begin(); iter != end; ++iter )
71  {
72  if( *iter == &object )
73  {
74  //Stop observing the object
75  (*iter)->RemoveObserver( *this );
76 
77  //Remove constraints created in the object
78  target.RemoveConstraints( tag );
79 
80  //Remove object from the vector of observed objects
81  mObservedObjects.Erase(iter);
82  }
83  }
84 }
85 
87 {
88  Object& object = GetImplementation(handle);
89 
90  //Add the object to the list of observed objects if it is not in it already
91  const ObjectIter end = mObservedObjects.End();
93  for(; iter != end; ++iter )
94  {
95  if( *iter == &object )
96  {
97  break;
98  }
99  }
100 
101  if( iter == end )
102  {
103  //Start observing the object
104  object.AddObserver( *this );
105 
106  //Add object in the observed objects vector
107  mObservedObjects.PushBack( &object );
108  }
109 }
110 
111 } // namespace Internal
112 
113 } // namespace Dali
114 
Dali Docs Home
Read more about Dali