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