Enable -Wnon-virtual-dtor to avoid incorrect C++ code sneaking in
[platform/core/uifw/dali-core.git] / dali / internal / update / common / uniform-map.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_UNIFORM_MAP_H
2 #define DALI_INTERNAL_SCENE_GRAPH_UNIFORM_MAP_H
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <dali/devel-api/common/hash.h>
21 #include <dali/devel-api/common/owner-container.h>
22 #include <string>
23
24 namespace Dali
25 {
26 namespace Internal
27 {
28 class PropertyInputImpl;
29
30 namespace SceneGraph
31 {
32
33 /**
34  * The uniform map is used to map a uniform name to a property value.
35  */
36 class UniformPropertyMapping
37 {
38 public:
39   typedef unsigned long Hash;
40
41   /**
42    * Constructor
43    */
44   UniformPropertyMapping( const std::string& theUniformName, const PropertyInputImpl* thePropertyPtr )
45   : propertyPtr( thePropertyPtr ),
46     uniformName( theUniformName ),
47     uniformNameHash( Dali::CalculateHash( theUniformName ) )
48   {
49   }
50
51   UniformPropertyMapping()
52   : propertyPtr( NULL ),
53     uniformName( "" ),
54     uniformNameHash( 0 )
55   {
56   }
57
58
59   const PropertyInputImpl* propertyPtr;
60   std::string uniformName;
61   Hash uniformNameHash;
62 };
63
64 /**
65  * The UniformMap class is used to map uniform names to property values. It is available
66  * in all of the classes responsible for rendering:
67  * Actor, Renderer, Geometry, TextureSet, Shader.
68  *
69  * It can be observed for changes to the mapping table.
70  */
71 class UniformMap
72 {
73 public:
74   class Observer
75   {
76   public:
77
78     /**
79      * Inform observer that uniform mappings have been changed
80      * @param mappings
81      */
82     virtual void UniformMappingsChanged(const UniformMap& mappings) = 0;
83
84   protected:
85
86     /**
87      * Virtual destructor, no deletion through this interface
88      */
89     virtual ~Observer() {}
90   };
91
92   /**
93    * Constructor
94    */
95   UniformMap();
96
97   /**
98    * Destructor
99    */
100   ~UniformMap();
101
102   /**
103    * Add an observer that watches for changes in the mappings
104    */
105   void AddObserver( Observer& observer );
106
107   /**
108    * Remove an observer
109    */
110   void RemoveObserver( Observer& observer );
111
112   /**
113    * Add a map to the mappings table.
114    */
115   void Add( UniformPropertyMapping* map );
116
117   /**
118    * Remove a map from the mappings table
119    */
120   void Remove( const std::string& uniformName );
121
122   /**
123    * Find a property given the uniform name.
124    * @return The address of the property if it's in the map, or NULL otherwise.
125    */
126   const PropertyInputImpl* Find( const std::string& uniformName );
127
128   /**
129    * Get the count of uniforms in the map
130    * @return The number of uniform mappings
131    */
132   unsigned int Count() const;
133
134   /**
135    * @pre index must be in the range 0 :: Count()-1
136    * @param[in] index The index of the element to fetch
137    * @return reference to the element in the map
138    */
139   const UniformPropertyMapping& operator[]( unsigned int index ) const;
140
141 private:
142   /**
143    * Helper to call the observers when the mappings have changed
144    */
145   void MappingChanged();
146
147 private:
148   typedef OwnerContainer< UniformPropertyMapping* > UniformMapContainer;
149   typedef UniformMapContainer::Iterator UniformMapIter;
150   typedef Dali::Vector< Observer* > Observers;
151   typedef Observers::Iterator ObserversIter;
152
153   UniformMapContainer mUniformMaps; // Owner container of uniform maps
154
155   Observers mObservers;
156 };
157
158
159 } // namespace SceneGraph
160 } // namespace Internal
161 } // namespace Dali
162
163 #endif // DALI_INTERNAL_SCENE_GRAPH_UNIFORM_MAP_H