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
|
|
@ -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