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

View file

@ -17,7 +17,7 @@ int main() {
printf("size=%d\ncapacity=%d\n\n", Vint_size(vint), Vint_capacity(vint));
for (i = 0; i < Vint_size(vint); i++)
printf("%d%c", Vint_at(vint, i), i+1 == Vint_size(vint) ? '\n' : ',');
printf("%d%c", Vint_get(vint, i), i+1 == Vint_size(vint) ? '\n' : ',');
Vint_clear(vint);
Vint_reserve(vint, 100);
@ -32,7 +32,7 @@ int main() {
}
for (i = 0; i < VA_size(va); i++) {
A *a = VA_at(va, i);
A *a = VA_get(va, i);
printf("%s %d\n", A_name_get(a), A_value_get(a));
}

View file

@ -76,7 +76,6 @@ FAILING_CPP_TESTS := \
li_std_map \
li_std_pair \
li_std_pair_using \
li_std_vector \
li_windows \
member_funcptr_galore \
member_pointer \

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>

View file

@ -68,6 +68,7 @@ namespace std {
typedef const _Tp& const_reference;
typedef _Alloc allocator_type;
#ifndef SWIGC
%traits_swigtype(_Tp);
%traits_enum(_Tp);
@ -85,6 +86,7 @@ namespace std {
}
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector< _Tp, _Alloc >);
#endif // !SWIGC
#ifdef %swig_vector_methods
// Add swig/language extra methods
@ -110,6 +112,7 @@ namespace std {
typedef value_type const_reference;
typedef _Alloc allocator_type;
#ifndef SWIGC
%traits_swigtype(_Tp);
%fragment(SWIG_Traits_frag(std::vector< _Tp*, _Alloc >), "header",
@ -126,6 +129,7 @@ namespace std {
}
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector< _Tp*, _Alloc >);
#endif // !SWIGC
#ifdef %swig_vector_methods_val
// Add swig/language extra methods
@ -150,6 +154,7 @@ namespace std {
typedef value_type const_reference;
typedef _Alloc allocator_type;
#ifndef SWIGC
%traits_swigtype(_Tp);
%fragment(SWIG_Traits_frag(std::vector< _Tp const*, _Alloc >), "header",
@ -166,6 +171,7 @@ namespace std {
}
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector< _Tp const*, _Alloc >);
#endif // !SWIGC
#ifdef %swig_vector_methods_val
// Add swig/language extra methods
@ -191,6 +197,7 @@ namespace std {
typedef value_type const_reference;
typedef _Alloc allocator_type;
#ifndef SWIGC
%traits_swigtype(bool);
%fragment(SWIG_Traits_frag(std::vector<bool, _Alloc >), "header",
@ -207,7 +214,7 @@ namespace std {
}
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<bool, _Alloc >);
#endif // !SWIGC
#ifdef %swig_vector_methods_val
// Add swig/language extra methods