Cogs.Core
ValueVariant.h
1#pragma once
2
3#include "Base.h"
4
5#include "Foundation/StringView.h"
6
7#include <glm/glm.hpp>
8
9namespace Cogs::Core
10{
11 enum class ParsedDataType
12 {
13 Unknown = 0,
14 Object,
15 String,
16 Float,
17 Float2,
18 Float3,
19 Float4,
20 Float4x4,
21 Int,
22 Int2,
23 Int3,
24 Int4,
25 UInt,
26 UInt2,
27 UInt3,
28 UInt4,
29 Bool,
30 Double,
31 Number = Double,
32 Texture2D,
33 ConstantBuffer,
34 Buffer,
35 Count
36 };
37
38 struct COGSCORE_DLL_API ValueVariant
39 {
40 ValueVariant() : float4x4Value(0.f) {};
41 ValueVariant( const ValueVariant& original);
42 explicit ValueVariant(float value) : floatValue(value), type(ParsedDataType::Float) {}
43 explicit ValueVariant(bool value) : boolValue(value), type(ParsedDataType::Bool) {}
44 explicit ValueVariant(double value) : doubleValue(value), type(ParsedDataType::Double) {}
45 explicit ValueVariant(int value) : intValue(value), type(ParsedDataType::Int) {}
46 explicit ValueVariant(const char * value) : float4x4Value(0.f), stringValue(value), type(ParsedDataType::String) {}
47 explicit ValueVariant(const StringView & value) : float4x4Value(0.f), stringValue(value.to_string()), type(ParsedDataType::String) {}
48 explicit ValueVariant(glm::vec2 value) : float2Value(value), type(ParsedDataType::Float2) {}
49 explicit ValueVariant(glm::vec3 value) : float3Value(value), type(ParsedDataType::Float3) {}
50 explicit ValueVariant(glm::vec4 value) : float4Value(value), type(ParsedDataType::Float4) {}
51
52 bool isNumericType(ParsedDataType type) const;
53 bool isNumeric() const { return isNumericType(type); }
54 bool isFloat() const { return isNumeric(); }
55
56 float getFloat(float defaultValue = 0.0f) const;
57 double getDouble(double defaultValue = 0.0) const;
58 bool getBool(bool defaultValue = false) const;
59 int getInt(int defaultValue = false) const;
60 glm::vec2 getVec2(glm::vec2 defaultValue = {}) const;
61 glm::vec3 getVec3(glm::vec3 defaultValue = {}) const;
62 glm::vec4 getVec4(glm::vec4 defaultValue = {}) const;
63 StringView getString(StringView defaultValue) const;
64
65 ParsedDataType getType() const { return type; }
66
67 ValueVariant& operator =( const ValueVariant& rhs);
68
69 private:
70 union
71 {
72 float floatValue;
73 glm::vec2 float2Value;
74 glm::vec3 float3Value;
75 glm::vec4 float4Value;
76 glm::mat4 float4x4Value;
77 int intValue;
78 glm::ivec2 int2Value;
79 glm::ivec3 int3Value;
80 glm::ivec4 int4Value;
81 uint32_t uintValue;
82 glm::uvec2 uint2Value;
83 glm::uvec3 uint3Value;
84 glm::uvec4 uint4Value;
85 bool boolValue;
86 double doubleValue;
87 };
88
89 std::string stringValue;
90
91 ParsedDataType type = ParsedDataType::Unknown;
92 };
93}
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....