2 * Copyright (c) 2015 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.
17 #include "uniform-map.h"
26 UniformMap::UniformMap()
30 UniformMap::~UniformMap()
32 // Nothing to do - let the owner container delete the maps
35 void UniformMap::AddObserver( Observer& observer )
37 bool foundObserver = false;
38 for( ObserversIter iter = mObservers.Begin(); iter != mObservers.End(); ++iter )
40 if( *iter == &observer )
48 mObservers.PushBack( &observer );
52 void UniformMap::RemoveObserver( Observer& observer )
54 for( ObserversIter iter = mObservers.Begin(); iter != mObservers.End(); ++iter )
56 if( *iter == &observer )
58 mObservers.Erase(iter);
64 void UniformMap::MappingChanged()
66 for( ObserversIter iter = mObservers.Begin(); iter != mObservers.End(); ++iter )
68 Observer* observer = (*iter);
69 observer->UniformMappingsChanged( *this );
73 void UniformMap::Add( UniformPropertyMapping* newMap )
75 UniformPropertyMapping::Hash nameHash = CalculateHash( newMap->uniformName );
79 for( UniformMapIter iter = mUniformMaps.Begin() ;
80 iter != mUniformMaps.End() ;
83 UniformPropertyMapping* map = *iter;
84 if( map->uniformNameHash == nameHash )
86 if( map->uniformName == newMap->uniformName )
89 // Mapping already exists - update it.
90 map->propertyPtr = newMap->propertyPtr;
98 // Take ownership of the new map
99 mUniformMaps.PushBack(newMap);
105 void UniformMap::Remove( const std::string& uniformName )
107 UniformPropertyMapping::Hash nameHash = CalculateHash( uniformName );
111 for( UniformMapIter iter = mUniformMaps.Begin() ;
112 iter != mUniformMaps.End() ;
115 UniformPropertyMapping* map = *iter;
116 if( map->uniformNameHash == nameHash )
118 if( map->uniformName == uniformName )
120 mUniformMaps.Erase( iter );
133 const PropertyInputImpl* UniformMap::Find( const std::string& uniformName )
135 UniformPropertyMapping::Hash nameHash = CalculateHash( uniformName );
137 for( UniformMapIter iter = mUniformMaps.Begin() ;
138 iter != mUniformMaps.End() ;
141 UniformPropertyMapping* map = *iter;
142 if( map->uniformNameHash == nameHash )
144 if( map->uniformName == uniformName )
146 return map->propertyPtr;
153 unsigned int UniformMap::Count() const
155 return mUniformMaps.Count();
158 const UniformPropertyMapping& UniformMap::operator[]( unsigned int index ) const
160 return *mUniformMaps[index];