Revert "Use std/std_vector.i instead of a poor copy in c/std_vector.i"
This reverts commit d89a95a48c as,
finally, it's not worth trying to use UTL typemaps from C: this required
bad hacks for std::vector and would be even worse for std::map, so don't
bother with them and just correct the "poor" C typemaps to be slightly
less poor and use them instead.
This commit is contained in:
parent
45bb179407
commit
5cbdae42d3
5 changed files with 90 additions and 27 deletions
|
|
@ -1 +0,0 @@
|
|||
%include <std/std_alloc.i>
|
||||
|
|
@ -1,7 +1,3 @@
|
|||
%include <typemaps/fragments.swg>
|
||||
%include <typemaps/swigmacros.swg>
|
||||
%include <std/std_common.i>
|
||||
|
||||
%include <std_except.i>
|
||||
|
||||
%apply size_t { std::size_t };
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
%include <std/std_container.i>
|
||||
|
|
@ -1,16 +1,92 @@
|
|||
// 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); }
|
||||
}
|
||||
/* -----------------------------------------------------------------------------
|
||||
* std_vector.i
|
||||
*
|
||||
* SWIG typemaps for std::vector
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
// Standard typemaps wrap get_allocator(), but it's not really useful for us, so don't bother with it.
|
||||
%ignore get_allocator
|
||||
%enddef
|
||||
%include <std_common.i>
|
||||
|
||||
%define %swig_vector_methods_val(Type...)
|
||||
%swig_vector_methods(Type...)
|
||||
%enddef
|
||||
%{
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
%}
|
||||
|
||||
%include <std/std_vector.i>
|
||||
namespace std {
|
||||
|
||||
template<class T> class vector {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef T value_type;
|
||||
typedef value_type* pointer;
|
||||
typedef const value_type* const_pointer;
|
||||
typedef value_type& reference;
|
||||
typedef const value_type& const_reference;
|
||||
|
||||
vector();
|
||||
vector(size_type n);
|
||||
vector(const vector& other);
|
||||
|
||||
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);
|
||||
%extend {
|
||||
const_reference get(int i) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
return (*self)[i];
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
void set(int i, const value_type& val) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
(*self)[i] = val;
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// bool specialization
|
||||
template<> class vector<bool> {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef bool value_type;
|
||||
typedef value_type* pointer;
|
||||
typedef const value_type* const_pointer;
|
||||
typedef value_type& reference;
|
||||
typedef bool const_reference;
|
||||
|
||||
vector();
|
||||
vector(size_type n);
|
||||
vector(const vector& other);
|
||||
|
||||
size_type size() const;
|
||||
size_type capacity() const;
|
||||
void reserve(size_type n);
|
||||
bool empty() const;
|
||||
void clear();
|
||||
void push_back(bool x);
|
||||
%extend {
|
||||
bool get(int i) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
return (*self)[i];
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
void set(int i, bool val) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
(*self)[i] = val;
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,6 @@ namespace std {
|
|||
typedef const value_type& const_reference;
|
||||
typedef _Alloc allocator_type;
|
||||
|
||||
#ifndef SWIGC
|
||||
%traits_swigtype(_Tp);
|
||||
%traits_enum(_Tp);
|
||||
|
||||
|
|
@ -86,7 +85,6 @@ namespace std {
|
|||
}
|
||||
|
||||
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector< _Tp, _Alloc >);
|
||||
#endif // !SWIGC
|
||||
|
||||
#ifdef %swig_vector_methods
|
||||
// Add swig/language extra methods
|
||||
|
|
@ -112,7 +110,6 @@ namespace std {
|
|||
typedef const value_type& const_reference;
|
||||
typedef _Alloc allocator_type;
|
||||
|
||||
#ifndef SWIGC
|
||||
%traits_swigtype(_Tp);
|
||||
|
||||
%fragment(SWIG_Traits_frag(std::vector< _Tp*, _Alloc >), "header",
|
||||
|
|
@ -129,7 +126,6 @@ namespace std {
|
|||
}
|
||||
|
||||
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector< _Tp*, _Alloc >);
|
||||
#endif // !SWIGC
|
||||
|
||||
#ifdef %swig_vector_methods_val
|
||||
// Add swig/language extra methods
|
||||
|
|
@ -154,7 +150,6 @@ namespace std {
|
|||
typedef const value_type& const_reference;
|
||||
typedef _Alloc allocator_type;
|
||||
|
||||
#ifndef SWIGC
|
||||
%traits_swigtype(_Tp);
|
||||
|
||||
%fragment(SWIG_Traits_frag(std::vector< _Tp const*, _Alloc >), "header",
|
||||
|
|
@ -171,7 +166,6 @@ 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
|
||||
|
|
@ -197,7 +191,6 @@ namespace std {
|
|||
typedef bool const_reference;
|
||||
typedef _Alloc allocator_type;
|
||||
|
||||
#ifndef SWIGC
|
||||
%traits_swigtype(bool);
|
||||
|
||||
%fragment(SWIG_Traits_frag(std::vector<bool, _Alloc >), "header",
|
||||
|
|
@ -214,7 +207,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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue