PageRenderTime 93ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/php/std_map.i

#
Swig | 72 lines | 56 code | 11 blank | 5 comment | 0 complexity | 9453d04e870635e047dbc24aa2fbeceb MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * std_map.i
  3. *
  4. * SWIG typemaps for std::map
  5. * ----------------------------------------------------------------------------- */
  6. %include <std_common.i>
  7. // ------------------------------------------------------------------------
  8. // std::map
  9. // ------------------------------------------------------------------------
  10. %{
  11. #include <map>
  12. #include <algorithm>
  13. #include <stdexcept>
  14. %}
  15. // exported class
  16. namespace std {
  17. template<class K, class T> class map {
  18. // add typemaps here
  19. public:
  20. map();
  21. map(const map<K,T> &);
  22. unsigned int size() const;
  23. void clear();
  24. %extend {
  25. const T& get(const K& key) throw (std::out_of_range) {
  26. std::map<K,T >::iterator i = self->find(key);
  27. if (i != self->end())
  28. return i->second;
  29. else
  30. throw std::out_of_range("key not found");
  31. }
  32. void set(const K& key, const T& x) {
  33. (*self)[key] = x;
  34. }
  35. void del(const K& key) throw (std::out_of_range) {
  36. std::map<K,T >::iterator i = self->find(key);
  37. if (i != self->end())
  38. self->erase(i);
  39. else
  40. throw std::out_of_range("key not found");
  41. }
  42. bool has_key(const K& key) {
  43. std::map<K,T >::iterator i = self->find(key);
  44. return i != self->end();
  45. }
  46. bool is_empty() const {
  47. return self->empty();
  48. }
  49. }
  50. };
  51. // Legacy macros (deprecated)
  52. %define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
  53. #warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary"
  54. %enddef
  55. %define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
  56. #warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary"
  57. %enddef
  58. %define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
  59. #warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary"
  60. %enddef
  61. }