1 /* -----------------------------------------------------------------------------
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.
7 * SWIG typemaps for std::vector types
8 * ----------------------------------------------------------------------------- */
10 %include <std_common.i>
12 // ------------------------------------------------------------------------
15 // The aim of all that follows would be to integrate std::vector with
16 // Python as much as possible, namely, to allow the user to pass and
17 // be returned Python tuples or lists.
18 // const declarations are used to guess the intent of the function being
19 // exported; therefore, the following rationale is applied:
21 // -- f(std::vector<T>), f(const std::vector<T>&), f(const std::vector<T>*):
22 // the parameter being read-only, either a Python sequence or a
23 // previously wrapped std::vector<T> can be passed.
24 // -- f(std::vector<T>&), f(std::vector<T>*):
25 // the parameter must be modified; therefore, only a wrapped std::vector
27 // -- std::vector<T> f():
28 // the vector is returned by copy; therefore, a Python sequence of T:s
29 // is returned which is most easily used in other Python functions
30 // -- std::vector<T>& f(), std::vector<T>* f(), const std::vector<T>& f(),
31 // const std::vector<T>* f():
32 // the vector is returned by reference; therefore, a wrapped std::vector
34 // ------------------------------------------------------------------------
45 template <class T> class vector {
47 vector(unsigned int size = 0);
48 vector(unsigned int size, const T& value);
49 vector(const vector<T>&);
50 unsigned int size() const;
53 void push_back(const T& x);
54 T operator [] ( int f );
55 vector <T> &operator = ( vector <T> &other );
57 void set( int i, const T &x ) {
64 T *array = new T[self->size() + 1];
65 for( int i = 0; i < self->size(); i++ )
66 array[i] = (*self)[i];
75 let array_to_vector v argcons array =
76 for i = 0 to (Array.length array) - 1 do
77 (invoke v) "set" (C_list [ C_int i ; (argcons array.(i)) ])
81 let vector_to_array v argcons array =
82 for i = 0; to (get_int ((invoke v) "size" C_void)) - 1 do
83 array.(i) <- argcons ((invoke v) "[]" (C_int i))
90 val array_to_vector : c_obj -> ('a -> c_obj) -> 'a array -> c_obj
91 val vector_to_array : c_obj -> (c_obj -> 'a) -> 'a array -> c_obj