PageRenderTime 19ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/perl5/std_map.i

#
Swig | 70 lines | 54 code | 11 blank | 5 comment | 0 complexity | a6b40c50e7459cdcbd32c4456a040912 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        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
57// Legacy macros (deprecated)
58%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
59#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary"
60%enddef
61
62%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
63#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary"
64%enddef
65
66%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
67#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary"
68%enddef
69
70}