2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali/internal/update/common/uniform-map.h>
27 UniformMap::UniformMap()
31 UniformMap::~UniformMap()
33 // Nothing to do - let the owner container delete the maps
36 void UniformMap::AddObserver( Observer& observer )
38 bool foundObserver = false;
39 for( ObserversIter iter = mObservers.Begin(); iter != mObservers.End(); ++iter )
41 if( *iter == &observer )
49 mObservers.PushBack( &observer );
53 void UniformMap::RemoveObserver( Observer& observer )
55 for( ObserversIter iter = mObservers.Begin(); iter != mObservers.End(); ++iter )
57 if( *iter == &observer )
59 mObservers.Erase(iter);
65 void UniformMap::MappingChanged()
67 for( ObserversIter iter = mObservers.Begin(); iter != mObservers.End(); ++iter )
69 Observer* observer = (*iter);
70 observer->UniformMappingsChanged( *this );
74 void UniformMap::Add( UniformPropertyMapping* newMap )
76 UniformPropertyMapping::Hash nameHash = CalculateHash( newMap->uniformName );
80 for( UniformMapIter iter = mUniformMaps.Begin() ;
81 iter != mUniformMaps.End() ;
84 UniformPropertyMapping* map = *iter;
85 if( map->uniformNameHash == nameHash )
87 if( map->uniformName == newMap->uniformName )
90 // Mapping already exists - update it.
91 map->propertyPtr = newMap->propertyPtr;
99 // Take ownership of the new map
100 mUniformMaps.PushBack(newMap);
106 void UniformMap::Remove( const std::string& uniformName )
108 UniformPropertyMapping::Hash nameHash = CalculateHash( uniformName );
112 for( UniformMapIter iter = mUniformMaps.Begin() ;
113 iter != mUniformMaps.End() ;
116 UniformPropertyMapping* map = *iter;
117 if( map->uniformNameHash == nameHash )
119 if( map->uniformName == uniformName )
121 mUniformMaps.Erase( iter );
134 const PropertyInputImpl* UniformMap::Find( const std::string& uniformName )
136 UniformPropertyMapping::Hash nameHash = CalculateHash( uniformName );
138 for( UniformMapIter iter = mUniformMaps.Begin() ;
139 iter != mUniformMaps.End() ;
142 UniformPropertyMapping* map = *iter;
143 if( map->uniformNameHash == nameHash )
145 if( map->uniformName == uniformName )
147 return map->propertyPtr;
154 UniformMap::SizeType UniformMap::Count() const
156 return static_cast<UniformMap::SizeType>( mUniformMaps.Count() );
159 const UniformPropertyMapping& UniformMap::operator[]( UniformMap::SizeType index ) const
161 return *mUniformMaps[index];