PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/d/std_map.i

#
Swig | 59 lines | 48 code | 6 blank | 5 comment | 0 complexity | 304148b9456230c8c94aa922142f09ca 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. typedef size_t size_type;
  21. typedef ptrdiff_t difference_type;
  22. typedef K key_type;
  23. typedef T mapped_type;
  24. map();
  25. map(const map<K,T> &);
  26. unsigned int size() const;
  27. bool empty() const;
  28. void clear();
  29. %extend {
  30. const T& get(const K& key) throw (std::out_of_range) {
  31. std::map<K,T >::iterator i = self->find(key);
  32. if (i != self->end())
  33. return i->second;
  34. else
  35. throw std::out_of_range("key not found");
  36. }
  37. void set(const K& key, const T& x) {
  38. (*self)[key] = x;
  39. }
  40. void del(const K& key) throw (std::out_of_range) {
  41. std::map<K,T >::iterator i = self->find(key);
  42. if (i != self->end())
  43. self->erase(i);
  44. else
  45. throw std::out_of_range("key not found");
  46. }
  47. bool has_key(const K& key) {
  48. std::map<K,T >::iterator i = self->find(key);
  49. return i != self->end();
  50. }
  51. }
  52. };
  53. }