ObjectMap.hx 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (C)2005-2015 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 haxe.ds;
  23. @:headerClassCode("
  24. inline void set(Dynamic key, ::null value) { __object_hash_set(h,key,value); }
  25. inline void set(Dynamic key, bool value) { __object_hash_set(h,key,value); }
  26. inline void set(Dynamic key, char value) { __object_hash_set_int(h,key,value); }
  27. inline void set(Dynamic key, unsigned char value) { __object_hash_set_int(h,key,value); }
  28. inline void set(Dynamic key, signed char value) { __object_hash_set_int(h,key,value); }
  29. inline void set(Dynamic key, short value) { __object_hash_set_int(h,key,value); }
  30. inline void set(Dynamic key, unsigned short value) { __object_hash_set_int(h,key,value); }
  31. inline void set(Dynamic key, int value) { __object_hash_set_int(h,key,value); }
  32. inline void set(Dynamic key, unsigned int value) { __object_hash_set_int(h,key,value); }
  33. inline void set(Dynamic key, float value) { __object_hash_set_float(h,key,value); }
  34. inline void set(Dynamic key, double value) { __object_hash_set_float(h,key,value); }
  35. inline void set(Dynamic key, ::String value) { __object_hash_set_string(h,key,value); }
  36. template<typename V, typename H>
  37. inline void set(Dynamic key, const ::cpp::Struct<V,H> &value) {__object_hash_set(h,key,value); }
  38. template<typename V>
  39. inline void set(Dynamic key, const ::cpp::Function<V> &value) {__object_hash_set(h,key,(Dynamic)value ); }
  40. template<typename V>
  41. inline void set(Dynamic key, const ::cpp::Pointer<V> &value) {__object_hash_set(h,key,(Dynamic)value ); }
  42. ")
  43. @:coreApi
  44. class ObjectMap<K:{},V> implements haxe.Constraints.IMap<K,V> {
  45. @:ifFeature("haxe.ds.ObjectMap.*")
  46. private var h : Dynamic;
  47. public function new() : Void { }
  48. public function set( key : K, value : V ) : Void {
  49. untyped __global__.__object_hash_set(h,key,value);
  50. }
  51. public function get( key : K ) : Null<V> {
  52. return untyped __global__.__object_hash_get(h,key);
  53. }
  54. public function exists( key : K ) : Bool {
  55. return untyped __global__.__object_hash_exists(h,key);
  56. }
  57. public function remove( key : K ) : Bool {
  58. return untyped __global__.__object_hash_remove(h,key);
  59. }
  60. public function keys() : Iterator<K> {
  61. var a:Array<K> = untyped __global__.__object_hash_keys(h);
  62. return a.iterator();
  63. }
  64. public function iterator() : Iterator<V> {
  65. var a:Array<Dynamic> = untyped __global__.__object_hash_values(h);
  66. return a.iterator();
  67. }
  68. public function toString() : String {
  69. return untyped __global__.__object_hash_to_string(h);
  70. }
  71. }