You.i Engine
YiVariant.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_VARIANT_H_
3 #define _YI_VARIANT_H_
4 
5 #include "framework/YiAny.h"
6 #include "utility/YiString.h"
7 
8 #include <glm/fwd.hpp>
9 
34 {
35 public:
39  enum class Type : uint8_t
40  {
42  Invalid,
44  Float,
46  FloatArray,
48  FloatVec2,
50  FloatVec3,
52  Integer,
56  Quaternion,
58  String
59  };
60 
64  CYIVariant() = default;
65 
69  CYIVariant(float value);
70 
74  CYIVariant(const float pValue[], uint32_t count);
75 
79  CYIVariant(std::vector<float> values);
80 
84  CYIVariant(const glm::vec2 &rvValue);
85 
89  CYIVariant(float x, float y);
90 
94  CYIVariant(const glm::vec3 &rvValue);
95 
99  CYIVariant(float x, float y, float z);
100 
104  CYIVariant(int32_t value);
105 
109  CYIVariant(const int32_t pValue[], uint32_t count);
110 
114  CYIVariant(std::vector<int32_t> values);
115 
119  CYIVariant(const glm::quat &rValue);
120 
124  explicit CYIVariant(const CYIString &rsValue);
125 
129  void Set(float value);
130 
134  void Set(const float pValue[], uint32_t count);
135 
139  void Set(std::vector<float> values);
140 
144  void Set(const glm::vec2 &rvValue);
145 
149  void Set(float x, float y);
150 
154  void Set(const glm::vec3 &rvValue);
155 
159  void Set(float x, float y, float z);
160 
164  void Set(int32_t value);
165 
169  void Set(const int32_t pValue[], uint32_t count);
170 
174  void Set(std::vector<int32_t> values);
175 
179  void Set(const glm::quat &rValue);
180 
184  void Set(const CYIString &rsValue);
185 
189  void SetInvalid();
190 
194  float GetAsFloat() const;
195 
199  const float *GetAsFloatPointer(size_t *pSize = nullptr) const;
200 
204  glm::vec2 GetAsFloatVec2() const;
205 
209  glm::vec3 GetAsFloatVec3() const;
210 
214  int32_t GetAsInt() const;
215 
219  const int32_t *GetAsIntPointer(size_t *pSize = nullptr) const;
220 
224  glm::quat GetAsQuaternion() const;
225 
229  CYIString GetAsString() const;
230 
234  bool IsValid() const;
235 
240  Type GetType() const;
241 
242  bool operator+=(const CYIVariant &rOther);
243  bool operator-=(const CYIVariant &rOther);
244  bool operator*=(const CYIVariant &rOther);
245  bool operator/=(const CYIVariant &rOther);
246  CYIVariant operator+(const CYIVariant &rOther) const;
247  CYIVariant operator-(const CYIVariant &rOther) const;
248  CYIVariant operator*(const CYIVariant &rOther) const;
249  CYIVariant operator/(const CYIVariant &rOther) const;
250 
254  CYIVariant LogOf() const;
255 
259  CYIVariant ExpOf() const;
260 
270  static void Lerp(const CYIVariant &start, const CYIVariant &end, float *pPercentages, size_t percentageCount, CYIVariant &out_variant);
271 
275  size_t GetApproximateSize() const;
276 
277 private:
278  friend bool operator==(const CYIVariant &rLHS, const CYIVariant &rRHS);
279  friend bool operator!=(const CYIVariant &rLHS, const CYIVariant &rRHS);
280 
281  CYIAny m_any;
282 };
283 
284 bool operator==(const CYIVariant &rLHS, const CYIVariant &rRHS);
285 bool operator!=(const CYIVariant &rLHS, const CYIVariant &rRHS);
286 
289 #endif // _YI_VARIANT_H_
void Set(float value)
const float * GetAsFloatPointer(size_t *pSize=nullptr) const
CYIVariant operator*(const CYIVariant &rOther) const
Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray.
A container class for common data types.
Definition: YiVariant.h:33
float GetAsFloat() const
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:36
CYIVariant LogOf() const
A class that holds instances of any type that is copy-constructible.
Definition: YiAny.h:77
size_t GetApproximateSize() const
friend bool operator==(const CYIVariant &rLHS, const CYIVariant &rRHS)
All types are supported. Two &#39;invalid&#39; variants are considered to be equal.
CYIVariant()=default
CYIVariant operator-(const CYIVariant &rOther) const
Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray.
int32_t GetAsInt() const
bool operator-=(const CYIVariant &rOther)
Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray.
CYIString GetAsString() const
bool operator*=(const CYIVariant &rOther)
Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray.
static void Lerp(const CYIVariant &start, const CYIVariant &end, float *pPercentages, size_t percentageCount, CYIVariant &out_variant)
glm::vec2 GetAsFloatVec2() const
Type
Definition: YiVariant.h:39
glm::quat GetAsQuaternion() const
void SetInvalid()
glm::vec3 GetAsFloatVec3() const
bool IsValid() const
const int32_t * GetAsIntPointer(size_t *pSize=nullptr) const
CYIVariant operator+(const CYIVariant &rOther) const
Supported types: Int, String, Float, FloatVec2, FloatVec3, FloatArray and IntArray.
CYIVariant ExpOf() const
Type GetType() const
CYIVariant operator/(const CYIVariant &rOther) const
Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray.
bool operator/=(const CYIVariant &rOther)
Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray.
bool operator+=(const CYIVariant &rOther)
Supported types: Int, String, Float, FloatVec2, FloatVec3, FloatArray and IntArray.
friend bool operator!=(const CYIVariant &rLHS, const CYIVariant &rRHS)
All types are supported. Two &#39;invalid&#39; variants are considered to be equal.