Reorder node's children only required case.
[platform/core/uifw/dali-core.git] / dali / internal / update / common / uniform-map.cpp
1 /*
2  * Copyright (c) 2023 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 <algorithm>
18
19 // CLASS HEADER
20 #include <dali/internal/update/common/uniform-map.h>
21
22 namespace Dali
23 {
24 namespace Internal
25 {
26 namespace SceneGraph
27 {
28 void UniformMap::MappingChanged()
29 {
30   ++mChangeCounter;
31 }
32
33 void UniformMap::Add(UniformPropertyMapping newMap)
34 {
35   auto iter = std::find_if(mUniformMaps.Begin(),
36                            mUniformMaps.End(),
37                            [&](auto& element) { return element.uniformName == newMap.uniformName; });
38
39   if(iter != mUniformMaps.End())
40   {
41     // Mapping already exists - update it.
42     (*iter).propertyPtr = newMap.propertyPtr;
43   }
44   else
45   {
46     // add the new map.
47     mUniformMaps.PushBack(newMap);
48   }
49
50   MappingChanged();
51 }
52
53 void UniformMap::Remove(ConstString uniformName)
54 {
55   auto iter = std::find_if(mUniformMaps.Begin(),
56                            mUniformMaps.End(),
57                            [&](auto& element) { return element.uniformName == uniformName; });
58
59   if(iter != mUniformMaps.End())
60   {
61     mUniformMaps.Erase(iter);
62     MappingChanged();
63   }
64 }
65
66 const PropertyInputImpl* UniformMap::Find(ConstString uniformName)
67 {
68   auto iter = std::find_if(mUniformMaps.Begin(),
69                            mUniformMaps.End(),
70                            [&](auto& element) { return element.uniformName == uniformName; });
71
72   return (iter != mUniformMaps.End()) ? (*iter).propertyPtr : nullptr;
73 }
74
75 UniformMap::SizeType UniformMap::Count() const
76 {
77   return static_cast<UniformMap::SizeType>(mUniformMaps.Count());
78 }
79
80 const UniformPropertyMapping& UniformMap::operator[](UniformMap::SizeType index) const
81 {
82   return mUniformMaps[index];
83 }
84
85 } // namespace SceneGraph
86 } // namespace Internal
87 } // namespace Dali