add in correct specialization for std::vector<bool> to follow C++ standard - to create compileable wrappers with vc++ and recent return by reference changes

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11153 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2009-03-16 19:33:38 +00:00
commit 956c57bb03
2 changed files with 51 additions and 5 deletions

View file

@ -24,7 +24,7 @@
// MACRO for use within the std::vector class body
// CSTYPE and CTYPE respectively correspond to the types in the cstype and ctype typemaps
%define SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE...)
%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CONST_REFERENCE_TYPE, CSTYPE, CTYPE...)
%typemap(csinterfaces) std::vector<CTYPE > "IDisposable, System.Collections.IEnumerable";
%typemap(cscode) std::vector<CTYPE > %{
public $csclassname(System.Collections.ICollection c) : this() {
@ -176,7 +176,7 @@
public:
typedef size_t size_type;
typedef CTYPE value_type;
typedef const value_type& const_reference;
typedef CONST_REFERENCE_TYPE const_reference;
%rename(Clear) clear;
void clear();
%rename(Add) push_back;
@ -286,6 +286,11 @@
}
%enddef
%define SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE...)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(const value_type&, CSTYPE, CTYPE)
%enddef
// Extra methods added to the collection class if operator== is defined for the class being wrapped
// CSTYPE and CTYPE respectively correspond to the types in the cstype and ctype typemaps
%define SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CSTYPE, CTYPE...)
@ -334,7 +339,6 @@ namespace std {
}
%enddef
%{
#include <vector>
#include <algorithm>
@ -365,7 +369,16 @@ namespace std {
// template specializations for std::vector
// these provide extra collections methods as operator== is defined
SWIG_STD_VECTOR_SPECIALIZE(bool, bool)
// extra specialization for bool
namespace std {
template<> class vector<bool > {
SWIG_STD_VECTOR_MINIMUM_INTERNAL(bool, bool, bool)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(bool, bool)
};
}
// primitive types specialization
SWIG_STD_VECTOR_SPECIALIZE(char, char)
SWIG_STD_VECTOR_SPECIALIZE(sbyte, signed char)
SWIG_STD_VECTOR_SPECIALIZE(byte, unsigned char)
@ -381,4 +394,3 @@ SWIG_STD_VECTOR_SPECIALIZE(float, float)
SWIG_STD_VECTOR_SPECIALIZE(double, double)
SWIG_STD_VECTOR_SPECIALIZE(string, std::string) // also requires a %include <std_string.i>

View file

@ -46,6 +46,40 @@ namespace std {
}
}
};
// bool specialization
template<> class vector<bool> {
public:
typedef size_t size_type;
typedef bool value_type;
typedef bool const_reference;
vector();
vector(size_type n);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
%rename(isEmpty) empty;
bool empty() const;
void clear();
%rename(add) push_back;
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");
}
}
};
}
%define specialize_std_vector(T)