Whitespace fixes in STL wrappers
This commit is contained in:
parent
fdca8e9829
commit
32e7074d9b
5 changed files with 154 additions and 160 deletions
|
|
@ -20,11 +20,11 @@
|
|||
// them, in order to achieve this.
|
||||
namespace {
|
||||
int size_as_int(std::size_t sz) {
|
||||
if (sz > static_cast<std::size_t>(INT_MAX)) {
|
||||
throw std::out_of_range("vector size is too big to be representable as int");
|
||||
}
|
||||
if (sz > static_cast<std::size_t>(INT_MAX)) {
|
||||
throw std::out_of_range("vector size is too big to be representable as int");
|
||||
}
|
||||
|
||||
return static_cast<int>(sz);
|
||||
return static_cast<int>(sz);
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
|
|
@ -82,74 +82,74 @@ int size_as_int(std::size_t sz) {
|
|||
}
|
||||
%}
|
||||
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef CTYPE value_type;
|
||||
typedef CREF_TYPE const_reference;
|
||||
vector();
|
||||
vector(size_type n);
|
||||
size_type capacity() const;
|
||||
void reserve(size_type n);
|
||||
%rename(isEmpty) empty;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%extend {
|
||||
int doSize() const {
|
||||
return size_as_int(self->size());
|
||||
}
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef CTYPE value_type;
|
||||
typedef CREF_TYPE const_reference;
|
||||
vector();
|
||||
vector(size_type n);
|
||||
size_type capacity() const;
|
||||
void reserve(size_type n);
|
||||
%rename(isEmpty) empty;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%extend {
|
||||
int doSize() const {
|
||||
return size_as_int(self->size());
|
||||
}
|
||||
|
||||
void doAdd(const value_type& value) {
|
||||
self->push_back(value);
|
||||
}
|
||||
void doAdd(const value_type& value) {
|
||||
self->push_back(value);
|
||||
}
|
||||
|
||||
void doAdd(int index, const value_type& value) throw (std::out_of_range) {
|
||||
const int size = size_as_int(self->size());
|
||||
if (0 <= index && index <= size) {
|
||||
self->insert(self->begin() + index, value);
|
||||
} else {
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
|
||||
value_type doRemove(int index) throw (std::out_of_range) {
|
||||
const int size = size_as_int(self->size());
|
||||
if (0 <= index && index < size) {
|
||||
CTYPE const old_value = (*self)[index];
|
||||
self->erase(self->begin() + index);
|
||||
return old_value;
|
||||
} else {
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
|
||||
CREF_TYPE doGet(int i) throw (std::out_of_range) {
|
||||
const int size = size_as_int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
return (*self)[i];
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
|
||||
value_type doSet(int i, const value_type& value) throw (std::out_of_range) {
|
||||
const int size = size_as_int(self->size());
|
||||
if (i>=0 && i<size) {
|
||||
CTYPE const old_value = (*self)[i];
|
||||
(*self)[i] = value;
|
||||
return old_value;
|
||||
}
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
|
||||
void doRemoveRange(int fromIndex, int toIndex) throw (std::out_of_range) {
|
||||
const int size = size_as_int(self->size());
|
||||
if (0 <= fromIndex && fromIndex <= toIndex && toIndex <= size) {
|
||||
self->erase(self->begin() + fromIndex, self->begin() + toIndex);
|
||||
} else {
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
void doAdd(int index, const value_type& value) throw (std::out_of_range) {
|
||||
const int size = size_as_int(self->size());
|
||||
if (0 <= index && index <= size) {
|
||||
self->insert(self->begin() + index, value);
|
||||
} else {
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
|
||||
value_type doRemove(int index) throw (std::out_of_range) {
|
||||
const int size = size_as_int(self->size());
|
||||
if (0 <= index && index < size) {
|
||||
CTYPE const old_value = (*self)[index];
|
||||
self->erase(self->begin() + index);
|
||||
return old_value;
|
||||
} else {
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
|
||||
CREF_TYPE doGet(int i) throw (std::out_of_range) {
|
||||
const int size = size_as_int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
return (*self)[i];
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
|
||||
value_type doSet(int i, const value_type& value) throw (std::out_of_range) {
|
||||
const int size = size_as_int(self->size());
|
||||
if (i>=0 && i<size) {
|
||||
CTYPE const old_value = (*self)[i];
|
||||
(*self)[i] = value;
|
||||
return old_value;
|
||||
}
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
|
||||
void doRemoveRange(int fromIndex, int toIndex) throw (std::out_of_range) {
|
||||
const int size = size_as_int(self->size());
|
||||
if (0 <= fromIndex && fromIndex <= toIndex && toIndex <= size) {
|
||||
self->erase(self->begin() + fromIndex, self->begin() + toIndex);
|
||||
} else {
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
%javamethodmodifiers std::vector::doSize "private";
|
||||
|
|
@ -160,7 +160,7 @@ int size_as_int(std::size_t sz) {
|
|||
%javamethodmodifiers std::vector::doRemoveRange "private";
|
||||
|
||||
namespace std {
|
||||
|
||||
|
||||
template<class T> class vector {
|
||||
SWIG_STD_VECTOR_MINIMUM_INTERNAL(T, const T&)
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue