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

« back to all changes in this revision

Viewing changes to Lib/ruby/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
// Ruby implementation
7
7
 
8
 
%include std_common.i
9
 
%include exception.i
10
 
 
11
 
%exception std::vector::__getitem__ {
12
 
    try {
13
 
        $action
14
 
    } catch (std::out_of_range& e) {
15
 
        SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
16
 
    }
17
 
}
18
 
 
19
 
%exception std::vector::__setitem__ {
20
 
    try {
21
 
        $action
22
 
    } catch (std::out_of_range& e) {
23
 
        SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
24
 
    }
25
 
}
26
 
 
27
 
%exception std::vector::pop  {
28
 
    try {
29
 
        $action
30
 
    } catch (std::out_of_range& e) {
31
 
        SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
32
 
    }
33
 
}
34
 
 
 
8
%include <std_common.i>
35
9
 
36
10
// ------------------------------------------------------------------------
37
11
// std::vector
179
153
        %rename(push) push_back;
180
154
        void push_back(const T& x);
181
155
        %extend {
182
 
            T pop() {
 
156
            T pop() throw (std::out_of_range) {
183
157
                if (self->size() == 0)
184
158
                    throw std::out_of_range("pop from empty vector");
185
159
                T x = self->back();
186
160
                self->pop_back();
187
161
                return x;
188
162
            }
189
 
            T& __getitem__(int i) {
 
163
            T& __getitem__(int i) throw (std::out_of_range) {
190
164
                int size = int(self->size());
191
165
                if (i<0) i += size;
192
166
                if (i>=0 && i<size)
194
168
                else
195
169
                    throw std::out_of_range("vector index out of range");
196
170
            }
197
 
            void __setitem__(int i, const T& x) {
 
171
            void __setitem__(int i, const T& x) throw (std::out_of_range) {
198
172
                int size = int(self->size());
199
173
                if (i<0) i+= size;
200
174
                if (i>=0 && i<size)
325
299
        %rename(push) push_back;
326
300
        void push_back(T* x);
327
301
        %extend {
328
 
            T* pop() {
 
302
            T* pop() throw (std::out_of_range) {
329
303
                if (self->size() == 0)
330
304
                    throw std::out_of_range("pop from empty vector");
331
305
                T* x = self->back();
332
306
                self->pop_back();
333
307
                return x;
334
308
            }
335
 
            T* __getitem__(int i) {
 
309
            T* __getitem__(int i) throw (std::out_of_range) {
336
310
                int size = int(self->size());
337
311
                if (i<0) i += size;
338
312
                if (i>=0 && i<size)
340
314
                else
341
315
                    throw std::out_of_range("vector index out of range");
342
316
            }
343
 
            void __setitem__(int i, T* x) {
 
317
            void __setitem__(int i, T* x) throw (std::out_of_range) {
344
318
                int size = int(self->size());
345
319
                if (i<0) i+= size;
346
320
                if (i>=0 && i<size)
471
445
        %rename(push) push_back;
472
446
        void push_back(T x);
473
447
        %extend {
474
 
            T pop() {
 
448
            T pop() throw (std::out_of_range) {
475
449
                if (self->size() == 0)
476
450
                    throw std::out_of_range("pop from empty vector");
477
451
                T x = self->back();
478
452
                self->pop_back();
479
453
                return x;
480
454
            }
481
 
            T __getitem__(int i) {
 
455
            T __getitem__(int i) throw (std::out_of_range) {
482
456
                int size = int(self->size());
483
457
                if (i<0) i += size;
484
458
                if (i>=0 && i<size)
486
460
                else
487
461
                    throw std::out_of_range("vector index out of range");
488
462
            }
489
 
            void __setitem__(int i, T x) {
 
463
            void __setitem__(int i, T x) throw (std::out_of_range) {
490
464
                int size = int(self->size());
491
465
                if (i<0) i+= size;
492
466
                if (i>=0 && i<size)