Variant.hpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*************************************************************************/
  2. /* Variant.hpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef VARIANT_H
  31. #define VARIANT_H
  32. #include <gdnative/variant.h>
  33. #include "Defs.hpp"
  34. #include "AABB.hpp"
  35. #include "Basis.hpp"
  36. #include "Color.hpp"
  37. #include "NodePath.hpp"
  38. #include "Plane.hpp"
  39. #include "PoolArrays.hpp"
  40. #include "Quat.hpp"
  41. #include "RID.hpp"
  42. #include "Rect2.hpp"
  43. #include "String.hpp"
  44. #include "Transform.hpp"
  45. #include "Transform2D.hpp"
  46. #include "Vector2.hpp"
  47. #include "Vector3.hpp"
  48. namespace godot {
  49. class Dictionary;
  50. class Array;
  51. class Variant {
  52. godot_variant _godot_variant;
  53. friend class Array;
  54. inline explicit Variant(godot_variant v) {
  55. _godot_variant = v;
  56. }
  57. public:
  58. enum Type {
  59. NIL,
  60. // atomic types
  61. BOOL,
  62. INT,
  63. REAL,
  64. STRING,
  65. // math types
  66. VECTOR2, // 5
  67. RECT2,
  68. VECTOR3,
  69. TRANSFORM2D,
  70. PLANE,
  71. QUAT, // 10
  72. RECT3, //sorry naming convention fail :( not like it's used often
  73. BASIS,
  74. TRANSFORM,
  75. // misc types
  76. COLOR,
  77. NODE_PATH, // 15
  78. _RID,
  79. OBJECT,
  80. DICTIONARY,
  81. ARRAY,
  82. // arrays
  83. POOL_BYTE_ARRAY, // 20
  84. POOL_INT_ARRAY,
  85. POOL_REAL_ARRAY,
  86. POOL_STRING_ARRAY,
  87. POOL_VECTOR2_ARRAY,
  88. POOL_VECTOR3_ARRAY, // 25
  89. POOL_COLOR_ARRAY,
  90. VARIANT_MAX
  91. };
  92. enum Operator {
  93. //comparation
  94. OP_EQUAL,
  95. OP_NOT_EQUAL,
  96. OP_LESS,
  97. OP_LESS_EQUAL,
  98. OP_GREATER,
  99. OP_GREATER_EQUAL,
  100. //mathematic
  101. OP_ADD,
  102. OP_SUBSTRACT,
  103. OP_MULTIPLY,
  104. OP_DIVIDE,
  105. OP_NEGATE,
  106. OP_POSITIVE,
  107. OP_MODULE,
  108. OP_STRING_CONCAT,
  109. //bitwise
  110. OP_SHIFT_LEFT,
  111. OP_SHIFT_RIGHT,
  112. OP_BIT_AND,
  113. OP_BIT_OR,
  114. OP_BIT_XOR,
  115. OP_BIT_NEGATE,
  116. //logic
  117. OP_AND,
  118. OP_OR,
  119. OP_XOR,
  120. OP_NOT,
  121. //containment
  122. OP_IN,
  123. OP_MAX
  124. };
  125. Variant();
  126. Variant(const Variant &v);
  127. Variant(bool p_bool);
  128. Variant(signed int p_int);
  129. Variant(unsigned int p_int);
  130. Variant(signed short p_short);
  131. inline Variant(unsigned short p_short) :
  132. Variant((unsigned int)p_short) {}
  133. inline Variant(signed char p_char) :
  134. Variant((signed int)p_char) {}
  135. inline Variant(unsigned char p_char) :
  136. Variant((unsigned int)p_char) {}
  137. Variant(int64_t p_char);
  138. Variant(uint64_t p_char);
  139. Variant(float p_float);
  140. Variant(double p_double);
  141. Variant(const String &p_string);
  142. Variant(const char *const p_cstring);
  143. Variant(const wchar_t *p_wstring);
  144. Variant(const Vector2 &p_vector2);
  145. Variant(const Rect2 &p_rect2);
  146. Variant(const Vector3 &p_vector3);
  147. Variant(const Plane &p_plane);
  148. Variant(const AABB &p_aabb);
  149. Variant(const Quat &p_quat);
  150. Variant(const Basis &p_transform);
  151. Variant(const Transform2D &p_transform);
  152. Variant(const Transform &p_transform);
  153. Variant(const Color &p_color);
  154. Variant(const NodePath &p_path);
  155. Variant(const RID &p_rid);
  156. Variant(const Object *p_object);
  157. Variant(const Dictionary &p_dictionary);
  158. Variant(const Array &p_array);
  159. Variant(const PoolByteArray &p_raw_array);
  160. Variant(const PoolIntArray &p_int_array);
  161. Variant(const PoolRealArray &p_real_array);
  162. Variant(const PoolStringArray &p_string_array);
  163. Variant(const PoolVector2Array &p_vector2_array);
  164. Variant(const PoolVector3Array &p_vector3_array);
  165. Variant(const PoolColorArray &p_color_array);
  166. Variant &operator=(const Variant &v);
  167. operator bool() const;
  168. operator signed int() const;
  169. operator unsigned int() const;
  170. operator signed short() const;
  171. operator unsigned short() const;
  172. operator signed char() const;
  173. operator unsigned char() const;
  174. operator int64_t() const;
  175. operator uint64_t() const;
  176. operator wchar_t() const;
  177. operator float() const;
  178. operator double() const;
  179. operator String() const;
  180. operator Vector2() const;
  181. operator Rect2() const;
  182. operator Vector3() const;
  183. operator Plane() const;
  184. operator AABB() const;
  185. operator Quat() const;
  186. operator Basis() const;
  187. operator Transform() const;
  188. operator Transform2D() const;
  189. operator Color() const;
  190. operator NodePath() const;
  191. operator RID() const;
  192. operator godot_object *() const;
  193. template <typename T>
  194. operator T *() const { return static_cast<T *>(T::___get_from_variant(*this)); }
  195. operator Dictionary() const;
  196. operator Array() const;
  197. operator PoolByteArray() const;
  198. operator PoolIntArray() const;
  199. operator PoolRealArray() const;
  200. operator PoolStringArray() const;
  201. operator PoolVector2Array() const;
  202. operator PoolVector3Array() const;
  203. operator PoolColorArray() const;
  204. Type get_type() const;
  205. Variant call(const String &method, const Variant **args, const int arg_count);
  206. bool has_method(const String &method);
  207. bool operator==(const Variant &b) const;
  208. bool operator!=(const Variant &b) const;
  209. bool operator<(const Variant &b) const;
  210. bool operator<=(const Variant &b) const;
  211. bool operator>(const Variant &b) const;
  212. bool operator>=(const Variant &b) const;
  213. bool hash_compare(const Variant &b) const;
  214. bool booleanize() const;
  215. ~Variant();
  216. };
  217. } // namespace godot
  218. #endif // VARIANT_H