Clean up the code to build successfully on macOS
[platform/core/uifw/dali-core.git] / dali / internal / update / common / uniform-map.cpp
1 /*
2  * Copyright (c) 2018 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 // CLASS HEADER
18 #include <dali/internal/update/common/uniform-map.h>
19
20 namespace Dali
21 {
22 namespace Internal
23 {
24 namespace SceneGraph
25 {
26
27 UniformMap::UniformMap()
28 {
29 }
30
31 UniformMap::~UniformMap()
32 {
33   // Nothing to do - let the owner container delete the maps
34 }
35
36 void UniformMap::AddObserver( Observer& observer )
37 {
38   bool foundObserver = false;
39   for( ObserversIter iter = mObservers.Begin(); iter != mObservers.End(); ++iter )
40   {
41     if( *iter == &observer )
42     {
43       foundObserver = true;
44       break;
45     }
46   }
47   if( !foundObserver )
48   {
49     mObservers.PushBack( &observer );
50   }
51 }
52
53 void UniformMap::RemoveObserver( Observer& observer )
54 {
55   for( ObserversIter iter = mObservers.Begin(); iter != mObservers.End(); ++iter )
56   {
57     if( *iter == &observer )
58     {
59       mObservers.Erase(iter);
60       return;
61     }
62   }
63 }
64
65 void UniformMap::MappingChanged()
66 {
67   for( ObserversIter iter = mObservers.Begin(); iter != mObservers.End(); ++iter )
68   {
69     Observer* observer = (*iter);
70     observer->UniformMappingsChanged( *this );
71   }
72 }
73
74 void UniformMap::Add( UniformPropertyMapping* newMap )
75 {
76   UniformPropertyMapping::Hash nameHash = CalculateHash( newMap->uniformName );
77
78   bool found = false;
79
80   for( UniformMapIter iter = mUniformMaps.Begin() ;
81        iter != mUniformMaps.End() ;
82        ++iter )
83   {
84     UniformPropertyMapping* map = *iter;
85     if( map->uniformNameHash == nameHash )
86     {
87       if( map->uniformName == newMap->uniformName )
88       {
89         found = true;
90         // Mapping already exists - update it.
91         map->propertyPtr = newMap->propertyPtr;
92         break;
93       }
94     }
95   }
96
97   if( found == false )
98   {
99     // Take ownership of the new map
100     mUniformMaps.PushBack(newMap);
101   }
102
103   MappingChanged();
104 }
105
106 void UniformMap::Remove( const std::string& uniformName )
107 {
108   UniformPropertyMapping::Hash nameHash = CalculateHash( uniformName );
109
110   bool found=false;
111
112   for( UniformMapIter iter = mUniformMaps.Begin() ;
113        iter != mUniformMaps.End() ;
114        ++iter )
115   {
116     UniformPropertyMapping* map = *iter;
117     if( map->uniformNameHash == nameHash )
118     {
119       if( map->uniformName == uniformName )
120       {
121         mUniformMaps.Erase( iter );
122         found = true;
123         break;
124       }
125     }
126   }
127
128   if( found )
129   {
130     MappingChanged();
131   }
132 }
133
134 const PropertyInputImpl* UniformMap::Find( const std::string& uniformName )
135 {
136   UniformPropertyMapping::Hash nameHash = CalculateHash( uniformName );
137
138   for( UniformMapIter iter = mUniformMaps.Begin() ;
139        iter != mUniformMaps.End() ;
140        ++iter )
141   {
142     UniformPropertyMapping* map = *iter;
143     if( map->uniformNameHash == nameHash )
144     {
145       if( map->uniformName == uniformName )
146       {
147         return map->propertyPtr;
148       }
149     }
150   }
151   return nullptr;
152 }
153
154 UniformMap::SizeType UniformMap::Count() const
155 {
156   return static_cast<UniformMap::SizeType>( mUniformMaps.Count() );
157 }
158
159 const UniformPropertyMapping& UniformMap::operator[]( UniformMap::SizeType index ) const
160 {
161   return *mUniformMaps[index];
162 }
163
164 } // SceneGraph
165 } // Internal
166 } // Dali