Statistics
| Branch: | Revision:

root / ide / org.omnetpp.ide.nativelibs / std_vector.i @ master

History | View | Annotate | Download (1.68 KB)

1 0418c1a0 Simon Tenbusch
/* -----------------------------------------------------------------------------
2
 * See the LICENSE file for information on copyright, usage and redistribution
3
 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
4
 *
5
 * std_vector.i
6
 * ----------------------------------------------------------------------------- */
7
8
%include <std_common.i>
9
10
%{
11
#include <vector>
12
#include <stdexcept>
13
%}
14
15
namespace std {
16
17
    template<class T> class vector {
18
      public:
19
        typedef size_t size_type;
20
        typedef T value_type;
21
        typedef const value_type& const_reference;
22
        vector();
23
        vector(size_type n);
24
        size_type size() const;
25
        size_type capacity() const;
26
        void reserve(size_type n);
27
        %rename(isEmpty) empty;
28
        bool empty() const;
29
        void clear();
30
        %rename(add) push_back;
31
        void push_back(const value_type& x);
32
        %extend {
33
            /*const_reference*/T get(int i) throw (std::out_of_range) {
34
                int size = int(self->size());
35
                if (i>=0 && i<size)
36
                    return (*self)[i];
37
                else
38
                    throw std::out_of_range("vector index out of range");
39
            }
40
            void set(int i, const value_type& x) throw (std::out_of_range) {
41
                int size = int(self->size());
42
                if (i>=0 && i<size)
43
                    (*self)[i] = x;
44
                else
45
                    throw std::out_of_range("vector index out of range");
46
            }
47
        }
48
    };
49
}
50
51
%define specialize_std_vector(T)
52
#warning "specialize_std_vector - specialization for type T no longer needed"
53
%enddef
54