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

« back to all changes in this revision

Viewing changes to Lib/perl5/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:
9
9
//
10
10
// Perl implementation
11
11
 
12
 
%include std_common.i
13
 
%include exception.i
14
 
 
15
 
// containers
16
 
 
17
 
// methods which can raise are caused to throw an IndexError
18
 
%exception std::vector::get {
19
 
    try {
20
 
        $action
21
 
    } catch (std::out_of_range& e) {
22
 
        SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
23
 
    }
24
 
}
25
 
 
26
 
%exception std::vector::set {
27
 
    try {
28
 
        $action
29
 
    } catch (std::out_of_range& e) {
30
 
        SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
31
 
    }
32
 
}
33
 
 
34
 
%exception std::vector::pop {
35
 
    try {
36
 
        $action
37
 
    } catch (std::out_of_range& e) {
38
 
        SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
39
 
    }
40
 
}
41
 
 
 
12
%include <std_common.i>
42
13
 
43
14
// ------------------------------------------------------------------------
44
15
// std::vector
226
197
        %rename(push) push_back;
227
198
        void push_back(const T& x);
228
199
        %extend {
229
 
            T pop() {
 
200
            T pop() throw (std::out_of_range) {
230
201
                if (self->size() == 0)
231
202
                    throw std::out_of_range("pop from empty vector");
232
203
                T x = self->back();
233
204
                self->pop_back();
234
205
                return x;
235
206
            }
236
 
            T& get(int i) {
 
207
            T& get(int i) throw (std::out_of_range) {
237
208
                int size = int(self->size());
238
209
                if (i>=0 && i<size)
239
210
                    return (*self)[i];
240
211
                else
241
212
                    throw std::out_of_range("vector index out of range");
242
213
            }
243
 
            void set(int i, const T& x) {
 
214
            void set(int i, const T& x) throw (std::out_of_range) {
244
215
                int size = int(self->size());
245
216
                if (i>=0 && i<size)
246
217
                    (*self)[i] = x;
295
266
                               "Expected an array of " #T);
296
267
                SV **tv;
297
268
                I32 len = av_len(av) + 1;
298
 
                T* obj;
299
269
                for (int i=0; i<len; i++) {
300
270
                    tv = av_fetch(av, i, 0);
301
271
                    if (CHECK_T(*tv)) {
313
283
            }
314
284
        }
315
285
        %typemap(out) vector<T> {
316
 
            int len = $1.size();
 
286
            size_t len = $1.size();
317
287
            SV **svs = new SV*[len];
318
 
            for (unsigned int i=0; i<len; i++) {
 
288
            for (size_t i=0; i<len; i++) {
319
289
                svs[i] = sv_newmortal();
320
290
                FROM_T(svs[i], $1[i]);
321
291
            }
397
367
        %rename(push) push_back;
398
368
        void push_back(T x);
399
369
        %extend {
400
 
            T pop() {
 
370
            T pop() throw (std::out_of_range) {
401
371
                if (self->size() == 0)
402
372
                    throw std::out_of_range("pop from empty vector");
403
373
                T x = self->back();
404
374
                self->pop_back();
405
375
                return x;
406
376
            }
407
 
            T get(int i) {
 
377
            T get(int i) throw (std::out_of_range) {
408
378
                int size = int(self->size());
409
379
                if (i>=0 && i<size)
410
380
                    return (*self)[i];
411
381
                else
412
382
                    throw std::out_of_range("vector index out of range");
413
383
            }
414
 
            void set(int i, T x) {
 
384
            void set(int i, T x) throw (std::out_of_range) {
415
385
                int size = int(self->size());
416
386
                if (i>=0 && i<size)
417
387
                    (*self)[i] = x;