Int64Map.hx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (C)2005-2019 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is 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
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package cpp;
  23. import haxe.Int64;
  24. @:headerClassCode("
  25. inline void set(cpp::Int64 key, ::null value) { __int64_hash_set(HX_MAP_THIS,key,value); }
  26. inline void set(cpp::Int64 key, bool value) { __int64_hash_set(HX_MAP_THIS,key,value); }
  27. inline void set(cpp::Int64 key, char value) { __int64_hash_set_int(HX_MAP_THIS,key,value); }
  28. inline void set(cpp::Int64 key, unsigned char value) { __int64_hash_set_int(HX_MAP_THIS,key,value); }
  29. inline void set(cpp::Int64 key, signed char value) { __int64_hash_set_int(HX_MAP_THIS,key,value); }
  30. inline void set(cpp::Int64 key, short value) { __int64_hash_set_int(HX_MAP_THIS,key,value); }
  31. inline void set(cpp::Int64 key, unsigned short value) { __int64_hash_set_int(HX_MAP_THIS,key,value); }
  32. inline void set(cpp::Int64 key, int value) { __int64_hash_set_int(HX_MAP_THIS,key,value); }
  33. inline void set(cpp::Int64 key, unsigned int value) { __int64_hash_set_int(HX_MAP_THIS,key,value); }
  34. inline void set(cpp::Int64 key, float value) { __int64_hash_set_float(HX_MAP_THIS,key,value); }
  35. inline void set(cpp::Int64 key, double value) { __int64_hash_set_float(HX_MAP_THIS,key,value); }
  36. inline void set(cpp::Int64 key, ::String value) { __int64_hash_set_string(HX_MAP_THIS,key,value); }
  37. inline void set(cpp::Int64 key, cpp::Int64 value) { __int64_hash_set_int64(HX_MAP_THIS,key,value); }
  38. template<typename V, typename H>
  39. inline void set(cpp::Int64 key, const ::cpp::Struct<V,H> &value) {__int64_hash_set(HX_MAP_THIS,key,value); }
  40. template<typename F>
  41. inline void set(cpp::Int64 key, const ::cpp::Function<F> &value) {__int64_hash_set(HX_MAP_THIS,key,value); }
  42. template<typename V>
  43. inline void set(cpp::Int64 key, const ::cpp::Pointer<V> &value) {__int64_hash_set(HX_MAP_THIS,key,(Dynamic)value ); }
  44. template<typename VALUE>
  45. inline void set(Dynamic &key, const VALUE &value) { set( (cpp::Int64)key, value ); }
  46. inline bool get_bool(cpp::Int64 key) { return __int64_hash_get_bool(h,key); }
  47. inline int get_int(cpp::Int64 key) { return __int64_hash_get_int(h,key); }
  48. inline Float get_float(cpp::Int64 key) { return __int64_hash_get_float(h,key); }
  49. inline String get_string(cpp::Int64 key) { return __int64_hash_get_string(h,key); }
  50. inline cpp::Int64 get_int64(cpp::Int64 key) { return __int64_hash_get_int64(h,key); }
  51. ")
  52. @:coreApi class Int64Map<T> implements haxe.Constraints.IMap<Int64, T> {
  53. @:ifFeature("cpp.Int64Map.*")
  54. private var h:Dynamic;
  55. public function new():Void {}
  56. public function set(key:Int64, value:T):Void {
  57. untyped __global__.__int64_hash_set(__cpp__("HX_MAP_THIS"), key, value);
  58. }
  59. public function get(key:Int64):Null<T> {
  60. return untyped __global__.__int64_hash_get(h, key);
  61. }
  62. public function exists(key:Int64):Bool {
  63. return untyped __global__.__int64_hash_exists(h, key);
  64. }
  65. public function remove(key:Int64):Bool {
  66. return untyped __global__.__int64_hash_remove(h, key);
  67. }
  68. public function keys():Iterator<Int64> {
  69. var a:Array<Int64> = untyped __global__.__int64_hash_keys(h);
  70. return a.iterator();
  71. }
  72. public function iterator():Iterator<T> {
  73. var a:Array<Dynamic> = untyped __global__.__int64_hash_values(h);
  74. return a.iterator();
  75. }
  76. @:runtime public inline function keyValueIterator():KeyValueIterator<Int64, T> {
  77. return new haxe.iterators.MapKeyValueIterator(this);
  78. }
  79. public function copy():Int64Map<T> {
  80. var copied = new Int64Map();
  81. for (key in keys())
  82. copied.set(key, get(key));
  83. return copied;
  84. }
  85. public function toString():String {
  86. return untyped __global__.__int64_hash_to_string(h);
  87. }
  88. public function clear():Void {
  89. #if (hxcpp_api_level >= 400)
  90. return untyped __global__.__int64_hash_clear(h);
  91. #else
  92. h = null;
  93. #end
  94. }
  95. #if (scriptable)
  96. private function setString(key:Int64, val:String):Void {
  97. untyped __int64_hash_set_string(__cpp__("HX_MAP_THIS"), key, val);
  98. }
  99. private function setInt(key:Int64, val:Int):Void {
  100. untyped __int64_hash_set_int(__cpp__("HX_MAP_THIS"), key, val);
  101. }
  102. private function setBool(key:Int64, val:Bool):Void {
  103. untyped __int64_hash_set_int(__cpp__("HX_MAP_THIS"), key, val);
  104. }
  105. private function setFloat(key:Int64, val:Float):Void {
  106. untyped __int64_hash_set_float(__cpp__("HX_MAP_THIS"), key, val);
  107. }
  108. private function setInt64(key:Int64, val:Int64):Void {
  109. untyped __int64_hash_set_int64(__cpp__("HX_MAP_THIS"), key, val);
  110. }
  111. private function getString(key:Int64):String {
  112. return untyped __int64_hash_get_string(h, key);
  113. }
  114. private function getInt(key:Int64):Int {
  115. return untyped __int64_hash_get_int(h, key);
  116. }
  117. private function getBool(key:Int64):Bool {
  118. return untyped __int64_hash_get_bool(h, key);
  119. }
  120. private function getFloat(key:Int64):Float {
  121. return untyped __int64_hash_get_float(h, key);
  122. }
  123. private function getInt64(key:Int64):Int64 {
  124. return untyped __int64_hash_get_int64(h, key);
  125. }
  126. #end
  127. }