plugify  1.0.0.0
value_type.hpp
1 #pragma once
2 
3 #include <cstdint>
4 #include <vector>
5 #include <memory>
6 #include <optional>
7 #include <string_view>
8 
9 namespace plugify {
14  enum class ValueType : uint8_t {
15  Invalid,
16 
17  // C types
18  Void,
19  Bool,
20  Char8,
21  Char16,
22  Int8,
23  Int16,
24  Int32,
25  Int64,
26  UInt8,
27  UInt16,
28  UInt32,
29  UInt64,
30  Pointer,
31  Float,
32  Double,
33 
34  Function,
35 
36  // Objects
37  String,
38  Any,
39 
40  ArrayBool,
41  ArrayChar8,
42  ArrayChar16,
43  ArrayInt8,
44  ArrayInt16,
45  ArrayInt32,
46  ArrayInt64,
47  ArrayUInt8,
48  ArrayUInt16,
49  ArrayUInt32,
50  ArrayUInt64,
51  ArrayPointer,
52  ArrayFloat,
53  ArrayDouble,
54  ArrayString,
55  ArrayAny,
56  ArrayVector2,
57  ArrayVector3,
58  ArrayVector4,
59  ArrayMatrix4x4,
60 
61  // Structs
62  Vector2,
63  Vector3,
64  Vector4,
65 
66  Matrix4x4,
67  //Matrix2x2,
68  //Matrix2x3,
69  //Matrix2x4,
70  //Matrix3x2,
71  //Matrix3x3,
72  //Matrix3x4,
73  //Matrix4x2,
74  //Matrix4x3,
75 
77 
78  _BaseStart = Void,
79  _BaseEnd = Function,
80 
81  _FloatStart = Float,
82  _FloatEnd = Double,
83 
84  _ObjectStart = String,
85  _ObjectEnd = ArrayMatrix4x4,
86 
87  _ArrayStart = ArrayBool,
88  _ArrayEnd = ArrayMatrix4x4,
89 
90  _StructStart = Vector2,
91  _StructEnd = Matrix4x4,
92 
93  // First struct which return as hidden parameter
94 #if _WIN32 && !_M_ARM64
95  _HiddenParamStart = Vector3,
96 #else
97  _HiddenParamStart = Matrix4x4,
98 #endif
99  _LastAssigned = Matrix4x4,
100  };
101 
105  namespace ValueName {
106  static constexpr std::string_view Void = "void";
107  static constexpr std::string_view Bool = "bool";
108  static constexpr std::string_view Char8 = "char8";
109  static constexpr std::string_view Char16 = "char16";
110  static constexpr std::string_view Int8 = "int8";
111  static constexpr std::string_view Int16 = "int16";
112  static constexpr std::string_view Int32 = "int32";
113  static constexpr std::string_view Int64 = "int64";
114  static constexpr std::string_view UInt8 = "uint8";
115  static constexpr std::string_view UInt16 = "uint16";
116  static constexpr std::string_view UInt32 = "uint32";
117  static constexpr std::string_view UInt64 = "uint64";
118  static constexpr std::string_view Float = "float";
119  static constexpr std::string_view Double = "double";
120  static constexpr std::string_view Function = "function";
121  static constexpr std::string_view String = "string";
122  static constexpr std::string_view Any = "any";
123  static constexpr std::string_view ArrayBool = "bool[]";
124  static constexpr std::string_view ArrayChar8 = "char8[]";
125  static constexpr std::string_view ArrayChar16 = "char16[]";
126  static constexpr std::string_view ArrayInt8 = "int8[]";
127  static constexpr std::string_view ArrayInt16 = "int16[]";
128  static constexpr std::string_view ArrayInt32 = "int32[]";
129  static constexpr std::string_view ArrayInt64 = "int64[]";
130  static constexpr std::string_view ArrayUInt8 = "uint8[]";
131  static constexpr std::string_view ArrayUInt16 = "uint16[]";
132  static constexpr std::string_view ArrayUInt32 = "uint32[]";
133  static constexpr std::string_view ArrayUInt64 = "uint64[]";
134  static constexpr std::string_view ArrayFloat = "float[]";
135  static constexpr std::string_view ArrayDouble = "double[]";
136  static constexpr std::string_view ArrayString = "string[]";
137  static constexpr std::string_view ArrayAny = "any[]";
138  static constexpr std::string_view ArrayVector2 = "vec2[]";
139  static constexpr std::string_view ArrayVector3 = "vec3[]";
140  static constexpr std::string_view ArrayVector4 = "vec4[]";
141  static constexpr std::string_view ArrayMatrix4x4 = "mat4x4[]";
142  static constexpr std::string_view Vector2 = "vec2";
143  static constexpr std::string_view Vector3 = "vec3";
144  static constexpr std::string_view Vector4 = "vec4";
145  static constexpr std::string_view Matrix4x4 = "mat4x4";
146  static constexpr std::string_view Invalid = "invalid";
147 #if INTPTR_MAX == INT32_MAX
148  static constexpr std::string_view Pointer = "ptr32";
149  static constexpr std::string_view ArrayPointer = "ptr32[]";
150 #elif INTPTR_MAX == INT64_MAX
151  static constexpr std::string_view Pointer = "ptr64";
152  static constexpr std::string_view ArrayPointer = "ptr64[]";
153 #else
154  #error "Environment not 32 or 64-bit."
155 #endif
156  }
157 
161  namespace ValueUtils {
171  template<typename T>
172  constexpr bool IsBetween(T x, T a, T b) noexcept {
173  return x >= a && x <= b;
174  }
175 
182  constexpr bool IsVoid(ValueType type) noexcept { return type == ValueType::Void; }
183 
190  constexpr bool IsValid(ValueType type) noexcept { return IsBetween(type, ValueType::Void, ValueType::_LastAssigned); }
191 
198  constexpr bool IsScalar(ValueType type) noexcept { return IsBetween(type, ValueType::_BaseStart, ValueType::_BaseEnd); }
199 
206  constexpr bool IsFloating(ValueType type) noexcept { return IsBetween(type, ValueType::_FloatStart, ValueType::_FloatEnd); }
207 
214  constexpr bool IsBool(ValueType type) noexcept { return type == ValueType::Bool; }
215 
222  constexpr bool IsChar8(ValueType type) noexcept { return type == ValueType::Char8; }
223 
230  constexpr bool IsChar16(ValueType type) noexcept { return type == ValueType::Char16; }
231 
238  constexpr bool IsInt8(ValueType type) noexcept { return type == ValueType::Int8; }
239 
246  constexpr bool IsUInt8(ValueType type) noexcept { return type == ValueType::UInt8; }
247 
254  constexpr bool IsInt16(ValueType type) noexcept { return type == ValueType::Int16; }
255 
262  constexpr bool IsUInt16(ValueType type) noexcept { return type == ValueType::UInt16; }
263 
270  constexpr bool IsInt32(ValueType type) noexcept { return type == ValueType::Int32; }
271 
278  constexpr bool IsUInt32(ValueType type) noexcept { return type == ValueType::UInt32; }
279 
286  constexpr bool IsInt64(ValueType type) noexcept { return type == ValueType::Int64; }
287 
294  constexpr bool IsUInt64(ValueType type) noexcept { return type == ValueType::UInt64; }
295 
302  constexpr bool IsPointer(ValueType type) noexcept { return type == ValueType::Pointer; }
303 
310  constexpr bool IsFloat(ValueType type) noexcept { return type == ValueType::Float; }
311 
318  constexpr bool IsDouble(ValueType type) noexcept { return type == ValueType::Double; }
319 
326  constexpr bool IsFunction(ValueType type) noexcept { return type == ValueType::Function; }
327 
334  constexpr bool IsString(ValueType type) noexcept { return type == ValueType::String; }
335 
342  constexpr bool IsAny(ValueType type) noexcept { return type == ValueType::Any; }
343 
350  constexpr bool IsObject(ValueType type) noexcept { return IsBetween(type, ValueType::_ObjectStart, ValueType::_ObjectEnd); }
351 
358  constexpr bool IsArray(ValueType type) noexcept { return IsBetween(type, ValueType::_ArrayStart, ValueType::_ArrayEnd); }
359 
366  constexpr bool IsStruct(ValueType type) noexcept { return IsBetween(type, ValueType::_StructStart, ValueType::_StructEnd); }
367 
368 
379  constexpr bool IsHiddenParam(ValueType type) noexcept {
380  return IsObject(type) || IsBetween(type, ValueType::_HiddenParamStart, ValueType::_StructEnd);
381  }
382 
388  constexpr std::string_view ToString(ValueType value) noexcept {
389  switch (value) {
390  case ValueType::Void: return ValueName::Void;
391  case ValueType::Bool: return ValueName::Bool;
392  case ValueType::Char8: return ValueName::Char8;
393  case ValueType::Char16: return ValueName::Char16;
394  case ValueType::Int8: return ValueName::Int8;
395  case ValueType::Int16: return ValueName::Int16;
396  case ValueType::Int32: return ValueName::Int32;
397  case ValueType::Int64: return ValueName::Int64;
398  case ValueType::UInt8: return ValueName::UInt8;
399  case ValueType::UInt16: return ValueName::UInt16;
400  case ValueType::UInt32: return ValueName::UInt32;
401  case ValueType::UInt64: return ValueName::UInt64;
402  case ValueType::Pointer: return ValueName::Pointer;
403  case ValueType::Float: return ValueName::Float;
404  case ValueType::Double: return ValueName::Double;
405  case ValueType::Function: return ValueName::Function;
406  case ValueType::String: return ValueName::String;
407  case ValueType::Any: return ValueName::Any;
408  case ValueType::ArrayBool: return ValueName::ArrayBool;
409  case ValueType::ArrayChar8: return ValueName::ArrayChar8;
410  case ValueType::ArrayChar16: return ValueName::ArrayChar16;
411  case ValueType::ArrayInt8: return ValueName::ArrayInt8;
412  case ValueType::ArrayInt16: return ValueName::ArrayInt16;
413  case ValueType::ArrayInt32: return ValueName::ArrayInt32;
414  case ValueType::ArrayInt64: return ValueName::ArrayInt64;
415  case ValueType::ArrayUInt8: return ValueName::ArrayUInt8;
416  case ValueType::ArrayUInt16: return ValueName::ArrayUInt16;
417  case ValueType::ArrayUInt32: return ValueName::ArrayUInt32;
418  case ValueType::ArrayUInt64: return ValueName::ArrayUInt64;
419  case ValueType::ArrayPointer: return ValueName::ArrayPointer;
420  case ValueType::ArrayFloat: return ValueName::ArrayFloat;
421  case ValueType::ArrayDouble: return ValueName::ArrayDouble;
422  case ValueType::ArrayString: return ValueName::ArrayString;
423  case ValueType::ArrayAny: return ValueName::ArrayAny;
424  case ValueType::ArrayVector2: return ValueName::ArrayVector2;
425  case ValueType::ArrayVector3: return ValueName::ArrayVector3;
426  case ValueType::ArrayVector4: return ValueName::ArrayVector4;
427  case ValueType::ArrayMatrix4x4: return ValueName::ArrayMatrix4x4;
428  case ValueType::Vector2: return ValueName::Vector2;
429  case ValueType::Vector3: return ValueName::Vector3;
430  case ValueType::Vector4: return ValueName::Vector4;
431  case ValueType::Matrix4x4: return ValueName::Matrix4x4;
432  default: return ValueName::Invalid;
433  }
434  }
435 
441  constexpr ValueType FromString(std::string_view value) noexcept {
442  if (value == ValueName::Void) {
443  return ValueType::Void;
444  } else if (value == ValueName::Bool) {
445  return ValueType::Bool;
446  } else if (value == ValueName::Char8) {
447  return ValueType::Char8;
448  } else if (value == ValueName::Char16) {
449  return ValueType::Char16;
450  } else if (value == ValueName::Int8) {
451  return ValueType::Int8;
452  } else if (value == ValueName::Int16) {
453  return ValueType::Int16;
454  } else if (value == ValueName::Int32) {
455  return ValueType::Int32;
456  } else if (value == ValueName::Int64) {
457  return ValueType::Int64;
458  } else if (value == ValueName::UInt8) {
459  return ValueType::UInt8;
460  } else if (value == ValueName::UInt16) {
461  return ValueType::UInt16;
462  } else if (value == ValueName::UInt32) {
463  return ValueType::UInt32;
464  } else if (value == ValueName::UInt64) {
465  return ValueType::UInt64;
466  } else if (value == ValueName::Pointer) {
467  return ValueType::Pointer;
468  } else if (value == ValueName::Float) {
469  return ValueType::Float;
470  } else if (value == ValueName::Double) {
471  return ValueType::Double;
472  } else if (value == ValueName::Function) {
473  return ValueType::Function;
474  } else if (value == ValueName::String) {
475  return ValueType::String;
476  } else if (value == ValueName::Any) {
477  return ValueType::Any;
478  } else if (value == ValueName::ArrayBool) {
479  return ValueType::ArrayBool;
480  } else if (value == ValueName::ArrayChar8) {
481  return ValueType::ArrayChar8;
482  } else if (value == ValueName::ArrayChar16) {
483  return ValueType::ArrayChar16;
484  } else if (value == ValueName::ArrayInt8) {
485  return ValueType::ArrayInt8;
486  } else if (value == ValueName::ArrayInt16) {
487  return ValueType::ArrayInt16;
488  } else if (value == ValueName::ArrayInt32) {
489  return ValueType::ArrayInt32;
490  } else if (value == ValueName::ArrayInt64) {
491  return ValueType::ArrayInt64;
492  } else if (value == ValueName::ArrayUInt8) {
493  return ValueType::ArrayUInt8;
494  } else if (value == ValueName::ArrayUInt16) {
495  return ValueType::ArrayUInt16;
496  } else if (value == ValueName::ArrayUInt32) {
497  return ValueType::ArrayUInt32;
498  } else if (value == ValueName::ArrayUInt64) {
499  return ValueType::ArrayUInt64;
500  } else if (value == ValueName::ArrayPointer) {
501  return ValueType::ArrayPointer;
502  } else if (value == ValueName::ArrayFloat) {
503  return ValueType::ArrayFloat;
504  } else if (value == ValueName::ArrayDouble) {
505  return ValueType::ArrayDouble;
506  } else if (value == ValueName::ArrayString) {
507  return ValueType::ArrayString;
508  } else if (value == ValueName::ArrayAny) {
509  return ValueType::ArrayAny;
510  } else if (value == ValueName::ArrayVector2) {
511  return ValueType::ArrayVector2;
512  } else if (value == ValueName::ArrayVector3) {
513  return ValueType::ArrayVector3;
514  } else if (value == ValueName::ArrayVector4) {
515  return ValueType::ArrayVector4;
516  } else if (value == ValueName::ArrayMatrix4x4) {
517  return ValueType::ArrayMatrix4x4;
518  } else if (value == ValueName::Vector2) {
519  return ValueType::Vector2;
520  } else if (value == ValueName::Vector3) {
521  return ValueType::Vector3;
522  } else if (value == ValueName::Vector4) {
523  return ValueType::Vector4;
524  } else if (value == ValueName::Matrix4x4) {
525  return ValueType::Matrix4x4;
526  }
527  return ValueType::Invalid;
528  }
529  } // namespace ValueUtils
530 
531 } // namespace plugify
constexpr bool IsBool(ValueType type) noexcept
Tests whether a given type is a 1-bit boolean.
Definition: value_type.hpp:214
constexpr bool IsDouble(ValueType type) noexcept
Tests whether a given type is a double.
Definition: value_type.hpp:318
constexpr bool IsChar16(ValueType type) noexcept
Tests whether a given type is a 16-bit character.
Definition: value_type.hpp:230
constexpr bool IsFloating(ValueType type) noexcept
Tests whether a given type is a scalar floating point of any size.
Definition: value_type.hpp:206
constexpr bool IsAny(ValueType type) noexcept
Tests whether a given type is an any.
Definition: value_type.hpp:342
constexpr bool IsVoid(ValueType type) noexcept
Tests whether a given type is ValueType::Void.
Definition: value_type.hpp:182
constexpr bool IsChar8(ValueType type) noexcept
Tests whether a given type is an 8-bit character.
Definition: value_type.hpp:222
constexpr bool IsBetween(T x, T a, T b) noexcept
Checks if a value is between two other values.
Definition: value_type.hpp:172
constexpr bool IsUInt32(ValueType type) noexcept
Tests whether a given type is a 32-bit unsigned integer.
Definition: value_type.hpp:278
constexpr bool IsString(ValueType type) noexcept
Tests whether a given type is a string.
Definition: value_type.hpp:334
constexpr bool IsUInt8(ValueType type) noexcept
Tests whether a given type is an 8-bit unsigned integer.
Definition: value_type.hpp:246
constexpr bool IsStruct(ValueType type) noexcept
Tests whether a given type is a POD (plain old data) structure of any size.
Definition: value_type.hpp:366
constexpr bool IsFloat(ValueType type) noexcept
Tests whether a given type is a float.
Definition: value_type.hpp:310
constexpr std::string_view ToString(ValueType value) noexcept
Convert a ValueType enum value to its string representation.
Definition: value_type.hpp:388
constexpr bool IsPointer(ValueType type) noexcept
Tests whether a given type is a pointer.
Definition: value_type.hpp:302
constexpr bool IsValid(ValueType type) noexcept
Tests whether a given type is a valid non-void type.
Definition: value_type.hpp:190
constexpr bool IsScalar(ValueType type) noexcept
Tests whether a given type is scalar (has no vector part).
Definition: value_type.hpp:198
constexpr bool IsInt64(ValueType type) noexcept
Tests whether a given type is a 64-bit integer.
Definition: value_type.hpp:286
constexpr bool IsFunction(ValueType type) noexcept
Tests whether a given type is a C-function pointer.
Definition: value_type.hpp:326
constexpr bool IsUInt16(ValueType type) noexcept
Tests whether a given type is a 16-bit unsigned integer.
Definition: value_type.hpp:262
constexpr bool IsObject(ValueType type) noexcept
Tests whether a given type is an object of any size.
Definition: value_type.hpp:350
constexpr ValueType FromString(std::string_view value) noexcept
Convert a string representation to a ValueType enum value.
Definition: value_type.hpp:441
constexpr bool IsInt16(ValueType type) noexcept
Tests whether a given type is a 16-bit integer.
Definition: value_type.hpp:254
constexpr bool IsInt32(ValueType type) noexcept
Tests whether a given type is a 32-bit integer.
Definition: value_type.hpp:270
constexpr bool IsInt8(ValueType type) noexcept
Tests whether a given type is an 8-bit integer.
Definition: value_type.hpp:238
constexpr bool IsArray(ValueType type) noexcept
Tests whether a given type is an array of any size.
Definition: value_type.hpp:358
constexpr bool IsUInt64(ValueType type) noexcept
Tests whether a given type is a 64-bit unsigned integer.
Definition: value_type.hpp:294
constexpr bool IsHiddenParam(ValueType type) noexcept
Checks if a given ValueType is considered a hidden object parameter.
Definition: value_type.hpp:379