Use std/std_vector.i instead of a poor copy in c/std_vector.i

At the very least, this gives us a working vector<bool> and allows
"li_std_vector" unit test to pass. It is also just nice to reuse the existing
typemaps instead of having another copy of them.

As C doesn't have UTL, some parts of std_vector.i had to be excluded from it
however.
This commit is contained in:
Vadim Zeitlin 2016-04-26 14:47:36 +02:00
commit d89a95a48c
7 changed files with 27 additions and 60 deletions

1
Lib/c/std_alloc.i Normal file
View file

@ -0,0 +1 @@
%include <std/std_alloc.i>

View file

@ -1,3 +1,7 @@
%include <typemaps/fragments.swg>
%include <typemaps/swigmacros.swg>
%include <std/std_common.i>
%include <std_except.i>
%apply size_t { std::size_t };

1
Lib/c/std_container.i Normal file
View file

@ -0,0 +1 @@
%include <std/std_container.i>

View file

@ -1,58 +1,13 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* std_vector.i
* ----------------------------------------------------------------------------- */
// Wrap const and non-const at() methods as set() and get(), this is simpler to use from C and more clear.
%define %swig_vector_methods(Type...)
%extend {
void set(size_type n, const value_type& val) { self->at(n) = val; }
value_type get(size_type n) const { return self->at(n); }
}
%enddef
%include <std_common.i>
%{
#include <vector>
#include <stdexcept>
%}
namespace std {
template<class T> class vector {
public:
typedef size_t size_type;
typedef T value_type;
typedef const value_type& const_reference;
vector();
vector(size_type n);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
bool empty() const;
void clear();
void push_back(const value_type& x);
const_reference at(size_type i);
};
%define specialize_std_vector(T)
template<> class vector<T> {
public:
typedef size_t size_type;
typedef T value_type;
vector();
vector(size_type n);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
bool empty() const;
void clear();
void push_back(T x) { this->push_back(x); }
T at(size_type i) { return this->at(i); }
};
%enddef
specialize_std_vector(int);
specialize_std_vector(bool);
/*specialize_std_vector(long);
specialize_std_vector(char);
specialize_std_vector(double);
specialize_std_vector(int*);
specialize_std_vector(char*);*/
}
%define %swig_vector_methods_val(Type...)
%swig_vector_methods(Type...)
%enddef
%include <std/std_vector.i>