~ubuntu-branches/ubuntu/edgy/swig1.3/edgy

« back to all changes in this revision

Viewing changes to Lib/php4/std_vector.i

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:16:04 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205011604-ygx904it6413k3go
Tags: 1.3.27-1ubuntu1
Resynchronise with Debian again, for the new subversion packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
//
6
6
// PHP implementation
7
7
 
8
 
%include exception.i
9
 
 
10
 
// containers
11
 
 
12
 
// methods which can raise are caused to throw an IndexError
13
 
%exception std::vector::get {
14
 
    try {
15
 
        $action
16
 
    } catch (std::out_of_range& e) {
17
 
        SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
18
 
    }
19
 
}
20
 
 
21
 
%exception std::vector::set {
22
 
    try {
23
 
        $action
24
 
    } catch (std::out_of_range& e) {
25
 
        SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
26
 
    }
27
 
}
28
 
 
29
 
%exception std::vector::pop {
30
 
    try {
31
 
        $action
32
 
    } catch (std::out_of_range& e) {
33
 
        SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
34
 
    }
35
 
}
36
 
 
 
8
%include <std_common.i>
37
9
 
38
10
// ------------------------------------------------------------------------
39
11
// std::vector
79
51
        %rename(push) push_back;
80
52
        void push_back(const T& x);
81
53
        %extend {
82
 
            T pop() {
 
54
            T pop() throw (std::out_of_range) {
83
55
                if (self->size() == 0)
84
56
                    throw std::out_of_range("pop from empty vector");
85
57
                T x = self->back();
86
58
                self->pop_back();
87
59
                return x;
88
60
            }
89
 
            T& get(int i) {
 
61
            T& get(int i) throw (std::out_of_range) {
90
62
                int size = int(self->size());
91
63
                if (i>=0 && i<size)
92
64
                    return (*self)[i];
93
65
                else
94
66
                    throw std::out_of_range("vector index out of range");
95
67
            }
96
 
            void set(int i, const T& x) {
 
68
            void set(int i, const T& x) throw (std::out_of_range) {
97
69
                int size = int(self->size());
98
70
                if (i>=0 && i<size)
99
71
                    (*self)[i] = x;
117
89
        %rename(push) push_back;
118
90
        void push_back(T x);
119
91
        %extend {
120
 
            T pop() {
 
92
            T pop() throw (std::out_of_range) {
121
93
                if (self->size() == 0)
122
94
                    throw std::out_of_range("pop from empty vector");
123
95
                T x = self->back();
124
96
                self->pop_back();
125
97
                return x;
126
98
            }
127
 
            T get(int i) {
 
99
            T get(int i) throw (std::out_of_range) {
128
100
                int size = int(self->size());
129
101
                if (i>=0 && i<size)
130
102
                    return (*self)[i];
131
103
                else
132
104
                    throw std::out_of_range("vector index out of range");
133
105
            }
134
 
            void set(int i, T x) {
 
106
            void set(int i, T x) throw (std::out_of_range) {
135
107
                int size = int(self->size());
136
108
                if (i>=0 && i<size)
137
109
                    (*self)[i] = x;