/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
*/
#include "dali-scene-loader/public-api/parse-renderer-state.h"
-#include "dali/devel-api/common/map-wrapper.h"
#include <cstring>
+#include "dali/devel-api/common/map-wrapper.h"
namespace Dali
{
{
namespace
{
-
std::map<std::string_view, Type> COMPARISONS{
-#define DECL_COMPARISON(x) { #x, Comparison::x }
+#define DECL_COMPARISON(x) {#x, Comparison::x}
DECL_COMPARISON(NEVER),
DECL_COMPARISON(ALWAYS),
DECL_COMPARISON(LESS),
{
Type value = 0x0;
auto iFind = COMPARISONS.find(str);
- if (iFind != COMPARISONS.end())
+ if(iFind != COMPARISONS.end())
{
value = iFind->second;
}
}
std::map<std::string_view, Type> BLEND_FACTORS{
-#define DECL_BLEND_FACTOR(x) { #x, SceneLoader::BlendFactor::x }
+#define DECL_BLEND_FACTOR(x) {#x, SceneLoader::BlendFactor::x}
DECL_BLEND_FACTOR(ZERO),
DECL_BLEND_FACTOR(ONE),
DECL_BLEND_FACTOR(SRC_COLOR),
{
Type value = 0x0;
auto iFind = BLEND_FACTORS.find(str);
- if (iFind != BLEND_FACTORS.end())
+ if(iFind != BLEND_FACTORS.end())
{
value = iFind->second << (BLEND_FACTOR_BASE_SHIFT + BLEND_FACTOR_ITEM_BITS * item);
}
}
std::map<std::string_view, Type> BUFFER_MODES{
-#define DECL_BUFFER_MODE(x) { #x, BufferMode::x }
+#define DECL_BUFFER_MODE(x) {#x, BufferMode::x}
DECL_BUFFER_MODE(NONE),
DECL_BUFFER_MODE(AUTO),
DECL_BUFFER_MODE(COLOR),
{
Type value = 0x0;
auto iFind = BUFFER_MODES.find(str);
- if (iFind != BUFFER_MODES.end())
+ if(iFind != BUFFER_MODES.end())
{
value = iFind->second << BUFFER_MODE_SHIFT;
}
return value;
}
-std::map<std::string_view, Type(*)(const std::string_view&)> RENDERER_STATE_PROCESSORS{
- { "DEPTH_WRITE", [](const std::string_view&) -> Type { return DEPTH_WRITE; } },
- { "DEPTH_TEST", [](const std::string_view&) -> Type { return DEPTH_TEST; } },
- { "CULL_FRONT", [](const std::string_view&) -> Type { return CULL_FRONT; } },
- { "CULL_BACK", [](const std::string_view&) -> Type { return CULL_BACK; } },
- { "ALPHA_BLEND", [](const std::string_view&) -> Type { return ALPHA_BLEND; } },
- { "DEPTH_FUNC", [](const std::string_view& arg) -> Type {
- Type value = (arg[0] == ':') ?
- (InterpretComparison(std::string_view(arg.data() + 1, arg.size() - 1)) << DEPTH_FUNCTION_SHIFT) : 0x0;
- return value;
- } },
- { "BLEND_SRC_RGB", [](const std::string_view& arg) -> Type {
- Type value = (arg[0] == ':') ? InterpretBlendFactor(std::string_view(arg.data() + 1, arg.size() - 1), 0) : 0x0;
- return value;
- }},
- { "BLEND_DST_RGB", [](const std::string_view& arg) -> Type {
- Type value = (arg[0] == ':') ? InterpretBlendFactor(std::string_view(arg.data() + 1, arg.size() - 1), 1) : 0x0;
- return value;
- }},
- { "BLEND_SRC_ALPHA", [](const std::string_view& arg) -> Type {
- Type value = (arg[0] == ':') ? InterpretBlendFactor(std::string_view(arg.data() + 1, arg.size() - 1), 2) : 0x0;
- return value;
- }},
- { "BLEND_DST_ALPHA", [](const std::string_view& arg) -> Type {
- Type value = (arg[0] == ':') ? InterpretBlendFactor(std::string_view(arg.data() + 1, arg.size() - 1), 3) : 0x0;
- return value;
- }},
- { "BUFFER_MODE", [](const std::string_view& arg) -> Type {
- Type value = (arg[0] == ':') ? InterpretBufferMode(std::string_view(arg.data() + 1, arg.size() - 1)) : 0x0;
- return value;
- }},
+std::map<std::string_view, Type (*)(const std::string_view&)> RENDERER_STATE_PROCESSORS{
+ {"DEPTH_WRITE", [](const std::string_view&) -> Type { return DEPTH_WRITE; }},
+ {"DEPTH_TEST", [](const std::string_view&) -> Type { return DEPTH_TEST; }},
+ {"CULL_FRONT", [](const std::string_view&) -> Type { return CULL_FRONT; }},
+ {"CULL_BACK", [](const std::string_view&) -> Type { return CULL_BACK; }},
+ {"ALPHA_BLEND", [](const std::string_view&) -> Type { return ALPHA_BLEND; }},
+ {"DEPTH_FUNC", [](const std::string_view& arg) -> Type {
+ Type value = (arg[0] == ':') ? (InterpretComparison(std::string_view(arg.data() + 1, arg.size() - 1)) << DEPTH_FUNCTION_SHIFT) : 0x0;
+ return value;
+ }},
+ {"BLEND_SRC_RGB", [](const std::string_view& arg) -> Type {
+ Type value = (arg[0] == ':') ? InterpretBlendFactor(std::string_view(arg.data() + 1, arg.size() - 1), 0) : 0x0;
+ return value;
+ }},
+ {"BLEND_DST_RGB", [](const std::string_view& arg) -> Type {
+ Type value = (arg[0] == ':') ? InterpretBlendFactor(std::string_view(arg.data() + 1, arg.size() - 1), 1) : 0x0;
+ return value;
+ }},
+ {"BLEND_SRC_ALPHA", [](const std::string_view& arg) -> Type {
+ Type value = (arg[0] == ':') ? InterpretBlendFactor(std::string_view(arg.data() + 1, arg.size() - 1), 2) : 0x0;
+ return value;
+ }},
+ {"BLEND_DST_ALPHA", [](const std::string_view& arg) -> Type {
+ Type value = (arg[0] == ':') ? InterpretBlendFactor(std::string_view(arg.data() + 1, arg.size() - 1), 3) : 0x0;
+ return value;
+ }},
+ {"BUFFER_MODE", [](const std::string_view& arg) -> Type {
+ Type value = (arg[0] == ':') ? InterpretBufferMode(std::string_view(arg.data() + 1, arg.size() - 1)) : 0x0;
+ return value;
+ }},
};
-}
+} // namespace
Type Parse(const char* string, size_t length, StringCallback onError)
{
- if (length == 0)
+ if(length == 0)
{
length = strlen(string);
}
Type value = 0x0;
- auto iEnd = string + length;
- while (string != iEnd)
+ auto iEnd = string + length;
+ while(string != iEnd)
{
auto iNextToken = std::find(string, iEnd, '|');
- auto iColon = std::find(string, iNextToken, ':');
- auto i = RENDERER_STATE_PROCESSORS.find(std::string_view(string, iColon - string));
- if (i != RENDERER_STATE_PROCESSORS.end() && size_t(std::distance(string, iNextToken)) >= i->first.size())
+ auto iColon = std::find(string, iNextToken, ':');
+ auto i = RENDERER_STATE_PROCESSORS.find(std::string_view(string, iColon - string));
+ if(i != RENDERER_STATE_PROCESSORS.end() && size_t(std::distance(string, iNextToken)) >= i->first.size())
{
value |= i->second(std::string_view(string + i->first.size(), iNextToken - iColon));
}
return value;
}
-} // RendererState
-}
-}
+} // namespace RendererState
+} // namespace SceneLoader
+} // namespace Dali