PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/perl5/std_map.i

#
Swig | 70 lines | 54 code | 11 blank | 5 comment | 0 complexity | a6b40c50e7459cdcbd32c4456a040912 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. bool empty() const;
  24. void clear();
  25. %extend {
  26. const T& get(const K& key) throw (std::out_of_range) {
  27. std::map<K,T >::iterator i = self->find(key);
  28. if (i != self->end())
  29. return i->second;
  30. else
  31. throw std::out_of_range("key not found");
  32. }
  33. void set(const K& key, const T& x) {
  34. (*self)[key] = x;
  35. }
  36. void del(const K& key) throw (std::out_of_range) {
  37. std::map<K,T >::iterator i = self->find(key);
  38. if (i != self->end())
  39. self->erase(i);
  40. else
  41. throw std::out_of_range("key not found");
  42. }
  43. bool has_key(const K& key) {
  44. std::map<K,T >::iterator i = self->find(key);
  45. return i != self->end();
  46. }
  47. }
  48. };
  49. // Legacy macros (deprecated)
  50. %define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
  51. #warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary"
  52. %enddef
  53. %define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
  54. #warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary"
  55. %enddef
  56. %define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
  57. #warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary"
  58. %enddef
  59. }