[dali_2.3.24] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / alpha-function-helper.cpp
index 1ac61ee..9c82704 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  *
  */
-#include "dali-scene3d/public-api/loader/alpha-function-helper.h"
+
+// CLASS HEADER
+#include <dali-scene3d/public-api/loader/alpha-function-helper.h>
+
+// EXTERNAL INCLUDES
 #include <unordered_map>
 
-namespace Dali
-{
-namespace Scene3D
-{
-namespace Loader
+namespace Dali::Scene3D::Loader
 {
 namespace
 {
@@ -29,22 +29,26 @@ namespace
 #define DALI_ALPHA_FUNCTION_ENTRY(x) { #x, AlphaFunction::x }
 // clang-format on
 
-std::unordered_map<std::string, AlphaFunction> sFunctions{
-  DALI_ALPHA_FUNCTION_ENTRY(DEFAULT),
-  DALI_ALPHA_FUNCTION_ENTRY(LINEAR),
-  DALI_ALPHA_FUNCTION_ENTRY(REVERSE),
-  DALI_ALPHA_FUNCTION_ENTRY(EASE_IN_SQUARE),
-  DALI_ALPHA_FUNCTION_ENTRY(EASE_OUT_SQUARE),
-  DALI_ALPHA_FUNCTION_ENTRY(EASE_IN),
-  DALI_ALPHA_FUNCTION_ENTRY(EASE_OUT),
-  DALI_ALPHA_FUNCTION_ENTRY(EASE_IN_OUT),
-  DALI_ALPHA_FUNCTION_ENTRY(EASE_IN_SINE),
-  DALI_ALPHA_FUNCTION_ENTRY(EASE_OUT_SINE),
-  DALI_ALPHA_FUNCTION_ENTRY(EASE_IN_OUT_SINE),
-  DALI_ALPHA_FUNCTION_ENTRY(BOUNCE),
-  DALI_ALPHA_FUNCTION_ENTRY(SIN),
-  DALI_ALPHA_FUNCTION_ENTRY(EASE_OUT_BACK),
-};
+std::unordered_map<std::string, AlphaFunction>& GetFunctions()
+{
+  static std::unordered_map<std::string, AlphaFunction> sFunctions{
+    DALI_ALPHA_FUNCTION_ENTRY(DEFAULT),
+    DALI_ALPHA_FUNCTION_ENTRY(LINEAR),
+    DALI_ALPHA_FUNCTION_ENTRY(REVERSE),
+    DALI_ALPHA_FUNCTION_ENTRY(EASE_IN_SQUARE),
+    DALI_ALPHA_FUNCTION_ENTRY(EASE_OUT_SQUARE),
+    DALI_ALPHA_FUNCTION_ENTRY(EASE_IN),
+    DALI_ALPHA_FUNCTION_ENTRY(EASE_OUT),
+    DALI_ALPHA_FUNCTION_ENTRY(EASE_IN_OUT),
+    DALI_ALPHA_FUNCTION_ENTRY(EASE_IN_SINE),
+    DALI_ALPHA_FUNCTION_ENTRY(EASE_OUT_SINE),
+    DALI_ALPHA_FUNCTION_ENTRY(EASE_IN_OUT_SINE),
+    DALI_ALPHA_FUNCTION_ENTRY(BOUNCE),
+    DALI_ALPHA_FUNCTION_ENTRY(SIN),
+    DALI_ALPHA_FUNCTION_ENTRY(EASE_OUT_BACK),
+  };
+  return sFunctions;
+}
 
 #undef DALI_ALPHA_FUNCTION_ENTRY
 
@@ -52,8 +56,8 @@ std::unordered_map<std::string, AlphaFunction> sFunctions{
 
 AlphaFunction GetAlphaFunction(const std::string& name, bool* found)
 {
-  auto iFind   = sFunctions.find(name);
-  bool success = iFind != sFunctions.end();
+  auto iFind   = GetFunctions().find(name);
+  bool success = iFind != GetFunctions().end();
   if(found)
   {
     *found = success;
@@ -63,10 +67,8 @@ AlphaFunction GetAlphaFunction(const std::string& name, bool* found)
 
 void RegisterAlphaFunction(const std::string& name, AlphaFunction alphaFn)
 {
-  DALI_ASSERT_ALWAYS(sFunctions.insert({name, alphaFn}).second &&
+  DALI_ASSERT_ALWAYS(GetFunctions().insert({name, alphaFn}).second &&
                      "Function with given key already exists.");
 }
 
-} // namespace Loader
-} // namespace Scene3D
-} // namespace Dali
+} // namespace Dali::Scene3D::Loader