Whitespace fixes in STL wrappers
This commit is contained in:
parent
fdca8e9829
commit
32e7074d9b
5 changed files with 154 additions and 160 deletions
|
|
@ -332,7 +332,7 @@
|
||||||
std::vector< CTYPE >::iterator it = std::find($self->begin(), $self->end(), value);
|
std::vector< CTYPE >::iterator it = std::find($self->begin(), $self->end(), value);
|
||||||
if (it != $self->end()) {
|
if (it != $self->end()) {
|
||||||
$self->erase(it);
|
$self->erase(it);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,44 +16,41 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
// exported class
|
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template<class K, class T> class map {
|
template<class K, class T> class map {
|
||||||
// add typemaps here
|
public:
|
||||||
public:
|
typedef size_t size_type;
|
||||||
typedef size_t size_type;
|
typedef ptrdiff_t difference_type;
|
||||||
typedef ptrdiff_t difference_type;
|
typedef K key_type;
|
||||||
typedef K key_type;
|
typedef T mapped_type;
|
||||||
typedef T mapped_type;
|
map();
|
||||||
map();
|
map(const map<K,T> &);
|
||||||
map(const map<K,T> &);
|
|
||||||
|
|
||||||
unsigned int size() const;
|
unsigned int size() const;
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
void clear();
|
void clear();
|
||||||
%extend {
|
%extend {
|
||||||
const T& get(const K& key) throw (std::out_of_range) {
|
const T& get(const K& key) throw (std::out_of_range) {
|
||||||
std::map<K,T >::iterator i = self->find(key);
|
std::map<K,T >::iterator i = self->find(key);
|
||||||
if (i != self->end())
|
if (i != self->end())
|
||||||
return i->second;
|
return i->second;
|
||||||
else
|
else
|
||||||
throw std::out_of_range("key not found");
|
throw std::out_of_range("key not found");
|
||||||
}
|
|
||||||
void set(const K& key, const T& x) {
|
|
||||||
(*self)[key] = x;
|
|
||||||
}
|
|
||||||
void del(const K& key) throw (std::out_of_range) {
|
|
||||||
std::map<K,T >::iterator i = self->find(key);
|
|
||||||
if (i != self->end())
|
|
||||||
self->erase(i);
|
|
||||||
else
|
|
||||||
throw std::out_of_range("key not found");
|
|
||||||
}
|
|
||||||
bool has_key(const K& key) {
|
|
||||||
std::map<K,T >::iterator i = self->find(key);
|
|
||||||
return i != self->end();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
void set(const K& key, const T& x) {
|
||||||
|
(*self)[key] = x;
|
||||||
|
}
|
||||||
|
void del(const K& key) throw (std::out_of_range) {
|
||||||
|
std::map<K,T >::iterator i = self->find(key);
|
||||||
|
if (i != self->end())
|
||||||
|
self->erase(i);
|
||||||
|
else
|
||||||
|
throw std::out_of_range("key not found");
|
||||||
|
}
|
||||||
|
bool has_key(const K& key) {
|
||||||
|
std::map<K,T >::iterator i = self->find(key);
|
||||||
|
return i != self->end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,47 +16,44 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
// exported class
|
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
|
||||||
template<class K, class T> class map {
|
template<class K, class T> class map {
|
||||||
// add typemaps here
|
public:
|
||||||
public:
|
typedef size_t size_type;
|
||||||
typedef size_t size_type;
|
typedef ptrdiff_t difference_type;
|
||||||
typedef ptrdiff_t difference_type;
|
typedef K key_type;
|
||||||
typedef K key_type;
|
typedef T mapped_type;
|
||||||
typedef T mapped_type;
|
map();
|
||||||
map();
|
map(const map<K,T> &);
|
||||||
map(const map<K,T> &);
|
|
||||||
|
|
||||||
unsigned int size() const;
|
unsigned int size() const;
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
void clear();
|
void clear();
|
||||||
%extend {
|
%extend {
|
||||||
const T& get(const K& key) throw (std::out_of_range) {
|
const T& get(const K& key) throw (std::out_of_range) {
|
||||||
std::map<K,T >::iterator i = self->find(key);
|
std::map<K,T >::iterator i = self->find(key);
|
||||||
if (i != self->end())
|
if (i != self->end())
|
||||||
return i->second;
|
return i->second;
|
||||||
else
|
else
|
||||||
throw std::out_of_range("key not found");
|
throw std::out_of_range("key not found");
|
||||||
}
|
|
||||||
void set(const K& key, const T& x) {
|
|
||||||
(*self)[key] = x;
|
|
||||||
}
|
|
||||||
void del(const K& key) throw (std::out_of_range) {
|
|
||||||
std::map<K,T >::iterator i = self->find(key);
|
|
||||||
if (i != self->end())
|
|
||||||
self->erase(i);
|
|
||||||
else
|
|
||||||
throw std::out_of_range("key not found");
|
|
||||||
}
|
|
||||||
bool has_key(const K& key) {
|
|
||||||
std::map<K,T >::iterator i = self->find(key);
|
|
||||||
return i != self->end();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
void set(const K& key, const T& x) {
|
||||||
|
(*self)[key] = x;
|
||||||
|
}
|
||||||
|
void del(const K& key) throw (std::out_of_range) {
|
||||||
|
std::map<K,T >::iterator i = self->find(key);
|
||||||
|
if (i != self->end())
|
||||||
|
self->erase(i);
|
||||||
|
else
|
||||||
|
throw std::out_of_range("key not found");
|
||||||
|
}
|
||||||
|
bool has_key(const K& key) {
|
||||||
|
std::map<K,T >::iterator i = self->find(key);
|
||||||
|
return i != self->end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Legacy macros (deprecated)
|
// Legacy macros (deprecated)
|
||||||
%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
|
%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,11 @@
|
||||||
// them, in order to achieve this.
|
// them, in order to achieve this.
|
||||||
namespace {
|
namespace {
|
||||||
int size_as_int(std::size_t sz) {
|
int size_as_int(std::size_t sz) {
|
||||||
if (sz > static_cast<std::size_t>(INT_MAX)) {
|
if (sz > static_cast<std::size_t>(INT_MAX)) {
|
||||||
throw std::out_of_range("vector size is too big to be representable as int");
|
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
|
} // anonymous namespace
|
||||||
|
|
||||||
|
|
@ -82,74 +82,74 @@ int size_as_int(std::size_t sz) {
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef size_t size_type;
|
typedef size_t size_type;
|
||||||
typedef CTYPE value_type;
|
typedef CTYPE value_type;
|
||||||
typedef CREF_TYPE const_reference;
|
typedef CREF_TYPE const_reference;
|
||||||
vector();
|
vector();
|
||||||
vector(size_type n);
|
vector(size_type n);
|
||||||
size_type capacity() const;
|
size_type capacity() const;
|
||||||
void reserve(size_type n);
|
void reserve(size_type n);
|
||||||
%rename(isEmpty) empty;
|
%rename(isEmpty) empty;
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
void clear();
|
void clear();
|
||||||
%extend {
|
%extend {
|
||||||
int doSize() const {
|
int doSize() const {
|
||||||
return size_as_int(self->size());
|
return size_as_int(self->size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void doAdd(const value_type& value) {
|
void doAdd(const value_type& value) {
|
||||||
self->push_back(value);
|
self->push_back(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void doAdd(int index, const value_type& value) throw (std::out_of_range) {
|
void doAdd(int index, const value_type& value) throw (std::out_of_range) {
|
||||||
const int size = size_as_int(self->size());
|
const int size = size_as_int(self->size());
|
||||||
if (0 <= index && index <= size) {
|
if (0 <= index && index <= size) {
|
||||||
self->insert(self->begin() + index, value);
|
self->insert(self->begin() + index, value);
|
||||||
} else {
|
} else {
|
||||||
throw std::out_of_range("vector index out of range");
|
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
%enddef
|
||||||
|
|
||||||
%javamethodmodifiers std::vector::doSize "private";
|
%javamethodmodifiers std::vector::doSize "private";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue