StringMap.hx 3.6 KB

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