use exception specification instead of %exception to handle STL error checking

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7352 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2005-07-27 20:09:42 +00:00
commit 03a67698a9
34 changed files with 299 additions and 849 deletions

View file

@ -5,6 +5,8 @@
//
// Ruby implementation
%include <std/std_except.i>
%apply size_t { std::size_t };
%{

View file

@ -5,24 +5,7 @@
//
// Ruby implementation
%include std_common.i
%include exception.i
%exception std::map::__getitem__ {
try {
$action
} catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%exception std::map::__delitem__ {
try {
$action
} catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%include <std_common.i>
// ------------------------------------------------------------------------
// std::map
@ -192,7 +175,7 @@ namespace std {
bool empty() const;
void clear();
%extend {
T& __getitem__(const K& key) {
T& __getitem__(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
@ -202,7 +185,7 @@ namespace std {
void __setitem__(const K& key, const T& x) {
(*self)[key] = x;
}
T __delitem__(const K& key) {
T __delitem__(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) {
T x = i->second;
@ -396,7 +379,7 @@ namespace std {
bool empty() const;
void clear();
%extend {
T& __getitem__(K key) {
T& __getitem__(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
@ -406,7 +389,7 @@ namespace std {
void __setitem__(K key, const T& x) {
(*self)[key] = x;
}
T __delitem__(K key) {
T __delitem__(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) {
T x = i->second;
@ -594,7 +577,7 @@ namespace std {
bool empty() const;
void clear();
%extend {
T __getitem__(const K& key) {
T __getitem__(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
@ -604,7 +587,7 @@ namespace std {
void __setitem__(const K& key, T x) {
(*self)[key] = x;
}
T __delitem__(const K& key) {
T __delitem__(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) {
T x = i->second;
@ -779,7 +762,7 @@ namespace std {
bool empty() const;
void clear();
%extend {
T __getitem__(K key) {
T __getitem__(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
@ -789,7 +772,7 @@ namespace std {
void __setitem__(K key, T x) {
(*self)[key] = x;
}
T __delitem__(K key) {
T __delitem__(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) {
T x = i->second;

View file

@ -5,33 +5,7 @@
//
// Ruby implementation
%include std_common.i
%include exception.i
%exception std::vector::__getitem__ {
try {
$action
} catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%exception std::vector::__setitem__ {
try {
$action
} catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%exception std::vector::pop {
try {
$action
} catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%include <std_common.i>
// ------------------------------------------------------------------------
// std::vector
@ -179,14 +153,14 @@ namespace std {
%rename(push) push_back;
void push_back(const T& x);
%extend {
T pop() {
T pop() throw (std::out_of_range) {
if (self->size() == 0)
throw std::out_of_range("pop from empty vector");
T x = self->back();
self->pop_back();
return x;
}
T& __getitem__(int i) {
T& __getitem__(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i<0) i += size;
if (i>=0 && i<size)
@ -194,7 +168,7 @@ namespace std {
else
throw std::out_of_range("vector index out of range");
}
void __setitem__(int i, const T& x) {
void __setitem__(int i, const T& x) throw (std::out_of_range) {
int size = int(self->size());
if (i<0) i+= size;
if (i>=0 && i<size)
@ -325,14 +299,14 @@ namespace std {
%rename(push) push_back;
void push_back(T* x);
%extend {
T* pop() {
T* pop() throw (std::out_of_range) {
if (self->size() == 0)
throw std::out_of_range("pop from empty vector");
T* x = self->back();
self->pop_back();
return x;
}
T* __getitem__(int i) {
T* __getitem__(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i<0) i += size;
if (i>=0 && i<size)
@ -340,7 +314,7 @@ namespace std {
else
throw std::out_of_range("vector index out of range");
}
void __setitem__(int i, T* x) {
void __setitem__(int i, T* x) throw (std::out_of_range) {
int size = int(self->size());
if (i<0) i+= size;
if (i>=0 && i<size)
@ -471,14 +445,14 @@ namespace std {
%rename(push) push_back;
void push_back(T x);
%extend {
T pop() {
T pop() throw (std::out_of_range) {
if (self->size() == 0)
throw std::out_of_range("pop from empty vector");
T x = self->back();
self->pop_back();
return x;
}
T __getitem__(int i) {
T __getitem__(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i<0) i += size;
if (i>=0 && i<size)
@ -486,7 +460,7 @@ namespace std {
else
throw std::out_of_range("vector index out of range");
}
void __setitem__(int i, T x) {
void __setitem__(int i, T x) throw (std::out_of_range) {
int size = int(self->size());
if (i<0) i+= size;
if (i>=0 && i<size)