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 // ------------------------------------------------------------------------
25 template<class K, class T> class map {
29 map(const map<K,T> &);
31 unsigned int size() const;
35 T& get(const K& key) throw (std::out_of_range) {
36 std::map<K,T >::iterator i = self->find(key);
40 throw std::out_of_range("key not found");
42 void set(const K& key, const T& x) {
45 void del(const K& key) throw (std::out_of_range) {
46 std::map<K,T >::iterator i = self->find(key);
50 throw std::out_of_range("key not found");
52 bool has_key(const K& key) {
53 std::map<K,T >::iterator i = self->find(key);
54 return i != self->end();
60 // specializations for built-ins
62 %define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
64 template<class T> class map<K,T> {
68 map(const map<K,T> &);
70 unsigned int size() const;
74 T& get(K key) throw (std::out_of_range) {
75 std::map<K,T >::iterator i = self->find(key);
79 throw std::out_of_range("key not found");
81 void set(K key, const T& x) {
84 void del(K key) throw (std::out_of_range) {
85 std::map<K,T >::iterator i = self->find(key);
89 throw std::out_of_range("key not found");
92 std::map<K,T >::iterator i = self->find(key);
93 return i != self->end();
99 %define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
100 template<class K> class map<K,T> {
104 map(const map<K,T> &);
106 unsigned int size() const;
110 T get(const K& key) throw (std::out_of_range) {
111 std::map<K,T >::iterator i = self->find(key);
112 if (i != self->end())
115 throw std::out_of_range("key not found");
117 void set(const K& key, T x) {
120 void del(const K& key) throw (std::out_of_range) {
121 std::map<K,T >::iterator i = self->find(key);
122 if (i != self->end())
125 throw std::out_of_range("key not found");
127 bool has_key(const K& key) {
128 std::map<K,T >::iterator i = self->find(key);
129 return i != self->end();
135 %define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO,
136 T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
137 template<> class map<K,T> {
141 map(const map<K,T> &);
143 unsigned int size() const;
147 T get(K key) throw (std::out_of_range) {
148 std::map<K,T >::iterator i = self->find(key);
149 if (i != self->end())
152 throw std::out_of_range("key not found");
154 void set(K key, T x) {
157 void del(K key) throw (std::out_of_range) {
158 std::map<K,T >::iterator i = self->find(key);
159 if (i != self->end())
162 throw std::out_of_range("key not found");
164 bool has_key(K key) {
165 std::map<K,T >::iterator i = self->find(key);
166 return i != self->end();
172 // add specializations here