1 /* ----------------------------------------------------------------------------- 2 * std_map.i 3 * 4 * SWIG typemaps for std::map 5 * ----------------------------------------------------------------------------- */ 6 7 %include <std_common.i> 8 9 // ------------------------------------------------------------------------ 10 // std::map 11 // ------------------------------------------------------------------------ 12 13 %{ 14 #include <map> 15 #include <algorithm> 16 #include <stdexcept> 17 %} 18 19 // exported class 20 21 namespace std { 22 template<class K, class T> class map { 23 // add typemaps here 24 public: 25 typedef size_t size_type; 26 typedef ptrdiff_t difference_type; 27 typedef K key_type; 28 typedef T mapped_type; 29 map(); 30 map(const map<K,T> &); 31 32 unsigned int size() const; 33 bool empty() const; 34 void clear(); 35 %extend { 36 const T& get(const K& key) throw (std::out_of_range) { 37 std::map<K,T >::iterator i = self->find(key); 38 if (i != self->end()) 39 return i->second; 40 else 41 throw std::out_of_range("key not found"); 42 } 43 void set(const K& key, const T& x) { 44 (*self)[key] = x; 45 } 46 void del(const K& key) throw (std::out_of_range) { 47 std::map<K,T >::iterator i = self->find(key); 48 if (i != self->end()) 49 self->erase(i); 50 else 51 throw std::out_of_range("key not found"); 52 } 53 bool has_key(const K& key) { 54 std::map<K,T >::iterator i = self->find(key); 55 return i != self->end(); 56 } 57 } 58 }; 59 60 // Legacy macros (deprecated) 61 %define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) 62 #warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary" 63 %enddef 64 65 %define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) 66 #warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary" 67 %enddef 68 69 %define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) 70 #warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary" 71 %enddef 72 73 } 74