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:
parent
ebde3e6253
commit
03a67698a9
34 changed files with 299 additions and 849 deletions
|
|
@ -6,6 +6,8 @@
|
|||
//
|
||||
// Ocaml implementation
|
||||
|
||||
%include <std/std_except.i>
|
||||
|
||||
%apply size_t { std::size_t };
|
||||
|
||||
%{
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
//
|
||||
// Python implementation
|
||||
|
||||
%include <std_common.i>
|
||||
|
||||
%module std_list
|
||||
%{
|
||||
|
|
@ -13,32 +14,6 @@
|
|||
#include <stdexcept>
|
||||
%}
|
||||
|
||||
%include "exception.i"
|
||||
|
||||
%exception std::list::__getitem__ {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
%exception std::list::__setitem__ {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
%exception std::list::__delitem__ {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace std{
|
||||
template<class T> class list
|
||||
|
|
@ -86,7 +61,7 @@ namespace std{
|
|||
|
||||
%extend
|
||||
{
|
||||
const_reference __getitem__(int i)
|
||||
const_reference __getitem__(int i) throw (std::out_of_range)
|
||||
{
|
||||
std::list<T>::iterator first = self->begin();
|
||||
int size = int(self->size());
|
||||
|
|
@ -101,7 +76,7 @@ namespace std{
|
|||
}
|
||||
else throw std::out_of_range("list index out of range");
|
||||
}
|
||||
void __setitem__(int i, const T& x)
|
||||
void __setitem__(int i, const T& x) throw (std::out_of_range)
|
||||
{
|
||||
std::list<T>::iterator first = self->begin();
|
||||
int size = int(self->size());
|
||||
|
|
@ -116,7 +91,7 @@ namespace std{
|
|||
}
|
||||
else throw std::out_of_range("list index out of range");
|
||||
}
|
||||
void __delitem__(int i)
|
||||
void __delitem__(int i) throw (std::out_of_range)
|
||||
{
|
||||
std::list<T>::iterator first = self->begin();
|
||||
int size = int(self->size());
|
||||
|
|
|
|||
|
|
@ -5,24 +5,7 @@
|
|||
//
|
||||
// Common implementation
|
||||
|
||||
%include std_common.i
|
||||
%include exception.i
|
||||
|
||||
%exception std::map::get {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
%exception std::map::del {
|
||||
try {
|
||||
$action
|
||||
} catch (std::out_of_range& e) {
|
||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||
}
|
||||
}
|
||||
%include <std_common.i>
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::map
|
||||
|
|
@ -47,7 +30,7 @@ namespace std {
|
|||
bool empty() const;
|
||||
void clear();
|
||||
%extend {
|
||||
T& get(const K& key) {
|
||||
T& get(const K& key) throw (std::out_of_range) {
|
||||
std::map<K,T >::iterator i = self->find(key);
|
||||
if (i != self->end())
|
||||
return i->second;
|
||||
|
|
@ -57,7 +40,7 @@ namespace std {
|
|||
void set(const K& key, const T& x) {
|
||||
(*self)[key] = x;
|
||||
}
|
||||
void del(const K& key) {
|
||||
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);
|
||||
|
|
@ -86,7 +69,7 @@ namespace std {
|
|||
bool empty() const;
|
||||
void clear();
|
||||
%extend {
|
||||
T& get(K key) {
|
||||
T& get(K key) throw (std::out_of_range) {
|
||||
std::map<K,T >::iterator i = self->find(key);
|
||||
if (i != self->end())
|
||||
return i->second;
|
||||
|
|
@ -96,7 +79,7 @@ namespace std {
|
|||
void set(K key, const T& x) {
|
||||
(*self)[key] = x;
|
||||
}
|
||||
void del(K key) {
|
||||
void del(K key) throw (std::out_of_range) {
|
||||
std::map<K,T >::iterator i = self->find(key);
|
||||
if (i != self->end())
|
||||
self->erase(i);
|
||||
|
|
@ -122,7 +105,7 @@ namespace std {
|
|||
bool empty() const;
|
||||
void clear();
|
||||
%extend {
|
||||
T get(const K& key) {
|
||||
T get(const K& key) throw (std::out_of_range) {
|
||||
std::map<K,T >::iterator i = self->find(key);
|
||||
if (i != self->end())
|
||||
return i->second;
|
||||
|
|
@ -132,7 +115,7 @@ namespace std {
|
|||
void set(const K& key, T x) {
|
||||
(*self)[key] = x;
|
||||
}
|
||||
void del(const K& key) {
|
||||
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);
|
||||
|
|
@ -159,7 +142,7 @@ namespace std {
|
|||
bool empty() const;
|
||||
void clear();
|
||||
%extend {
|
||||
T get(K key) {
|
||||
T get(K key) throw (std::out_of_range) {
|
||||
std::map<K,T >::iterator i = self->find(key);
|
||||
if (i != self->end())
|
||||
return i->second;
|
||||
|
|
@ -169,7 +152,7 @@ namespace std {
|
|||
void set(K key, T x) {
|
||||
(*self)[key] = x;
|
||||
}
|
||||
void del(K key) {
|
||||
void del(K key) throw (std::out_of_range) {
|
||||
std::map<K,T >::iterator i = self->find(key);
|
||||
if (i != self->end())
|
||||
self->erase(i);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue