diff options
author | Vince Harron <vharron@google.com> | 2015-06-07 21:43:05 -0700 |
---|---|---|
committer | Vince Harron <vharron@google.com> | 2015-06-08 08:33:11 -0700 |
commit | 330b6544424d02bcdf29653dd889d524d2e6f7d2 (patch) | |
tree | 4c40fd53e5c12fcc83aeaa06f27fa606bcfe3d3c /share/swig/2.0.11/ocaml/std_vector.i | |
parent | 7b7c39b73762eb3aa12d79a3893e156fd801468e (diff) | |
download | windows-x86-330b6544424d02bcdf29653dd889d524d2e6f7d2.tar.gz |
Adding binaries for 2.0.11HEADstudio-master-dev_before_27917934studio-master-dev_before_26911779studio-3.1.2studio-2.3studio-2.0-rc1studio-2.0studio-1.5studio-1.4gradle_3.1.2gradle_2.3.0gradle_2.0.0studio-master-releasestudio-1.4-releasestudio-1.4-devstudio-1.3-releasestudio-1.3-devmastermain
Diffstat (limited to 'share/swig/2.0.11/ocaml/std_vector.i')
-rw-r--r-- | share/swig/2.0.11/ocaml/std_vector.i | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/share/swig/2.0.11/ocaml/std_vector.i b/share/swig/2.0.11/ocaml/std_vector.i new file mode 100644 index 0000000..53d1074 --- /dev/null +++ b/share/swig/2.0.11/ocaml/std_vector.i @@ -0,0 +1,89 @@ +/* ----------------------------------------------------------------------------- + * std_vector.i + * + * SWIG typemaps for std::vector types + * ----------------------------------------------------------------------------- */ + +%include <std_common.i> + +// ------------------------------------------------------------------------ +// std::vector +// +// The aim of all that follows would be to integrate std::vector with +// Python as much as possible, namely, to allow the user to pass and +// be returned Python tuples or lists. +// const declarations are used to guess the intent of the function being +// exported; therefore, the following rationale is applied: +// +// -- f(std::vector<T>), f(const std::vector<T>&), f(const std::vector<T>*): +// the parameter being read-only, either a Python sequence or a +// previously wrapped std::vector<T> can be passed. +// -- f(std::vector<T>&), f(std::vector<T>*): +// the parameter must be modified; therefore, only a wrapped std::vector +// can be passed. +// -- std::vector<T> f(): +// the vector is returned by copy; therefore, a Python sequence of T:s +// is returned which is most easily used in other Python functions +// -- std::vector<T>& f(), std::vector<T>* f(), const std::vector<T>& f(), +// const std::vector<T>* f(): +// the vector is returned by reference; therefore, a wrapped std::vector +// is returned +// ------------------------------------------------------------------------ + +%{ +#include <vector> +#include <algorithm> +#include <stdexcept> +%} + +// exported class + +namespace std { + template <class T> class vector { + public: + vector(unsigned int size = 0); + vector(unsigned int size, const T& value); + vector(const vector<T>&); + unsigned int size() const; + bool empty() const; + void clear(); + void push_back(const T& x); + T operator [] ( int f ); + vector <T> &operator = ( vector <T> &other ); + %extend { + void set( int i, const T &x ) { + self->resize(i+1); + (*self)[i] = x; + } + }; + %extend { + T *to_array() { + T *array = new T[self->size() + 1]; + for( int i = 0; i < self->size(); i++ ) + array[i] = (*self)[i]; + return array; + } + }; + }; +}; + +%insert(ml) %{ + + let array_to_vector v argcons array = + for i = 0 to (Array.length array) - 1 do + (invoke v) "set" (C_list [ C_int i ; (argcons array.(i)) ]) + done ; + v + + let vector_to_array v argcons array = + for i = 0; to (get_int ((invoke v) "size" C_void)) - 1 do + array.(i) <- argcons ((invoke v) "[]" (C_int i)) + done ; + v + +%} + +%insert(mli) %{ + val array_to_vector : c_obj -> ('a -> c_obj) -> 'a array -> c_obj + val vector_to_array : c_obj -> (c_obj -> 'a) -> 'a array -> c_obj +%} |