Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.9 KiB

  1. /* -----------------------------------------------------------------------------
  2. * See the LICENSE file for information on copyright, usage and redistribution
  3. * of SWIG, and the README file for authors - http://www.swig.org/release.html.
  4. *
  5. * std_map.i
  6. *
  7. * SWIG typemaps for std::map
  8. * ----------------------------------------------------------------------------- */
  9. %include <std_common.i>
  10. // ------------------------------------------------------------------------
  11. // std::map
  12. // ------------------------------------------------------------------------
  13. %{
  14. #include <map>
  15. #include <algorithm>
  16. #include <stdexcept>
  17. %}
  18. // exported class
  19. namespace std {
  20. template<class K, class T> class map {
  21. // add typemaps here
  22. public:
  23. typedef size_t size_type;
  24. typedef ptrdiff_t difference_type;
  25. typedef K key_type;
  26. typedef T mapped_type;
  27. map();
  28. map(const map<K,T> &);
  29. unsigned int size() const;
  30. bool empty() const;
  31. void clear();
  32. %extend {
  33. const T& get(const K& key) throw (std::out_of_range) {
  34. std::map<K,T >::iterator i = self->find(key);
  35. if (i != self->end())
  36. return i->second;
  37. else
  38. throw std::out_of_range("key not found");
  39. }
  40. void set(const K& key, const T& x) {
  41. (*self)[key] = x;
  42. }
  43. void del(const K& key) throw (std::out_of_range) {
  44. std::map<K,T >::iterator i = self->find(key);
  45. if (i != self->end())
  46. self->erase(i);
  47. else
  48. throw std::out_of_range("key not found");
  49. }
  50. bool has_key(const K& key) {
  51. std::map<K,T >::iterator i = self->find(key);
  52. return i != self->end();
  53. }
  54. }
  55. };
  56. }