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.
7 * SWIG typemaps for std::map
8 * ----------------------------------------------------------------------------- */
10 %include <std_common.i>
12 // ------------------------------------------------------------------------
14 // ------------------------------------------------------------------------
26 template<class K, class T> class map {
30 map(const map<K,T> &);
32 unsigned int size() const;
36 T& get(const K& key) throw (std::out_of_range) {
37 std::map<K,T >::iterator i = self->find(key);
41 throw std::out_of_range("key not found");
43 void set(const K& key, const T& x) {
46 void del(const K& key) throw (std::out_of_range) {
47 std::map<K,T >::iterator i = self->find(key);
51 throw std::out_of_range("key not found");
53 bool has_key(const K& key) {
54 std::map<K,T >::iterator i = self->find(key);
55 return i != self->end();
61 // specializations for built-ins
63 %define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
65 template<class T> class map<K,T> {
69 map(const map<K,T> &);
71 unsigned int size() const;
75 T& get(K key) throw (std::out_of_range) {
76 std::map<K,T >::iterator i = self->find(key);
80 throw std::out_of_range("key not found");
82 void set(K key, const T& x) {
85 void del(K key) throw (std::out_of_range) {
86 std::map<K,T >::iterator i = self->find(key);
90 throw std::out_of_range("key not found");
93 std::map<K,T >::iterator i = self->find(key);
94 return i != self->end();
100 %define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
101 template<class K> class map<K,T> {
105 map(const map<K,T> &);
107 unsigned int size() const;
111 T get(const K& key) throw (std::out_of_range) {
112 std::map<K,T >::iterator i = self->find(key);
113 if (i != self->end())
116 throw std::out_of_range("key not found");
118 void set(const K& key, T x) {
121 void del(const K& key) throw (std::out_of_range) {
122 std::map<K,T >::iterator i = self->find(key);
123 if (i != self->end())
126 throw std::out_of_range("key not found");
128 bool has_key(const K& key) {
129 std::map<K,T >::iterator i = self->find(key);
130 return i != self->end();
136 %define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO,
137 T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
138 template<> class map<K,T> {
142 map(const map<K,T> &);
144 unsigned int size() const;
148 T get(K key) throw (std::out_of_range) {
149 std::map<K,T >::iterator i = self->find(key);
150 if (i != self->end())
153 throw std::out_of_range("key not found");
155 void set(K key, T x) {
158 void del(K key) throw (std::out_of_range) {
159 std::map<K,T >::iterator i = self->find(key);
160 if (i != self->end())
163 throw std::out_of_range("key not found");
165 bool has_key(K key) {
166 std::map<K,T >::iterator i = self->find(key);
167 return i != self->end();
173 // add specializations here