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>
26 UniformMap::UniformMap() = default;
28 UniformMap::~UniformMap()
30 // Nothing to do - let the owner container delete the maps
33 void UniformMap::AddObserver( Observer& observer )
35 bool foundObserver = false;
36 for( ObserversIter iter = mObservers.Begin(); iter != mObservers.End(); ++iter )
38 if( *iter == &observer )
46 mObservers.PushBack( &observer );
50 void UniformMap::RemoveObserver( Observer& observer )
52 for( ObserversIter iter = mObservers.Begin(); iter != mObservers.End(); ++iter )
54 if( *iter == &observer )
56 mObservers.Erase(iter);
62 void UniformMap::MappingChanged()
64 for( ObserversIter iter = mObservers.Begin(); iter != mObservers.End(); ++iter )
66 Observer* observer = (*iter);
67 observer->UniformMappingsChanged( *this );
71 void UniformMap::Add( UniformPropertyMapping* newMap )
73 UniformPropertyMapping::Hash nameHash = CalculateHash( newMap->uniformName );
77 for( UniformMapIter iter = mUniformMaps.Begin() ;
78 iter != mUniformMaps.End() ;
81 UniformPropertyMapping* map = *iter;
82 if( map->uniformNameHash == nameHash )
84 if( map->uniformName == newMap->uniformName )
87 // Mapping already exists - update it.
88 map->propertyPtr = newMap->propertyPtr;
96 // Take ownership of the new map
97 mUniformMaps.PushBack(newMap);
103 void UniformMap::Remove( const std::string& uniformName )
105 UniformPropertyMapping::Hash nameHash = CalculateHash( uniformName );
109 for( UniformMapIter iter = mUniformMaps.Begin() ;
110 iter != mUniformMaps.End() ;
113 UniformPropertyMapping* map = *iter;
114 if( map->uniformNameHash == nameHash )
116 if( map->uniformName == uniformName )
118 mUniformMaps.Erase( iter );
131 const PropertyInputImpl* UniformMap::Find( const std::string& uniformName )
133 UniformPropertyMapping::Hash nameHash = CalculateHash( uniformName );
135 for( UniformMapIter iter = mUniformMaps.Begin() ;
136 iter != mUniformMaps.End() ;
139 UniformPropertyMapping* map = *iter;
140 if( map->uniformNameHash == nameHash )
142 if( map->uniformName == uniformName )
144 return map->propertyPtr;
151 UniformMap::SizeType UniformMap::Count() const
153 return static_cast<UniformMap::SizeType>( mUniformMaps.Count() );
156 const UniformPropertyMapping& UniformMap::operator[]( UniformMap::SizeType index ) const
158 return *mUniformMaps[index];