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