1#include "ValueVariant.h"
3#include "Foundation/Logging/Logger.h"
5#include <glm/gtc/type_ptr.hpp>
14Cogs::Core::ValueVariant::ValueVariant(
const ValueVariant& original) : stringValue( original.stringValue ){
16 memcpy(
static_cast<void*
>(&float4x4Value), &original.float4x4Value,
sizeof(float4x4Value));
19bool Cogs::Core::ValueVariant::isNumericType(ParsedDataType type)
const
21 return type == ParsedDataType::Float ||
22 type == ParsedDataType::Double ||
23 type == ParsedDataType::Int;
26float Cogs::Core::ValueVariant::getFloat(
float defaultValue)
const
29 case ParsedDataType::Float:
32 return static_cast<float>(getDouble(defaultValue));
36double Cogs::Core::ValueVariant::getDouble(
double defaultValue)
const
39 case ParsedDataType::Bool:
40 return boolValue ? 1 : 0;
41 case ParsedDataType::Int:
42 return static_cast<double>(intValue);
43 case ParsedDataType::Float:
45 case ParsedDataType::Double:
47 case ParsedDataType::String:
48 return parseDouble(stringValue, defaultValue);
49 case ParsedDataType::Unknown:
52 LOG_WARNING(logger,
"Invalid implicit conversion from type %d to numeric.",
static_cast<int>(type));
57bool Cogs::Core::ValueVariant::getBool(
bool defaultValue)
const
60 case ParsedDataType::Bool:
62 case ParsedDataType::Int:
64 case ParsedDataType::String:
65 return parseBool(stringValue, defaultValue);
66 case ParsedDataType::Unknown:
69 LOG_WARNING(logger,
"Invalid implicit conversion from type %d to numeric.",
static_cast<int>(type));
74int Cogs::Core::ValueVariant::getInt(
int defaultValue)
const
77 case ParsedDataType::Bool:
78 return boolValue ? 1 : 0;
79 case ParsedDataType::Int:
81 case ParsedDataType::Float:
82 return (
int)floatValue;
83 case ParsedDataType::Double:
84 return (
int)doubleValue;
85 case ParsedDataType::String:
86 return parseInt(stringValue, defaultValue);
87 case ParsedDataType::Unknown:
90 LOG_WARNING(logger,
"Invalid implicit conversion from type %d to int.",
static_cast<int>(type));
95glm::vec2 Cogs::Core::ValueVariant::getVec2(glm::vec2 defaultValue)
const
98 case ParsedDataType::Float2:
100 case ParsedDataType::Float3:
101 return glm::vec2(float3Value);
102 case ParsedDataType::Float4:
103 return glm::vec2(float4Value);
104 case ParsedDataType::String:
106 glm::vec2 value = {};
107 auto tokens = split(stringValue,
",[](){}");
109 parseValues(glm::value_ptr(value), tokens, 2);
118glm::vec3 Cogs::Core::ValueVariant::getVec3(glm::vec3 defaultValue)
const
121 case ParsedDataType::Float3:
123 case ParsedDataType::Float4:
124 return glm::vec3(float4Value);
125 case ParsedDataType::String:
127 glm::vec3 value = {};
128 auto tokens = split(stringValue,
",[](){}");
130 parseValues(glm::value_ptr(value), tokens, 3);
139glm::vec4 Cogs::Core::ValueVariant::getVec4(glm::vec4 defaultValue)
const
142 case ParsedDataType::Float3:
143 return glm::vec4(float3Value, 1);
144 case ParsedDataType::Float4:
146 case ParsedDataType::String:
148 glm::vec4 value = defaultValue;
149 auto tokens = split(stringValue,
",[](){}");
151 parseValues(glm::value_ptr(value), tokens, 4);
160Cogs::StringView Cogs::Core::ValueVariant::getString(StringView defaultValue)
const
162 return type == ParsedDataType::String ? stringValue : defaultValue;
167 stringValue = rhs.stringValue;
170 case ParsedDataType::Float: floatValue = rhs.floatValue;
break;
171 case ParsedDataType::Float2: float2Value = rhs.float2Value;
break;
172 case ParsedDataType::Float3: float3Value = rhs.float3Value;
break;
173 case ParsedDataType::Float4: float4Value = rhs.float4Value;
break;
174 case ParsedDataType::Float4x4: float4x4Value = rhs.float4x4Value;
break;
175 case ParsedDataType::Int: intValue = rhs.intValue;
break;
176 case ParsedDataType::Int2: int2Value = rhs.int2Value;
break;
177 case ParsedDataType::Int3: int3Value = rhs.int3Value;
break;
178 case ParsedDataType::Int4: int4Value = rhs.int4Value;
break;
179 case ParsedDataType::UInt: uintValue = rhs.uintValue;
break;
180 case ParsedDataType::UInt2: uint2Value = rhs.uint2Value;
break;
181 case ParsedDataType::UInt3: uint3Value = rhs.uint3Value;
break;
182 case ParsedDataType::UInt4: uint4Value = rhs.uint4Value;
break;
183 case ParsedDataType::Bool: boolValue = rhs.boolValue;
break;
184 case ParsedDataType::Double: doubleValue = rhs.doubleValue;
break;
Log implementation class.
Provides a weakly referenced view over the contents of a string.
constexpr Log getLogger(const char(&name)[LEN]) noexcept