Variant.h 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Container/HashMap.h"
  24. #include "../Container/Ptr.h"
  25. #include "../Math/Color.h"
  26. #include "../Math/Matrix3.h"
  27. #include "../Math/Matrix3x4.h"
  28. #include "../Math/Rect.h"
  29. #include "../Math/StringHash.h"
  30. namespace Atomic
  31. {
  32. /// Variant's supported types.
  33. enum VariantType
  34. {
  35. VAR_NONE = 0,
  36. VAR_INT,
  37. VAR_BOOL,
  38. VAR_FLOAT,
  39. VAR_VECTOR2,
  40. VAR_VECTOR3,
  41. VAR_VECTOR4,
  42. VAR_QUATERNION,
  43. VAR_COLOR,
  44. VAR_STRING,
  45. VAR_BUFFER,
  46. VAR_VOIDPTR,
  47. VAR_RESOURCEREF,
  48. VAR_RESOURCEREFLIST,
  49. VAR_VARIANTVECTOR,
  50. VAR_VARIANTMAP,
  51. VAR_INTRECT,
  52. VAR_INTVECTOR2,
  53. VAR_PTR,
  54. VAR_MATRIX3,
  55. VAR_MATRIX3X4,
  56. VAR_MATRIX4,
  57. VAR_DOUBLE,
  58. VAR_STRINGVECTOR,
  59. VAR_RECT,
  60. VAR_INTVECTOR3,
  61. VAR_INT64,
  62. MAX_VAR_TYPES
  63. };
  64. /// Union for the possible variant values. Also stores non-POD objects such as String and math objects (excluding Matrix) which must not exceed 16 bytes in size (or 32 bytes in a 64-bit build.) Objects exceeding the limit are allocated on the heap and pointed to by _ptr.
  65. struct VariantValue
  66. {
  67. union
  68. {
  69. int int_;
  70. bool bool_;
  71. float float_;
  72. void* ptr_;
  73. };
  74. union
  75. {
  76. int int2_;
  77. float float2_;
  78. void* ptr2_;
  79. };
  80. union
  81. {
  82. int int3_;
  83. float float3_;
  84. void* ptr3_;
  85. };
  86. union
  87. {
  88. int int4_;
  89. float float4_;
  90. void* ptr4_;
  91. };
  92. };
  93. class Variant;
  94. class VectorBuffer;
  95. /// Vector of variants.
  96. typedef Vector<Variant> VariantVector;
  97. /// Vector of strings.
  98. typedef Vector<String> StringVector;
  99. /// Map of variants.
  100. typedef HashMap<StringHash, Variant> VariantMap;
  101. /// Typed resource reference.
  102. struct ATOMIC_API ResourceRef
  103. {
  104. /// Construct.
  105. ResourceRef()
  106. {
  107. }
  108. /// Construct with type only and empty id.
  109. ResourceRef(StringHash type) :
  110. type_(type)
  111. {
  112. }
  113. /// Construct with type and resource name.
  114. ResourceRef(StringHash type, const String& name) :
  115. type_(type),
  116. name_(name)
  117. {
  118. }
  119. /// Construct with type and resource name.
  120. ResourceRef(const String& type, const String& name) :
  121. type_(type),
  122. name_(name)
  123. {
  124. }
  125. /// Construct with type and resource name.
  126. ResourceRef(const char* type, const char* name) :
  127. type_(type),
  128. name_(name)
  129. {
  130. }
  131. /// Construct from another ResourceRef.
  132. ResourceRef(const ResourceRef& rhs) :
  133. type_(rhs.type_),
  134. name_(rhs.name_)
  135. {
  136. }
  137. /// Object type.
  138. StringHash type_;
  139. /// Object name.
  140. String name_;
  141. /// Test for equality with another reference.
  142. bool operator ==(const ResourceRef& rhs) const { return type_ == rhs.type_ && name_ == rhs.name_; }
  143. /// Test for inequality with another reference.
  144. bool operator !=(const ResourceRef& rhs) const { return type_ != rhs.type_ || name_ != rhs.name_; }
  145. };
  146. /// %List of typed resource references.
  147. struct ATOMIC_API ResourceRefList
  148. {
  149. /// Construct.
  150. ResourceRefList()
  151. {
  152. }
  153. /// Construct with type only.
  154. ResourceRefList(StringHash type) :
  155. type_(type)
  156. {
  157. }
  158. /// Construct with type and id list.
  159. ResourceRefList(StringHash type, const StringVector& names) :
  160. type_(type),
  161. names_(names)
  162. {
  163. }
  164. /// Object type.
  165. StringHash type_;
  166. /// List of object names.
  167. StringVector names_;
  168. /// Test for equality with another reference list.
  169. bool operator ==(const ResourceRefList& rhs) const { return type_ == rhs.type_ && names_ == rhs.names_; }
  170. /// Test for inequality with another reference list.
  171. bool operator !=(const ResourceRefList& rhs) const { return type_ != rhs.type_ || names_ != rhs.names_; }
  172. };
  173. /// Variable that supports a fixed set of types.
  174. class ATOMIC_API Variant
  175. {
  176. public:
  177. /// Construct empty.
  178. Variant() :
  179. type_(VAR_NONE)
  180. {
  181. }
  182. /// Construct from integer.
  183. Variant(int value) :
  184. type_(VAR_NONE)
  185. {
  186. *this = value;
  187. }
  188. /// Construct from 64 bit integer.
  189. Variant(long long value) :
  190. type_(VAR_NONE)
  191. {
  192. *this = value;
  193. }
  194. /// Construct from unsigned integer.
  195. Variant(unsigned value) :
  196. type_(VAR_NONE)
  197. {
  198. *this = (int)value;
  199. }
  200. /// Construct from unsigned integer.
  201. Variant(unsigned long long value) :
  202. type_(VAR_NONE)
  203. {
  204. *this = (long long)value;
  205. }
  206. /// Construct from a string hash (convert to integer).
  207. Variant(const StringHash& value) :
  208. type_(VAR_NONE)
  209. {
  210. *this = (int)value.Value();
  211. }
  212. /// Construct from a bool.
  213. Variant(bool value) :
  214. type_(VAR_NONE)
  215. {
  216. *this = value;
  217. }
  218. /// Construct from a float.
  219. Variant(float value) :
  220. type_(VAR_NONE)
  221. {
  222. *this = value;
  223. }
  224. /// Construct from a double.
  225. Variant(double value) :
  226. type_(VAR_NONE)
  227. {
  228. *this = value;
  229. }
  230. /// Construct from a Vector2.
  231. Variant(const Vector2& value) :
  232. type_(VAR_NONE)
  233. {
  234. *this = value;
  235. }
  236. /// Construct from a Vector3.
  237. Variant(const Vector3& value) :
  238. type_(VAR_NONE)
  239. {
  240. *this = value;
  241. }
  242. /// Construct from a Vector4.
  243. Variant(const Vector4& value) :
  244. type_(VAR_NONE)
  245. {
  246. *this = value;
  247. }
  248. /// Construct from a quaternion.
  249. Variant(const Quaternion& value) :
  250. type_(VAR_NONE)
  251. {
  252. *this = value;
  253. }
  254. /// Construct from a color.
  255. Variant(const Color& value) :
  256. type_(VAR_NONE)
  257. {
  258. *this = value;
  259. }
  260. /// Construct from a string.
  261. Variant(const String& value) :
  262. type_(VAR_NONE)
  263. {
  264. *this = value;
  265. }
  266. /// Construct from a C string.
  267. Variant(const char* value) :
  268. type_(VAR_NONE)
  269. {
  270. *this = value;
  271. }
  272. /// Construct from a buffer.
  273. Variant(const PODVector<unsigned char>& value) :
  274. type_(VAR_NONE)
  275. {
  276. *this = value;
  277. }
  278. /// Construct from a %VectorBuffer and store as a buffer.
  279. Variant(const VectorBuffer& value) :
  280. type_(VAR_NONE)
  281. {
  282. *this = value;
  283. }
  284. /// Construct from a pointer.
  285. Variant(void* value) :
  286. type_(VAR_NONE)
  287. {
  288. *this = value;
  289. }
  290. /// Construct from a resource reference.
  291. Variant(const ResourceRef& value) :
  292. type_(VAR_NONE)
  293. {
  294. *this = value;
  295. }
  296. /// Construct from a resource reference list.
  297. Variant(const ResourceRefList& value) :
  298. type_(VAR_NONE)
  299. {
  300. *this = value;
  301. }
  302. /// Construct from a variant vector.
  303. Variant(const VariantVector& value) :
  304. type_(VAR_NONE)
  305. {
  306. *this = value;
  307. }
  308. /// Construct from a variant map.
  309. Variant(const VariantMap& value) :
  310. type_(VAR_NONE)
  311. {
  312. *this = value;
  313. }
  314. /// Construct from a string vector.
  315. Variant(const StringVector& value) :
  316. type_ (VAR_NONE)
  317. {
  318. *this = value;
  319. }
  320. /// Construct from a rect.
  321. Variant(const Rect& value) :
  322. type_(VAR_NONE)
  323. {
  324. *this = value;
  325. }
  326. /// Construct from an integer rect.
  327. Variant(const IntRect& value) :
  328. type_(VAR_NONE)
  329. {
  330. *this = value;
  331. }
  332. /// Construct from an IntVector2.
  333. Variant(const IntVector2& value) :
  334. type_(VAR_NONE)
  335. {
  336. *this = value;
  337. }
  338. /// Construct from an IntVector3.
  339. Variant(const IntVector3& value) :
  340. type_(VAR_NONE)
  341. {
  342. *this = value;
  343. }
  344. /// Construct from a RefCounted pointer. The object will be stored internally in a WeakPtr so that its expiration can be detected safely.
  345. Variant(RefCounted* value) :
  346. type_(VAR_NONE)
  347. {
  348. *this = value;
  349. }
  350. /// Construct from a Matrix3.
  351. Variant(const Matrix3& value) :
  352. type_(VAR_NONE)
  353. {
  354. *this = value;
  355. }
  356. /// Construct from a Matrix3x4.
  357. Variant(const Matrix3x4& value) :
  358. type_(VAR_NONE)
  359. {
  360. *this = value;
  361. }
  362. /// Construct from a Matrix4.
  363. Variant(const Matrix4& value) :
  364. type_(VAR_NONE)
  365. {
  366. *this = value;
  367. }
  368. /// Construct from type and value.
  369. Variant(const String& type, const String& value) :
  370. type_(VAR_NONE)
  371. {
  372. FromString(type, value);
  373. }
  374. /// Construct from type and value.
  375. Variant(VariantType type, const String& value) :
  376. type_(VAR_NONE)
  377. {
  378. FromString(type, value);
  379. }
  380. /// Construct from type and value.
  381. Variant(const char* type, const char* value) :
  382. type_(VAR_NONE)
  383. {
  384. FromString(type, value);
  385. }
  386. /// Construct from type and value.
  387. Variant(VariantType type, const char* value) :
  388. type_(VAR_NONE)
  389. {
  390. FromString(type, value);
  391. }
  392. /// Copy-construct from another variant.
  393. Variant(const Variant& value) :
  394. type_(VAR_NONE)
  395. {
  396. *this = value;
  397. }
  398. /// Destruct.
  399. ~Variant()
  400. {
  401. SetType(VAR_NONE);
  402. }
  403. /// Reset to empty.
  404. void Clear()
  405. {
  406. SetType(VAR_NONE);
  407. }
  408. /// Assign from another variant.
  409. Variant& operator =(const Variant& rhs);
  410. /// Assign from an integer.
  411. Variant& operator =(int rhs)
  412. {
  413. SetType(VAR_INT);
  414. value_.int_ = rhs;
  415. return *this;
  416. }
  417. /// Assign from 64 bit integer.
  418. Variant& operator =(long long rhs)
  419. {
  420. SetType(VAR_INT64);
  421. *reinterpret_cast<long long*>(&value_) = rhs;
  422. return *this;
  423. }
  424. /// Assign from unsigned 64 bit integer.
  425. Variant& operator =(unsigned long long rhs)
  426. {
  427. SetType(VAR_INT64);
  428. *reinterpret_cast<long long*>(&value_) = (long long)rhs;
  429. return *this;
  430. }
  431. /// Assign from an unsigned integer.
  432. Variant& operator =(unsigned rhs)
  433. {
  434. SetType(VAR_INT);
  435. value_.int_ = (int)rhs;
  436. return *this;
  437. }
  438. /// Assign from a StringHash (convert to integer.)
  439. Variant& operator =(const StringHash& rhs)
  440. {
  441. SetType(VAR_INT);
  442. value_.int_ = (int)rhs.Value();
  443. return *this;
  444. }
  445. /// Assign from a bool.
  446. Variant& operator =(bool rhs)
  447. {
  448. SetType(VAR_BOOL);
  449. value_.bool_ = rhs;
  450. return *this;
  451. }
  452. /// Assign from a float.
  453. Variant& operator =(float rhs)
  454. {
  455. SetType(VAR_FLOAT);
  456. value_.float_ = rhs;
  457. return *this;
  458. }
  459. /// Assign from a double.
  460. Variant& operator = (double rhs)
  461. {
  462. SetType(VAR_DOUBLE);
  463. *(reinterpret_cast<double*>(&value_)) = rhs;
  464. return *this;
  465. }
  466. /// Assign from a Vector2.
  467. Variant& operator =(const Vector2& rhs)
  468. {
  469. SetType(VAR_VECTOR2);
  470. *(reinterpret_cast<Vector2*>(&value_)) = rhs;
  471. return *this;
  472. }
  473. /// Assign from a Vector3.
  474. Variant& operator =(const Vector3& rhs)
  475. {
  476. SetType(VAR_VECTOR3);
  477. *(reinterpret_cast<Vector3*>(&value_)) = rhs;
  478. return *this;
  479. }
  480. /// Assign from a Vector4.
  481. Variant& operator =(const Vector4& rhs)
  482. {
  483. SetType(VAR_VECTOR4);
  484. *(reinterpret_cast<Vector4*>(&value_)) = rhs;
  485. return *this;
  486. }
  487. /// Assign from a quaternion.
  488. Variant& operator =(const Quaternion& rhs)
  489. {
  490. SetType(VAR_QUATERNION);
  491. *(reinterpret_cast<Quaternion*>(&value_)) = rhs;
  492. return *this;
  493. }
  494. /// Assign from a color.
  495. Variant& operator =(const Color& rhs)
  496. {
  497. SetType(VAR_COLOR);
  498. *(reinterpret_cast<Color*>(&value_)) = rhs;
  499. return *this;
  500. }
  501. /// Assign from a string.
  502. Variant& operator =(const String& rhs)
  503. {
  504. SetType(VAR_STRING);
  505. *(reinterpret_cast<String*>(&value_)) = rhs;
  506. return *this;
  507. }
  508. /// Assign from a C string.
  509. Variant& operator =(const char* rhs)
  510. {
  511. SetType(VAR_STRING);
  512. *(reinterpret_cast<String*>(&value_)) = String(rhs);
  513. return *this;
  514. }
  515. /// Assign from a buffer.
  516. Variant& operator =(const PODVector<unsigned char>& rhs)
  517. {
  518. SetType(VAR_BUFFER);
  519. *(reinterpret_cast<PODVector<unsigned char>*>(&value_)) = rhs;
  520. return *this;
  521. }
  522. /// Assign from a %VectorBuffer and store as a buffer.
  523. Variant& operator =(const VectorBuffer& rhs);
  524. /// Assign from a void pointer.
  525. Variant& operator =(void* rhs)
  526. {
  527. SetType(VAR_VOIDPTR);
  528. value_.ptr_ = rhs;
  529. return *this;
  530. }
  531. /// Assign from a resource reference.
  532. Variant& operator =(const ResourceRef& rhs)
  533. {
  534. SetType(VAR_RESOURCEREF);
  535. *(reinterpret_cast<ResourceRef*>(&value_)) = rhs;
  536. return *this;
  537. }
  538. /// Assign from a resource reference list.
  539. Variant& operator =(const ResourceRefList& rhs)
  540. {
  541. SetType(VAR_RESOURCEREFLIST);
  542. *(reinterpret_cast<ResourceRefList*>(&value_)) = rhs;
  543. return *this;
  544. }
  545. /// Assign from a variant vector.
  546. Variant& operator =(const VariantVector& rhs)
  547. {
  548. SetType(VAR_VARIANTVECTOR);
  549. *(reinterpret_cast<VariantVector*>(&value_)) = rhs;
  550. return *this;
  551. }
  552. /// Assign from a string vector.
  553. Variant& operator =(const StringVector& rhs)
  554. {
  555. SetType(VAR_STRINGVECTOR);
  556. *(reinterpret_cast<StringVector*>(&value_)) = rhs;
  557. return *this;
  558. }
  559. /// Assign from a variant map.
  560. Variant& operator =(const VariantMap& rhs)
  561. {
  562. SetType(VAR_VARIANTMAP);
  563. *(reinterpret_cast<VariantMap*>(&value_)) = rhs;
  564. return *this;
  565. }
  566. /// Assign from a rect.
  567. Variant& operator =(const Rect& rhs)
  568. {
  569. SetType(VAR_RECT);
  570. *(reinterpret_cast<Rect*>(&value_)) = rhs;
  571. return *this;
  572. }
  573. /// Assign from an integer rect.
  574. Variant& operator =(const IntRect& rhs)
  575. {
  576. SetType(VAR_INTRECT);
  577. *(reinterpret_cast<IntRect*>(&value_)) = rhs;
  578. return *this;
  579. }
  580. /// Assign from an IntVector2.
  581. Variant& operator =(const IntVector2& rhs)
  582. {
  583. SetType(VAR_INTVECTOR2);
  584. *(reinterpret_cast<IntVector2*>(&value_)) = rhs;
  585. return *this;
  586. }
  587. /// Assign from an IntVector3.
  588. Variant& operator =(const IntVector3& rhs)
  589. {
  590. SetType(VAR_INTVECTOR3);
  591. *(reinterpret_cast<IntVector3*>(&value_)) = rhs;
  592. return *this;
  593. }
  594. /// Assign from a RefCounted pointer. The object will be stored internally in a WeakPtr so that its expiration can be detected safely.
  595. Variant& operator =(RefCounted* rhs)
  596. {
  597. SetType(VAR_PTR);
  598. *(reinterpret_cast<WeakPtr<RefCounted>*>(&value_)) = rhs;
  599. return *this;
  600. }
  601. /// Assign from a Matrix3.
  602. Variant& operator =(const Matrix3& rhs)
  603. {
  604. SetType(VAR_MATRIX3);
  605. *(reinterpret_cast<Matrix3*>(value_.ptr_)) = rhs;
  606. return *this;
  607. }
  608. /// Assign from a Matrix3x4.
  609. Variant& operator =(const Matrix3x4& rhs)
  610. {
  611. SetType(VAR_MATRIX3X4);
  612. *(reinterpret_cast<Matrix3x4*>(value_.ptr_)) = rhs;
  613. return *this;
  614. }
  615. /// Assign from a Matrix4.
  616. Variant& operator =(const Matrix4& rhs)
  617. {
  618. SetType(VAR_MATRIX4);
  619. *(reinterpret_cast<Matrix4*>(value_.ptr_)) = rhs;
  620. return *this;
  621. }
  622. /// Test for equality with another variant.
  623. bool operator ==(const Variant& rhs) const;
  624. /// Test for equality with an integer. To return true, both the type and value must match.
  625. bool operator ==(int rhs) const { return type_ == VAR_INT ? value_.int_ == rhs : false; }
  626. /// Test for equality with an unsigned 64 bit integer. To return true, both the type and value must match.
  627. bool operator ==(unsigned rhs) const { return type_ == VAR_INT ? value_.int_ == (int)rhs : false; }
  628. /// Test for equality with an 64 bit integer. To return true, both the type and value must match.
  629. bool operator ==(long long rhs) const { return type_ == VAR_INT64 ? *reinterpret_cast<const long long*>(&value_.int_) == rhs : false; }
  630. /// Test for equality with an unsigned integer. To return true, both the type and value must match.
  631. bool operator ==(unsigned long long rhs) const { return type_ == VAR_INT64 ? *reinterpret_cast<const unsigned long long*>(&value_.int_) == (int)rhs : false; }
  632. /// Test for equality with a bool. To return true, both the type and value must match.
  633. bool operator ==(bool rhs) const { return type_ == VAR_BOOL ? value_.bool_ == rhs : false; }
  634. /// Test for equality with a float. To return true, both the type and value must match.
  635. bool operator ==(float rhs) const { return type_ == VAR_FLOAT ? value_.float_ == rhs : false; }
  636. /// Test for equality with a double. To return true, both the type and value must match.
  637. bool operator ==(double rhs) const { return type_ == VAR_DOUBLE ? *(reinterpret_cast<const double*>(&value_)) == rhs : false; }
  638. /// Test for equality with a Vector2. To return true, both the type and value must match.
  639. bool operator ==(const Vector2& rhs) const
  640. {
  641. return type_ == VAR_VECTOR2 ? *(reinterpret_cast<const Vector2*>(&value_)) == rhs : false;
  642. }
  643. /// Test for equality with a Vector3. To return true, both the type and value must match.
  644. bool operator ==(const Vector3& rhs) const
  645. {
  646. return type_ == VAR_VECTOR3 ? *(reinterpret_cast<const Vector3*>(&value_)) == rhs : false;
  647. }
  648. /// Test for equality with a Vector4. To return true, both the type and value must match.
  649. bool operator ==(const Vector4& rhs) const
  650. {
  651. return type_ == VAR_VECTOR4 ? *(reinterpret_cast<const Vector4*>(&value_)) == rhs : false;
  652. }
  653. /// Test for equality with a quaternion. To return true, both the type and value must match.
  654. bool operator ==(const Quaternion& rhs) const
  655. {
  656. return type_ == VAR_QUATERNION ? *(reinterpret_cast<const Quaternion*>(&value_)) == rhs : false;
  657. }
  658. /// Test for equality with a color. To return true, both the type and value must match.
  659. bool operator ==(const Color& rhs) const
  660. {
  661. return type_ == VAR_COLOR ? *(reinterpret_cast<const Color*>(&value_)) == rhs : false;
  662. }
  663. /// Test for equality with a string. To return true, both the type and value must match.
  664. bool operator ==(const String& rhs) const
  665. {
  666. return type_ == VAR_STRING ? *(reinterpret_cast<const String*>(&value_)) == rhs : false;
  667. }
  668. /// Test for equality with a buffer. To return true, both the type and value must match.
  669. bool operator ==(const PODVector<unsigned char>& rhs) const;
  670. /// Test for equality with a %VectorBuffer. To return true, both the type and value must match.
  671. bool operator ==(const VectorBuffer& rhs) const;
  672. /// Test for equality with a void pointer. To return true, both the type and value must match, with the exception that a RefCounted pointer is also allowed.
  673. bool operator ==(void* rhs) const
  674. {
  675. if (type_ == VAR_VOIDPTR)
  676. return value_.ptr_ == rhs;
  677. else if (type_ == VAR_PTR)
  678. return *(reinterpret_cast<const WeakPtr<RefCounted>*>(&value_)) == rhs;
  679. else
  680. return false;
  681. }
  682. /// Test for equality with a resource reference. To return true, both the type and value must match.
  683. bool operator ==(const ResourceRef& rhs) const
  684. {
  685. return type_ == VAR_RESOURCEREF ? *(reinterpret_cast<const ResourceRef*>(&value_)) == rhs : false;
  686. }
  687. /// Test for equality with a resource reference list. To return true, both the type and value must match.
  688. bool operator ==(const ResourceRefList& rhs) const
  689. {
  690. return type_ == VAR_RESOURCEREFLIST ? *(reinterpret_cast<const ResourceRefList*>(&value_)) == rhs : false;
  691. }
  692. /// Test for equality with a variant vector. To return true, both the type and value must match.
  693. bool operator ==(const VariantVector& rhs) const
  694. {
  695. return type_ == VAR_VARIANTVECTOR ? *(reinterpret_cast<const VariantVector*>(&value_)) == rhs : false;
  696. }
  697. /// Test for equality with a string vector. To return true, both the type and value must match.
  698. bool operator ==(const StringVector& rhs) const
  699. {
  700. return type_ == VAR_STRINGVECTOR ? *(reinterpret_cast<const StringVector*>(&value_)) == rhs : false;
  701. }
  702. /// Test for equality with a variant map. To return true, both the type and value must match.
  703. bool operator ==(const VariantMap& rhs) const
  704. {
  705. return type_ == VAR_VARIANTMAP ? *(reinterpret_cast<const VariantMap*>(&value_)) == rhs : false;
  706. }
  707. /// Test for equality with a rect. To return true, both the type and value must match.
  708. bool operator ==(const Rect& rhs) const
  709. {
  710. return type_ == VAR_RECT ? *(reinterpret_cast<const Rect*>(&value_)) == rhs : false;
  711. }
  712. /// Test for equality with an integer rect. To return true, both the type and value must match.
  713. bool operator ==(const IntRect& rhs) const
  714. {
  715. return type_ == VAR_INTRECT ? *(reinterpret_cast<const IntRect*>(&value_)) == rhs : false;
  716. }
  717. /// Test for equality with an IntVector2. To return true, both the type and value must match.
  718. bool operator ==(const IntVector2& rhs) const
  719. {
  720. return type_ == VAR_INTVECTOR2 ? *(reinterpret_cast<const IntVector2*>(&value_)) == rhs : false;
  721. }
  722. /// Test for equality with an IntVector3. To return true, both the type and value must match.
  723. bool operator ==(const IntVector3& rhs) const
  724. {
  725. return type_ == VAR_INTVECTOR3 ? *(reinterpret_cast<const IntVector3*>(&value_)) == rhs : false;
  726. }
  727. /// Test for equality with a StringHash. To return true, both the type and value must match.
  728. bool operator ==(const StringHash& rhs) const { return type_ == VAR_INT ? (unsigned)value_.int_ == rhs.Value() : false; }
  729. /// Test for equality with a RefCounted pointer. To return true, both the type and value must match, with the exception that void pointer is also allowed.
  730. bool operator ==(RefCounted* rhs) const
  731. {
  732. if (type_ == VAR_PTR)
  733. return *(reinterpret_cast<const WeakPtr<RefCounted>*>(&value_)) == rhs;
  734. else if (type_ == VAR_VOIDPTR)
  735. return value_.ptr_ == rhs;
  736. else
  737. return false;
  738. }
  739. /// Test for equality with a Matrix3. To return true, both the type and value must match.
  740. bool operator ==(const Matrix3& rhs) const
  741. {
  742. return type_ == VAR_MATRIX3 ? *(reinterpret_cast<const Matrix3*>(value_.ptr_)) == rhs : false;
  743. }
  744. /// Test for equality with a Matrix3x4. To return true, both the type and value must match.
  745. bool operator ==(const Matrix3x4& rhs) const
  746. {
  747. return type_ == VAR_MATRIX3X4 ? *(reinterpret_cast<const Matrix3x4*>(value_.ptr_)) == rhs : false;
  748. }
  749. /// Test for equality with a Matrix4. To return true, both the type and value must match.
  750. bool operator ==(const Matrix4& rhs) const
  751. {
  752. return type_ == VAR_MATRIX4 ? *(reinterpret_cast<const Matrix4*>(value_.ptr_)) == rhs : false;
  753. }
  754. /// Test for inequality with another variant.
  755. bool operator !=(const Variant& rhs) const { return !(*this == rhs); }
  756. /// Test for inequality with an integer.
  757. bool operator !=(int rhs) const { return !(*this == rhs); }
  758. /// Test for inequality with an unsigned integer.
  759. bool operator !=(unsigned rhs) const { return !(*this == rhs); }
  760. /// Test for inequality with an 64 bit integer.
  761. bool operator !=(long long rhs) const { return !(*this == rhs); }
  762. /// Test for inequality with an unsigned 64 bit integer.
  763. bool operator !=(unsigned long long rhs) const { return !(*this == rhs); }
  764. /// Test for inequality with a bool.
  765. bool operator !=(bool rhs) const { return !(*this == rhs); }
  766. /// Test for inequality with a float.
  767. bool operator !=(float rhs) const { return !(*this == rhs); }
  768. /// Test for inequality with a double.
  769. bool operator !=(double rhs) const { return !(*this == rhs); }
  770. /// Test for inequality with a Vector2.
  771. bool operator !=(const Vector2& rhs) const { return !(*this == rhs); }
  772. /// Test for inequality with a Vector3.
  773. bool operator !=(const Vector3& rhs) const { return !(*this == rhs); }
  774. /// Test for inequality with an Vector4.
  775. bool operator !=(const Vector4& rhs) const { return !(*this == rhs); }
  776. /// Test for inequality with a Quaternion.
  777. bool operator !=(const Quaternion& rhs) const { return !(*this == rhs); }
  778. /// Test for inequality with a string.
  779. bool operator !=(const String& rhs) const { return !(*this == rhs); }
  780. /// Test for inequality with a buffer.
  781. bool operator !=(const PODVector<unsigned char>& rhs) const { return !(*this == rhs); }
  782. /// Test for inequality with a %VectorBuffer.
  783. bool operator !=(const VectorBuffer& rhs) const { return !(*this == rhs); }
  784. /// Test for inequality with a pointer.
  785. bool operator !=(void* rhs) const { return !(*this == rhs); }
  786. /// Test for inequality with a resource reference.
  787. bool operator !=(const ResourceRef& rhs) const { return !(*this == rhs); }
  788. /// Test for inequality with a resource reference list.
  789. bool operator !=(const ResourceRefList& rhs) const { return !(*this == rhs); }
  790. /// Test for inequality with a variant vector.
  791. bool operator !=(const VariantVector& rhs) const { return !(*this == rhs); }
  792. /// Test for inequality with a string vector.
  793. bool operator !=(const StringVector& rhs) const { return !(*this == rhs); }
  794. /// Test for inequality with a variant map.
  795. bool operator !=(const VariantMap& rhs) const { return !(*this == rhs); }
  796. /// Test for inequality with a rect.
  797. bool operator !=(const Rect& rhs) const { return !(*this == rhs); }
  798. /// Test for inequality with an integer rect.
  799. bool operator !=(const IntRect& rhs) const { return !(*this == rhs); }
  800. /// Test for inequality with an IntVector2.
  801. bool operator !=(const IntVector2& rhs) const { return !(*this == rhs); }
  802. /// Test for inequality with an IntVector3.
  803. bool operator !=(const IntVector3& rhs) const { return !(*this == rhs); }
  804. /// Test for inequality with a StringHash.
  805. bool operator !=(const StringHash& rhs) const { return !(*this == rhs); }
  806. /// Test for inequality with a RefCounted pointer.
  807. bool operator !=(RefCounted* rhs) const { return !(*this == rhs); }
  808. /// Test for inequality with a Matrix3.
  809. bool operator !=(const Matrix3& rhs) const { return !(*this == rhs); }
  810. /// Test for inequality with a Matrix3x4.
  811. bool operator !=(const Matrix3x4& rhs) const { return !(*this == rhs); }
  812. /// Test for inequality with a Matrix4.
  813. bool operator !=(const Matrix4& rhs) const { return !(*this == rhs); }
  814. /// Set from typename and value strings. Pointers will be set to null, and VariantBuffer or VariantMap types are not supported.
  815. void FromString(const String& type, const String& value);
  816. /// Set from typename and value strings. Pointers will be set to null, and VariantBuffer or VariantMap types are not supported.
  817. void FromString(const char* type, const char* value);
  818. /// Set from type and value string. Pointers will be set to null, and VariantBuffer or VariantMap types are not supported.
  819. void FromString(VariantType type, const String& value);
  820. /// Set from type and value string. Pointers will be set to null, and VariantBuffer or VariantMap types are not supported.
  821. void FromString(VariantType type, const char* value);
  822. /// Set buffer type from a memory area.
  823. void SetBuffer(const void* data, unsigned size);
  824. /// Return int or zero on type mismatch. Floats and doubles are converted.
  825. int GetInt() const
  826. {
  827. if (type_ == VAR_INT)
  828. return value_.int_;
  829. else if (type_ == VAR_FLOAT)
  830. return (int)value_.float_;
  831. else if (type_ == VAR_DOUBLE)
  832. return (int)*reinterpret_cast<const double*>(&value_);
  833. else
  834. return 0;
  835. }
  836. /// Return 64 bit int or zero on type mismatch. Floats and doubles are converted.
  837. long long GetInt64() const
  838. {
  839. if (type_ == VAR_INT64)
  840. return *(reinterpret_cast<const long long*>(&value_));
  841. else if (type_ == VAR_INT)
  842. return value_.int_;
  843. else if (type_ == VAR_FLOAT)
  844. return (long long)value_.float_;
  845. else if (type_ == VAR_DOUBLE)
  846. return (long long)*reinterpret_cast<const double*>(&value_);
  847. else
  848. return 0;
  849. }
  850. /// Return unsigned 64 bit int or zero on type mismatch. Floats and doubles are converted.
  851. unsigned long long GetUInt64() const
  852. {
  853. if (type_ == VAR_INT64)
  854. return *(reinterpret_cast<const unsigned long long*>(&value_));
  855. else if (type_ == VAR_INT)
  856. return static_cast<unsigned long long>(value_.int_);
  857. else if (type_ == VAR_FLOAT)
  858. return (unsigned long long)value_.float_;
  859. else if (type_ == VAR_DOUBLE)
  860. return (unsigned long long)*reinterpret_cast<const double*>(&value_);
  861. else
  862. return 0;
  863. }
  864. /// Return unsigned int or zero on type mismatch. Floats and doubles are converted.
  865. unsigned GetUInt() const
  866. {
  867. if (type_ == VAR_INT)
  868. return (unsigned)value_.int_;
  869. else if (type_ == VAR_FLOAT)
  870. return (unsigned)value_.float_;
  871. else if (type_ == VAR_DOUBLE)
  872. return (unsigned)*reinterpret_cast<const double*>(&value_);
  873. else
  874. return 0;
  875. }
  876. /// Return StringHash or zero on type mismatch.
  877. StringHash GetStringHash() const { return StringHash(GetUInt()); }
  878. /// Return bool or false on type mismatch.
  879. bool GetBool() const { return type_ == VAR_BOOL ? value_.bool_ : false; }
  880. /// Return float or zero on type mismatch. Ints and doubles are converted.
  881. float GetFloat() const
  882. {
  883. if (type_ == VAR_FLOAT)
  884. return value_.float_;
  885. else if (type_ == VAR_DOUBLE)
  886. return (float)*reinterpret_cast<const double*>(&value_);
  887. else if (type_ == VAR_INT)
  888. return (float)value_.int_;
  889. else
  890. return 0.0f;
  891. }
  892. /// Return double or zero on type mismatch. Ints and floats are converted.
  893. double GetDouble() const
  894. {
  895. if (type_ == VAR_DOUBLE)
  896. return *reinterpret_cast<const double*>(&value_);
  897. else if (type_ == VAR_FLOAT)
  898. return (double)value_.float_;
  899. else if (type_ == VAR_INT)
  900. return (double)value_.int_;
  901. else
  902. return 0.0;
  903. }
  904. /// Return Vector2 or zero on type mismatch.
  905. const Vector2& GetVector2() const { return type_ == VAR_VECTOR2 ? *reinterpret_cast<const Vector2*>(&value_) : Vector2::ZERO; }
  906. /// Return Vector3 or zero on type mismatch.
  907. const Vector3& GetVector3() const { return type_ == VAR_VECTOR3 ? *reinterpret_cast<const Vector3*>(&value_) : Vector3::ZERO; }
  908. /// Return Vector4 or zero on type mismatch.
  909. const Vector4& GetVector4() const { return type_ == VAR_VECTOR4 ? *reinterpret_cast<const Vector4*>(&value_) : Vector4::ZERO; }
  910. /// Return quaternion or identity on type mismatch.
  911. const Quaternion& GetQuaternion() const
  912. {
  913. return type_ == VAR_QUATERNION ? *reinterpret_cast<const Quaternion*>(&value_) : Quaternion::IDENTITY;
  914. }
  915. /// Return color or default on type mismatch. Vector4 is aliased to Color if necessary.
  916. const Color& GetColor() const { return (type_ == VAR_COLOR || type_ == VAR_VECTOR4) ? *reinterpret_cast<const Color*>(&value_) : Color::WHITE; }
  917. /// Return string or empty on type mismatch.
  918. const String& GetString() const { return type_ == VAR_STRING ? *reinterpret_cast<const String*>(&value_) : String::EMPTY; }
  919. /// Return buffer or empty on type mismatch.
  920. const PODVector<unsigned char>& GetBuffer() const
  921. {
  922. return type_ == VAR_BUFFER ? *reinterpret_cast<const PODVector<unsigned char>*>(&value_) : emptyBuffer;
  923. }
  924. /// Return %VectorBuffer containing the buffer or empty on type mismatch.
  925. VectorBuffer GetVectorBuffer() const;
  926. /// Return void pointer or null on type mismatch. RefCounted pointer will be converted.
  927. void* GetVoidPtr() const
  928. {
  929. if (type_ == VAR_VOIDPTR)
  930. return value_.ptr_;
  931. else if (type_ == VAR_PTR)
  932. return *reinterpret_cast<const WeakPtr<RefCounted>*>(&value_);
  933. else
  934. return 0;
  935. }
  936. /// Return a resource reference or empty on type mismatch.
  937. const ResourceRef& GetResourceRef() const
  938. {
  939. return type_ == VAR_RESOURCEREF ? *reinterpret_cast<const ResourceRef*>(&value_) : emptyResourceRef;
  940. }
  941. /// Return a resource reference list or empty on type mismatch.
  942. const ResourceRefList& GetResourceRefList() const
  943. {
  944. return type_ == VAR_RESOURCEREFLIST ? *reinterpret_cast<const ResourceRefList*>(&value_) : emptyResourceRefList;
  945. }
  946. /// Return a variant vector or empty on type mismatch.
  947. const VariantVector& GetVariantVector() const
  948. {
  949. return type_ == VAR_VARIANTVECTOR ? *reinterpret_cast<const VariantVector*>(&value_) : emptyVariantVector;
  950. }
  951. /// Return a string vector or empty on type mismatch.
  952. const StringVector& GetStringVector() const
  953. {
  954. return type_ == VAR_STRINGVECTOR ? *reinterpret_cast<const StringVector*>(&value_) : emptyStringVector;
  955. }
  956. /// Return a variant map or empty on type mismatch.
  957. const VariantMap& GetVariantMap() const
  958. {
  959. return type_ == VAR_VARIANTMAP ? *reinterpret_cast<const VariantMap*>(&value_) : emptyVariantMap;
  960. }
  961. /// Return a rect or empty on type mismatch.
  962. const Rect& GetRect() const { return type_ == VAR_RECT ? *reinterpret_cast<const Rect*>(&value_) : Rect::ZERO; }
  963. /// Return an integer rect or empty on type mismatch.
  964. const IntRect& GetIntRect() const { return type_ == VAR_INTRECT ? *reinterpret_cast<const IntRect*>(&value_) : IntRect::ZERO; }
  965. /// Return an IntVector2 or empty on type mismatch.
  966. const IntVector2& GetIntVector2() const
  967. {
  968. return type_ == VAR_INTVECTOR2 ? *reinterpret_cast<const IntVector2*>(&value_) : IntVector2::ZERO;
  969. }
  970. /// Return an IntVector3 or empty on type mismatch.
  971. const IntVector3& GetIntVector3() const
  972. {
  973. return type_ == VAR_INTVECTOR3 ? *reinterpret_cast<const IntVector3*>(&value_) : IntVector3::ZERO;
  974. }
  975. /// Return a RefCounted pointer or null on type mismatch. Will return null if holding a void pointer, as it can not be safely verified that the object is a RefCounted.
  976. RefCounted* GetPtr() const
  977. {
  978. return type_ == VAR_PTR ? *reinterpret_cast<const WeakPtr<RefCounted>*>(&value_) : (RefCounted*)0;
  979. }
  980. /// Return a Matrix3 or identity on type mismatch.
  981. const Matrix3& GetMatrix3() const
  982. {
  983. return type_ == VAR_MATRIX3 ? *(reinterpret_cast<const Matrix3*>(value_.ptr_)) : Matrix3::IDENTITY;
  984. }
  985. /// Return a Matrix3x4 or identity on type mismatch.
  986. const Matrix3x4& GetMatrix3x4() const
  987. {
  988. return type_ == VAR_MATRIX3X4 ? *(reinterpret_cast<const Matrix3x4*>(value_.ptr_)) : Matrix3x4::IDENTITY;
  989. }
  990. /// Return a Matrix4 or identity on type mismatch.
  991. const Matrix4& GetMatrix4() const
  992. {
  993. return type_ == VAR_MATRIX4 ? *(reinterpret_cast<const Matrix4*>(value_.ptr_)) : Matrix4::IDENTITY;
  994. }
  995. /// Return value's type.
  996. VariantType GetType() const { return type_; }
  997. /// Return value's type name.
  998. String GetTypeName() const;
  999. /// Convert value to string. Pointers are returned as null, and VariantBuffer or VariantMap are not supported and return empty.
  1000. String ToString() const;
  1001. /// Return true when the variant value is considered zero according to its actual type.
  1002. bool IsZero() const;
  1003. /// Return true when the variant is empty (i.e. not initialized yet).
  1004. bool IsEmpty() const { return type_ == VAR_NONE; }
  1005. /// Return the value, template version.
  1006. template <class T> T Get() const;
  1007. /// Return a pointer to a modifiable buffer or null on type mismatch.
  1008. PODVector<unsigned char>* GetBufferPtr()
  1009. {
  1010. return type_ == VAR_BUFFER ? reinterpret_cast<PODVector<unsigned char>*>(&value_) : 0;
  1011. }
  1012. /// Return a pointer to a modifiable variant vector or null on type mismatch.
  1013. VariantVector* GetVariantVectorPtr() { return type_ == VAR_VARIANTVECTOR ? reinterpret_cast<VariantVector*>(&value_) : 0; }
  1014. /// Return a pointer to a modifiable string vector or null on type mismatch.
  1015. StringVector* GetStringVectorPtr() { return type_ == VAR_STRINGVECTOR ? reinterpret_cast<StringVector*>(&value_) : 0; }
  1016. /// Return a pointer to a modifiable variant map or null on type mismatch.
  1017. VariantMap* GetVariantMapPtr() { return type_ == VAR_VARIANTMAP ? reinterpret_cast<VariantMap*>(&value_) : 0; }
  1018. /// Return name for variant type.
  1019. static String GetTypeName(VariantType type);
  1020. /// Return variant type from type name.
  1021. static VariantType GetTypeFromName(const String& typeName);
  1022. /// Return variant type from type name.
  1023. static VariantType GetTypeFromName(const char* typeName);
  1024. /// Empty variant.
  1025. static const Variant EMPTY;
  1026. /// Empty buffer.
  1027. static const PODVector<unsigned char> emptyBuffer;
  1028. /// Empty resource reference.
  1029. static const ResourceRef emptyResourceRef;
  1030. /// Empty resource reference list.
  1031. static const ResourceRefList emptyResourceRefList;
  1032. /// Empty variant map.
  1033. static const VariantMap emptyVariantMap;
  1034. /// Empty variant vector.
  1035. static const VariantVector emptyVariantVector;
  1036. /// Empty string vector.
  1037. static const StringVector emptyStringVector;
  1038. private:
  1039. /// Set new type and allocate/deallocate memory as necessary.
  1040. void SetType(VariantType newType);
  1041. /// Variant type.
  1042. VariantType type_;
  1043. /// Variant value.
  1044. VariantValue value_;
  1045. };
  1046. /// Return variant type from type.
  1047. template <typename T> VariantType GetVariantType();
  1048. // Return variant type from concrete types
  1049. template <> inline VariantType GetVariantType<int>() { return VAR_INT; }
  1050. template <> inline VariantType GetVariantType<unsigned>() { return VAR_INT; }
  1051. template <> inline VariantType GetVariantType<long long>() { return VAR_INT64; }
  1052. template <> inline VariantType GetVariantType<unsigned long long>() { return VAR_INT64; }
  1053. template <> inline VariantType GetVariantType<bool>() { return VAR_BOOL; }
  1054. template <> inline VariantType GetVariantType<float>() { return VAR_FLOAT; }
  1055. template <> inline VariantType GetVariantType<double>() { return VAR_DOUBLE; }
  1056. template <> inline VariantType GetVariantType<Vector2>() { return VAR_VECTOR2; }
  1057. template <> inline VariantType GetVariantType<Vector3>() { return VAR_VECTOR3; }
  1058. template <> inline VariantType GetVariantType<Vector4>() { return VAR_VECTOR4; }
  1059. template <> inline VariantType GetVariantType<Quaternion>() { return VAR_QUATERNION; }
  1060. template <> inline VariantType GetVariantType<Color>() { return VAR_COLOR; }
  1061. template <> inline VariantType GetVariantType<String>() { return VAR_STRING; }
  1062. template <> inline VariantType GetVariantType<StringHash>() { return VAR_INT; }
  1063. template <> inline VariantType GetVariantType<PODVector<unsigned char> >() { return VAR_BUFFER; }
  1064. template <> inline VariantType GetVariantType<ResourceRef>() { return VAR_RESOURCEREF; }
  1065. template <> inline VariantType GetVariantType<ResourceRefList>() { return VAR_RESOURCEREFLIST; }
  1066. template <> inline VariantType GetVariantType<VariantVector>() { return VAR_VARIANTVECTOR; }
  1067. template <> inline VariantType GetVariantType<StringVector>() { return VAR_STRINGVECTOR; }
  1068. template <> inline VariantType GetVariantType<VariantMap>() { return VAR_VARIANTMAP; }
  1069. template <> inline VariantType GetVariantType<Rect>() { return VAR_RECT; }
  1070. template <> inline VariantType GetVariantType<IntRect>() { return VAR_INTRECT; }
  1071. template <> inline VariantType GetVariantType<IntVector2>() { return VAR_INTVECTOR2; }
  1072. template <> inline VariantType GetVariantType<IntVector3>() { return VAR_INTVECTOR3; }
  1073. template <> inline VariantType GetVariantType<Matrix3>() { return VAR_MATRIX3; }
  1074. template <> inline VariantType GetVariantType<Matrix3x4>() { return VAR_MATRIX3X4; }
  1075. template <> inline VariantType GetVariantType<Matrix4>() { return VAR_MATRIX4; }
  1076. // Specializations of Variant::Get<T>
  1077. template <> ATOMIC_API int Variant::Get<int>() const;
  1078. template <> ATOMIC_API unsigned Variant::Get<unsigned>() const;
  1079. template <> ATOMIC_API long long Variant::Get<long long>() const;
  1080. template <> ATOMIC_API unsigned long long Variant::Get<unsigned long long>() const;
  1081. template <> ATOMIC_API StringHash Variant::Get<StringHash>() const;
  1082. template <> ATOMIC_API bool Variant::Get<bool>() const;
  1083. template <> ATOMIC_API float Variant::Get<float>() const;
  1084. template <> ATOMIC_API double Variant::Get<double>() const;
  1085. template <> ATOMIC_API const Vector2& Variant::Get<const Vector2&>() const;
  1086. template <> ATOMIC_API const Vector3& Variant::Get<const Vector3&>() const;
  1087. template <> ATOMIC_API const Vector4& Variant::Get<const Vector4&>() const;
  1088. template <> ATOMIC_API const Quaternion& Variant::Get<const Quaternion&>() const;
  1089. template <> ATOMIC_API const Color& Variant::Get<const Color&>() const;
  1090. template <> ATOMIC_API const String& Variant::Get<const String&>() const;
  1091. template <> ATOMIC_API const Rect& Variant::Get<const Rect&>() const;
  1092. template <> ATOMIC_API const IntRect& Variant::Get<const IntRect&>() const;
  1093. template <> ATOMIC_API const IntVector2& Variant::Get<const IntVector2&>() const;
  1094. template <> ATOMIC_API const IntVector3& Variant::Get<const IntVector3&>() const;
  1095. template <> ATOMIC_API const PODVector<unsigned char>& Variant::Get<const PODVector<unsigned char>&>() const;
  1096. template <> ATOMIC_API void* Variant::Get<void*>() const;
  1097. template <> ATOMIC_API RefCounted* Variant::Get<RefCounted*>() const;
  1098. template <> ATOMIC_API const Matrix3& Variant::Get<const Matrix3&>() const;
  1099. template <> ATOMIC_API const Matrix3x4& Variant::Get<const Matrix3x4&>() const;
  1100. template <> ATOMIC_API const Matrix4& Variant::Get<const Matrix4&>() const;
  1101. template <> ATOMIC_API ResourceRef Variant::Get<ResourceRef>() const;
  1102. template <> ATOMIC_API ResourceRefList Variant::Get<ResourceRefList>() const;
  1103. template <> ATOMIC_API VariantVector Variant::Get<VariantVector>() const;
  1104. template <> ATOMIC_API StringVector Variant::Get<StringVector>() const;
  1105. template <> ATOMIC_API VariantMap Variant::Get<VariantMap>() const;
  1106. template <> ATOMIC_API Vector2 Variant::Get<Vector2>() const;
  1107. template <> ATOMIC_API Vector3 Variant::Get<Vector3>() const;
  1108. template <> ATOMIC_API Vector4 Variant::Get<Vector4>() const;
  1109. template <> ATOMIC_API Quaternion Variant::Get<Quaternion>() const;
  1110. template <> ATOMIC_API Color Variant::Get<Color>() const;
  1111. template <> ATOMIC_API String Variant::Get<String>() const;
  1112. template <> ATOMIC_API Rect Variant::Get<Rect>() const;
  1113. template <> ATOMIC_API IntRect Variant::Get<IntRect>() const;
  1114. template <> ATOMIC_API IntVector2 Variant::Get<IntVector2>() const;
  1115. template <> ATOMIC_API IntVector3 Variant::Get<IntVector3>() const;
  1116. template <> ATOMIC_API PODVector<unsigned char> Variant::Get<PODVector<unsigned char> >() const;
  1117. template <> ATOMIC_API Matrix3 Variant::Get<Matrix3>() const;
  1118. template <> ATOMIC_API Matrix3x4 Variant::Get<Matrix3x4>() const;
  1119. template <> ATOMIC_API Matrix4 Variant::Get<Matrix4>() const;
  1120. }