PageRenderTime 15ms CodeModel.GetById 11ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Lib/php/std_map.i

#
Swig | 72 lines | 56 code | 11 blank | 5 comment | 0 complexity | 9453d04e870635e047dbc24aa2fbeceb MD5 | raw file
 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
21namespace std {
22
23    template<class K, class T> class map {
24        // add typemaps here
25      public:
26        map();
27        map(const map<K,T> &);
28        
29        unsigned int size() const;
30        void clear();
31        %extend {
32            const T& get(const K& key) throw (std::out_of_range) {
33                std::map<K,T >::iterator i = self->find(key);
34                if (i != self->end())
35                    return i->second;
36                else
37                    throw std::out_of_range("key not found");
38            }
39            void set(const K& key, const T& x) {
40                (*self)[key] = x;
41            }
42            void del(const K& key) throw (std::out_of_range) {
43                std::map<K,T >::iterator i = self->find(key);
44                if (i != self->end())
45                    self->erase(i);
46                else
47                    throw std::out_of_range("key not found");
48            }
49            bool has_key(const K& key) {
50                std::map<K,T >::iterator i = self->find(key);
51                return i != self->end();
52            }
53            bool is_empty() const {
54                return self->empty();
55            }
56        }
57    };
58
59// Legacy macros (deprecated)
60%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
61#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary"
62%enddef
63
64%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
65#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary"
66%enddef
67
68%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
69#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary"
70%enddef
71
72}