Updated all cpp files to new format
[platform/core/uifw/dali-toolkit.git] / dali-scene-loader / public-api / alpha-function-helper.cpp
1 /*
2  * Copyright (c) 2021 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 "dali-scene-loader/public-api/alpha-function-helper.h"
18 #include <unordered_map>
19
20 namespace Dali
21 {
22 namespace SceneLoader
23 {
24 namespace
25 {
26 // clang-format off
27 #define DALI_ALPHA_FUNCTION_ENTRY(x) { #x, AlphaFunction::x }
28 // clang-format on
29
30 std::unordered_map<std::string, AlphaFunction> sFunctions{
31   DALI_ALPHA_FUNCTION_ENTRY(DEFAULT),
32   DALI_ALPHA_FUNCTION_ENTRY(LINEAR),
33   DALI_ALPHA_FUNCTION_ENTRY(REVERSE),
34   DALI_ALPHA_FUNCTION_ENTRY(EASE_IN_SQUARE),
35   DALI_ALPHA_FUNCTION_ENTRY(EASE_OUT_SQUARE),
36   DALI_ALPHA_FUNCTION_ENTRY(EASE_IN),
37   DALI_ALPHA_FUNCTION_ENTRY(EASE_OUT),
38   DALI_ALPHA_FUNCTION_ENTRY(EASE_IN_OUT),
39   DALI_ALPHA_FUNCTION_ENTRY(EASE_IN_SINE),
40   DALI_ALPHA_FUNCTION_ENTRY(EASE_OUT_SINE),
41   DALI_ALPHA_FUNCTION_ENTRY(EASE_IN_OUT_SINE),
42   DALI_ALPHA_FUNCTION_ENTRY(BOUNCE),
43   DALI_ALPHA_FUNCTION_ENTRY(SIN),
44   DALI_ALPHA_FUNCTION_ENTRY(EASE_OUT_BACK),
45 };
46
47 #undef DALI_ALPHA_FUNCTION_ENTRY
48
49 } // namespace
50
51 AlphaFunction GetAlphaFunction(const std::string& name, bool* found)
52 {
53   auto iFind   = sFunctions.find(name);
54   bool success = iFind != sFunctions.end();
55   if(found)
56   {
57     *found = success;
58   }
59   return success ? iFind->second : AlphaFunction(AlphaFunction::DEFAULT);
60 }
61
62 void RegisterAlphaFunction(const std::string& name, AlphaFunction alphaFn)
63 {
64   DALI_ASSERT_ALWAYS(sFunctions.insert({name, alphaFn}).second &&
65                      "Function with given key already exists.");
66 }
67
68 } // namespace SceneLoader
69 } // namespace Dali