Statistics
| Branch: | Revision:

root / src / org.omnetpp.ide.nativelibs / std_set.i @ 79bb12dc

History | View | Annotate | Download (2.68 KB)

1
//
2
// SWIG typemaps for std::set
3
// Andras Varga
4
// Aug. 2005
5
//
6
// Common implementation
7

    
8
%include std_common.i
9
%include exception.i
10

    
11
%exception std::set::del  {
12
    try {
13
        $action
14
    } catch (std::out_of_range& e) {
15
        SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, const_cast<char*>(e.what()));
16
        return $null;
17
    }
18
}
19

    
20
// ------------------------------------------------------------------------
21
// std::set
22
// ------------------------------------------------------------------------
23

    
24
%{
25
#include <set>
26
#include <algorithm>
27
#include <stdexcept>
28
%}
29

    
30
// exported class
31

    
32
namespace std {
33

    
34
    template<class T> class set {
35
        // add typemaps here
36
      public:
37
        set();
38
        set(const set<T> &);
39

    
40
        unsigned int size() const;
41
        bool empty() const;
42
        void clear();
43
        %extend {
44
            void insert(const T& key) {
45
                self->insert(key);
46
            }
47
            void del(const T& key) {
48
                std::set<T>::iterator i = self->find(key);
49
                if (i != self->end())
50
                    self->erase(i);
51
                else
52
                    throw std::out_of_range("key not found");
53
            }
54
            bool has_key(const T& key) {
55
                std::set<T>::iterator i = self->find(key);
56
                return i != self->end();
57
            }
58
        }
59
    };
60

    
61
    // specializations for built-ins
62

    
63
    %define specialize_std_set(T)
64

    
65
    template<> class set<T> {
66
        // add typemaps here
67
      public:
68
        set();
69
        set(const set<T> &);
70

    
71
        unsigned int size() const;
72
        bool empty() const;
73
        void clear();
74
        %extend {
75
            void insert(T key) {
76
                self->insert(key);
77
            }
78
            void del(T key) {
79
                std::set<T>::iterator i = self->find(key);
80
                if (i != self->end())
81
                    self->erase(i);
82
                else
83
                    throw std::out_of_range("key not found");
84
            }
85
            bool has_key(T key) {
86
                std::set<T>::iterator i = self->find(key);
87
                return i != self->end();
88
            }
89
        }
90
    };
91

    
92

    
93
    %enddef
94

    
95
    // add specializations here
96

    
97
    specialize_std_set(bool);
98
    specialize_std_set(char);
99
    specialize_std_set(int);
100
    specialize_std_set(short);
101
    specialize_std_set(long);
102
    specialize_std_set(unsigned char);
103
    specialize_std_set(unsigned int);
104
    specialize_std_set(unsigned short);
105
    specialize_std_set(unsigned long);
106
    specialize_std_set(float);
107
    specialize_std_set(double);
108
    specialize_std_set(std::string);
109
}