Java std::vector std::list enhancements
- Add missing vector copy constructor - Add constructor to initialize the containers. Note that Java's equivalent constructor for ArrayList just sets the capacity, whereas the wrappers behave like the C++ constructor and set the size. I've done this mainly because there has been a vector(size_type) constructor in the Java wrappers for many years, so best to keep this unchanged.
This commit is contained in:
parent
b40b9aee83
commit
ea55c5bba0
5 changed files with 114 additions and 12 deletions
|
|
@ -29,7 +29,7 @@ SWIGINTERN jint SWIG_ListSize(size_t size) {
|
|||
namespace std {
|
||||
template <typename T> class list {
|
||||
|
||||
%typemap(javabase) std::list< T > "java.util.AbstractSequentialList<$typemap(jboxtype, T)>"
|
||||
%typemap(javabase) std::list<T> "java.util.AbstractSequentialList<$typemap(jboxtype, T)>"
|
||||
%proxycode %{
|
||||
public $javaclassname(java.util.Collection c) {
|
||||
this();
|
||||
|
|
@ -158,7 +158,6 @@ namespace std {
|
|||
};
|
||||
|
||||
list();
|
||||
list(size_type n, const T &value = T());
|
||||
list(const list &other);
|
||||
~list();
|
||||
void assign(size_type n, const T &value);
|
||||
|
|
@ -178,6 +177,18 @@ namespace std {
|
|||
|
||||
%extend {
|
||||
%fragment("SWIG_ListSize");
|
||||
list(jint count) {
|
||||
if (count < 0)
|
||||
throw std::out_of_range("list count must be positive");
|
||||
return new std::list<T>(static_cast<std::list<T>::size_type>(count));
|
||||
}
|
||||
|
||||
list(jint count, const T &value) {
|
||||
if (count < 0)
|
||||
throw std::out_of_range("list count must be positive");
|
||||
return new std::list<T>(static_cast<std::list<T>::size_type>(count), value);
|
||||
}
|
||||
|
||||
jint doSize() const throw (std::out_of_range) {
|
||||
return SWIG_ListSize(self->size());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ SWIGINTERN jint SWIG_VectorSize(size_t size) {
|
|||
typedef CTYPE value_type;
|
||||
typedef CREF_TYPE const_reference;
|
||||
vector();
|
||||
vector(size_type n);
|
||||
vector(const vector &other);
|
||||
size_type capacity() const;
|
||||
void reserve(size_type n);
|
||||
%rename(isEmpty) empty;
|
||||
|
|
@ -83,6 +83,18 @@ SWIGINTERN jint SWIG_VectorSize(size_t size) {
|
|||
void clear();
|
||||
%extend {
|
||||
%fragment("SWIG_VectorSize");
|
||||
vector(jint count) {
|
||||
if (count < 0)
|
||||
throw std::out_of_range("vector count must be positive");
|
||||
return new std::vector< CTYPE >(static_cast<std::vector< CTYPE >::size_type>(count));
|
||||
}
|
||||
|
||||
vector(jint count, const CTYPE &value) {
|
||||
if (count < 0)
|
||||
throw std::out_of_range("vector count must be positive");
|
||||
return new std::vector< CTYPE >(static_cast<std::vector< CTYPE >::size_type>(count), value);
|
||||
}
|
||||
|
||||
jint doSize() const throw (std::out_of_range) {
|
||||
return SWIG_VectorSize(self->size());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue