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

@ -3,36 +3,13 @@
* this file to generate wrappers. * this file to generate wrappers.
*/ */
%include <std_common.i>
%{ %{
#include <deque> #include <deque>
#include <stdexcept> #include <stdexcept>
%} %}
%include "exception.i"
%exception std::deque::getitem {
try {
$action
} catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%exception std::deque::setitem {
try {
$action
} catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%exception std::deque::delitem {
try {
$action
} catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
/* This macro defines all of the standard methods for a deque. This /* This macro defines all of the standard methods for a deque. This
is defined as a macro to simplify the task of specialization. For is defined as a macro to simplify the task of specialization. For
@ -69,7 +46,7 @@
/* Some useful extensions */ /* Some useful extensions */
%extend { %extend {
const_reference getitem(int i) { const_reference getitem(int i) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i<0) i += size; if (i<0) i += size;
if (i>=0 && i<size) if (i>=0 && i<size)
@ -77,7 +54,7 @@
else else
throw std::out_of_range("deque index out of range"); throw std::out_of_range("deque 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()); int size = int(self->size());
if (i<0) i+= size; if (i<0) i+= size;
if (i>=0 && i<size) if (i>=0 && i<size)
@ -85,7 +62,7 @@
else else
throw std::out_of_range("deque index out of range"); throw std::out_of_range("deque index out of range");
} }
void delitem(int i) { void delitem(int i) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i<0) i+= size; if (i<0) i+= size;
if (i>=0 && i<size) { if (i>=0 && i<size) {

View file

@ -1,3 +1,4 @@
%include <std/std_except.i>
%apply size_t { std::size_t }; %apply size_t { std::size_t };

View file

@ -5,26 +5,7 @@
// //
// Common implementation // Common implementation
%include std_common.i %include <std_common.i>
%include exception.i
%exception std::map::get {
try {
$action
} catch (std::out_of_range& e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpIndexOutOfRangeException, const_cast<char*>(e.what()));
return $null;
}
}
%exception std::map::del {
try {
$action
} catch (std::out_of_range& e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpIndexOutOfRangeException, const_cast<char*>(e.what()));
return $null;
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// std::map // std::map
@ -50,7 +31,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -60,7 +41,7 @@ namespace std {
void set(const K& key, const T& x) { void set(const K& key, const T& x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -89,7 +70,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T& get(K key) { T& get(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;
@ -99,7 +80,7 @@ namespace std {
void set(K key, const T& x) { void set(K key, const T& x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -125,7 +106,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -135,7 +116,7 @@ namespace std {
void set(const K& key, T x) { void set(const K& key, T x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -162,7 +143,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T get(K key) { T get(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;
@ -172,7 +153,7 @@ namespace std {
void set(K key, T x) { void set(K key, T x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);

View file

@ -8,6 +8,8 @@
* Warning: heavy macro usage in this file. Use swig -E to get a sane view on the real file contents! * Warning: heavy macro usage in this file. Use swig -E to get a sane view on the real file contents!
*/ */
%include <std_common.i>
// MACRO for use within the std::vector class body // MACRO for use within the std::vector class body
// CSTYPE and CTYPE respectively correspond to the types in the cstype and ctype typemaps // CSTYPE and CTYPE respectively correspond to the types in the cstype and ctype typemaps
%define SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE...) %define SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE...)
@ -172,7 +174,7 @@
%newobject Repeat(const CTYPE& value, int count); %newobject Repeat(const CTYPE& value, int count);
vector(); vector();
%extend { %extend {
vector(int capacity) { vector(int capacity) throw (std::out_of_range) {
std::vector<CTYPE >* pv = 0; std::vector<CTYPE >* pv = 0;
if (capacity >= 0) { if (capacity >= 0) {
pv = new std::vector<CTYPE >(); pv = new std::vector<CTYPE >();
@ -182,19 +184,19 @@
} }
return pv; return pv;
} }
CTYPE getitemcopy(int index) { CTYPE getitemcopy(int index) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size()) if (index>=0 && index<(int)self->size())
return (*self)[index]; return (*self)[index];
else else
throw std::out_of_range("index"); throw std::out_of_range("index");
} }
const CTYPE& getitem(int index) { const CTYPE& getitem(int index) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size()) if (index>=0 && index<(int)self->size())
return (*self)[index]; return (*self)[index];
else else
throw std::out_of_range("index"); throw std::out_of_range("index");
} }
void setitem(int index, const CTYPE& value) { void setitem(int index, const CTYPE& value) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size()) if (index>=0 && index<(int)self->size())
(*self)[index] = value; (*self)[index] = value;
else else
@ -205,44 +207,44 @@
self->insert(self->end(), values.begin(), values.end()); self->insert(self->end(), values.begin(), values.end());
} }
// Takes a deep copy of the elements unlike ArrayList.GetRange // Takes a deep copy of the elements unlike ArrayList.GetRange
std::vector<CTYPE > *GetRange(int index, int count) { std::vector<CTYPE > *GetRange(int index, int count) throw (std::out_of_range, std::invalid_argument) {
if (index < 0) if (index < 0)
throw std::out_of_range("index"); throw std::out_of_range("index");
if (count < 0) if (count < 0)
throw std::out_of_range("count"); throw std::out_of_range("count");
if (index >= (int)self->size()+1 || index+count > (int)self->size()) if (index >= (int)self->size()+1 || index+count > (int)self->size())
throw "invalid range"; throw std::invalid_argument("invalid range");
return new std::vector<CTYPE >(self->begin()+index, self->begin()+index+count); return new std::vector<CTYPE >(self->begin()+index, self->begin()+index+count);
} }
void Insert(int index, const CTYPE& value) { void Insert(int index, const CTYPE& value) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size()+1) if (index>=0 && index<(int)self->size()+1)
self->insert(self->begin()+index, value); self->insert(self->begin()+index, value);
else else
throw std::out_of_range("index"); throw std::out_of_range("index");
} }
// Takes a deep copy of the elements unlike ArrayList.InsertRange // Takes a deep copy of the elements unlike ArrayList.InsertRange
void InsertRange(int index, const std::vector<CTYPE >& values) { void InsertRange(int index, const std::vector<CTYPE >& values) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size()+1) if (index>=0 && index<(int)self->size()+1)
self->insert(self->begin()+index, values.begin(), values.end()); self->insert(self->begin()+index, values.begin(), values.end());
else else
throw std::out_of_range("index"); throw std::out_of_range("index");
} }
void RemoveAt(int index) { void RemoveAt(int index) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size()) if (index>=0 && index<(int)self->size())
self->erase(self->begin() + index); self->erase(self->begin() + index);
else else
throw std::out_of_range("index"); throw std::out_of_range("index");
} }
void RemoveRange(int index, int count) { void RemoveRange(int index, int count) throw (std::out_of_range, std::invalid_argument) {
if (index < 0) if (index < 0)
throw std::out_of_range("index"); throw std::out_of_range("index");
if (count < 0) if (count < 0)
throw std::out_of_range("count"); throw std::out_of_range("count");
if (index >= (int)self->size()+1 || index+count > (int)self->size()) if (index >= (int)self->size()+1 || index+count > (int)self->size())
throw "invalid range"; throw std::invalid_argument("invalid range");
self->erase(self->begin()+index, self->begin()+index+count); self->erase(self->begin()+index, self->begin()+index+count);
} }
static std::vector<CTYPE > *Repeat(const CTYPE& value, int count) { static std::vector<CTYPE > *Repeat(const CTYPE& value, int count) throw (std::out_of_range) {
if (count < 0) if (count < 0)
throw std::out_of_range("count"); throw std::out_of_range("count");
return new std::vector<CTYPE >(count, value); return new std::vector<CTYPE >(count, value);
@ -250,17 +252,17 @@
void Reverse() { void Reverse() {
std::reverse(self->begin(), self->end()); std::reverse(self->begin(), self->end());
} }
void Reverse(int index, int count) { void Reverse(int index, int count) throw (std::out_of_range, std::invalid_argument) {
if (index < 0) if (index < 0)
throw std::out_of_range("index"); throw std::out_of_range("index");
if (count < 0) if (count < 0)
throw std::out_of_range("count"); throw std::out_of_range("count");
if (index >= (int)self->size()+1 || index+count > (int)self->size()) if (index >= (int)self->size()+1 || index+count > (int)self->size())
throw "invalid range"; throw std::invalid_argument("invalid range");
std::reverse(self->begin()+index, self->begin()+index+count); std::reverse(self->begin()+index, self->begin()+index+count);
} }
// Takes a deep copy of the elements unlike ArrayList.SetRange // Takes a deep copy of the elements unlike ArrayList.SetRange
void SetRange(int index, const std::vector<CTYPE >& values) { void SetRange(int index, const std::vector<CTYPE >& values) throw (std::out_of_range) {
if (index < 0) if (index < 0)
throw std::out_of_range("index"); throw std::out_of_range("index");
if (index+values.size() > self->size()) if (index+values.size() > self->size())
@ -319,125 +321,6 @@ namespace std {
%enddef %enddef
// Methods which can throw an Exception
%exception std::vector::vector(int capacity) {
try {
$action
} catch (std::out_of_range& e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
return $null;
}
}
%exception std::vector::getitemcopy {
try {
$action
} catch (std::out_of_range& e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
return $null;
}
}
%exception std::vector::getitem {
try {
$action
} catch (std::out_of_range& e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
return $null;
}
}
%exception std::vector::setitem {
try {
$action
} catch (std::out_of_range& e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
return $null;
}
}
%exception std::vector::GetRange {
try {
$action
} catch (std::out_of_range& e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
return $null;
} catch (const char *e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentException, e, "");
return $null;
}
}
%exception std::vector::Insert {
try {
$action
} catch (std::out_of_range& e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
return $null;
}
}
%exception std::vector::InsertRange {
try {
$action
} catch (std::out_of_range& e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
return $null;
}
}
%exception std::vector::RemoveAt {
try {
$action
} catch (std::out_of_range& e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
return $null;
}
}
%exception std::vector::Repeat {
try {
$action
} catch (std::out_of_range& e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
return $null;
}
}
%exception std::vector::RemoveRange {
try {
$action
} catch (std::out_of_range& e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
return $null;
} catch (const char *e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentException, e, "");
return $null;
}
}
%exception std::vector::Reverse(int index, int count) {
try {
$action
} catch (std::out_of_range& e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
return $null;
} catch (const char *e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentException, e, "");
return $null;
}
}
%exception std::vector::SetRange {
try {
$action
} catch (std::out_of_range& e) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, e.what());
return $null;
}
}
%{ %{
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>

View file

@ -5,6 +5,8 @@
// //
// Guile implementation // Guile implementation
%include <std/std_except.i>
%apply size_t { std::size_t }; %apply size_t { std::size_t };
#define SWIG_bool2scm(b) gh_bool2scm(b ? 1 : 0) #define SWIG_bool2scm(b) gh_bool2scm(b ? 1 : 0)

View file

@ -5,24 +5,7 @@
// //
// Guile implementation // Guile implementation
%include std_common.i %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()));
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// std::map // std::map
@ -242,7 +225,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -252,7 +235,7 @@ namespace std {
void __setitem__(const K& key, const T& x) { void __setitem__(const K& key, const T& x) {
(*self)[key] = x; (*self)[key] = x;
} }
void __delitem__(const K& key) { void __delitem__(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())
self->erase(i); self->erase(i);
@ -462,7 +445,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T& __getitem__(K key) { T& __getitem__(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;
@ -472,7 +455,7 @@ namespace std {
void __setitem__(K key, const T& x) { void __setitem__(K key, const T& x) {
(*self)[key] = x; (*self)[key] = x;
} }
void __delitem__(K key) { void __delitem__(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())
self->erase(i); self->erase(i);
@ -674,7 +657,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -684,7 +667,7 @@ namespace std {
void __setitem__(const K& key, T x) { void __setitem__(const K& key, T x) {
(*self)[key] = x; (*self)[key] = x;
} }
void __delitem__(const K& key) { void __delitem__(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())
self->erase(i); self->erase(i);
@ -886,7 +869,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T __getitem__(K key) { T __getitem__(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;
@ -896,7 +879,7 @@ namespace std {
void __setitem__(K key, T x) { void __setitem__(K key, T x) {
(*self)[key] = x; (*self)[key] = x;
} }
void __delitem__(K key) { void __delitem__(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())
self->erase(i); self->erase(i);

View file

@ -5,33 +5,7 @@
// //
// Guile implementation // Guile implementation
%include std_common.i %include <std_common.i>
%include exception.i
%exception std::vector::ref {
try {
$action
} catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%exception std::vector::set {
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()));
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// std::vector // std::vector
@ -228,21 +202,21 @@ namespace std {
%rename("push!") push_back; %rename("push!") push_back;
void push_back(const T& x); void push_back(const T& x);
%extend { %extend {
T pop() { T pop() throw (std::out_of_range) {
if (self->size() == 0) if (self->size() == 0)
throw std::out_of_range("pop from empty vector"); throw std::out_of_range("pop from empty vector");
T x = self->back(); T x = self->back();
self->pop_back(); self->pop_back();
return x; return x;
} }
T& ref(int i) { T& ref(int i) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
return (*self)[i]; return (*self)[i];
else else
throw std::out_of_range("vector index out of range"); throw std::out_of_range("vector index out of range");
} }
void set(int i, const T& x) { void set(int i, const T& x) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
(*self)[i] = x; (*self)[i] = x;
@ -396,21 +370,21 @@ namespace std {
%rename("push!") push_back; %rename("push!") push_back;
void push_back(T x); void push_back(T x);
%extend { %extend {
T pop() { T pop() throw (std::out_of_range) {
if (self->size() == 0) if (self->size() == 0)
throw std::out_of_range("pop from empty vector"); throw std::out_of_range("pop from empty vector");
T x = self->back(); T x = self->back();
self->pop_back(); self->pop_back();
return x; return x;
} }
T ref(int i) { T ref(int i) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
return (*self)[i]; return (*self)[i];
else else
throw std::out_of_range("vector index out of range"); throw std::out_of_range("vector index out of range");
} }
void set(int i, T x) { void set(int i, T x) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
(*self)[i] = x; (*self)[i] = x;

View file

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

View file

@ -5,26 +5,7 @@
// //
// Common implementation // Common implementation
%include std_common.i %include <std_common.i>
%include exception.i
%exception std::map::get {
try {
$action
} catch (std::out_of_range& e) {
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, const_cast<char*>(e.what()));
return $null;
}
}
%exception std::map::del {
try {
$action
} catch (std::out_of_range& e) {
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, const_cast<char*>(e.what()));
return $null;
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// std::map // std::map
@ -50,7 +31,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -60,7 +41,7 @@ namespace std {
void set(const K& key, const T& x) { void set(const K& key, const T& x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -89,7 +70,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T& get(K key) { T& get(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;
@ -99,7 +80,7 @@ namespace std {
void set(K key, const T& x) { void set(K key, const T& x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -125,7 +106,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -135,7 +116,7 @@ namespace std {
void set(const K& key, T x) { void set(const K& key, T x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -162,7 +143,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T get(K key) { T get(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;
@ -172,7 +153,7 @@ namespace std {
void set(K key, T x) { void set(K key, T x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);

View file

@ -5,27 +5,7 @@
// //
// Java implementation // Java implementation
%include <std_common.i>
%include exception.i
%exception std::vector::get {
try {
$action
} catch (std::out_of_range& e) {
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, const_cast<char*>(e.what()));
return $null;
}
}
%exception std::vector::set {
try {
$action
} catch (std::out_of_range& e) {
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, const_cast<char*>(e.what()));
return $null;
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// std::vector // std::vector
@ -73,14 +53,14 @@ namespace std {
%rename(add) push_back; %rename(add) push_back;
void push_back(const T& x); void push_back(const T& x);
%extend { %extend {
T& get(int i) { T& get(int i) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
return (*self)[i]; return (*self)[i];
else else
throw std::out_of_range("vector index out of range"); throw std::out_of_range("vector index out of range");
} }
void set(int i, const T& x) { void set(int i, const T& x) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
(*self)[i] = x; (*self)[i] = x;
@ -106,14 +86,14 @@ namespace std {
%rename(add) push_back; %rename(add) push_back;
void push_back(T x); void push_back(T x);
%extend { %extend {
T get(int i) { T get(int i) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
return (*self)[i]; return (*self)[i];
else else
throw std::out_of_range("vector index out of range"); throw std::out_of_range("vector index out of range");
} }
void set(int i, T x) { void set(int i, T x) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
(*self)[i] = x; (*self)[i] = x;

View file

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

View file

@ -5,24 +5,7 @@
// //
// MzScheme implementation // MzScheme implementation
%include std_common.i %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()));
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// std::map // std::map
@ -242,7 +225,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -252,7 +235,7 @@ namespace std {
void __setitem__(const K& key, const T& x) { void __setitem__(const K& key, const T& x) {
(*self)[key] = x; (*self)[key] = x;
} }
void __delitem__(const K& key) { void __delitem__(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())
self->erase(i); self->erase(i);
@ -462,7 +445,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T& __getitem__(K key) { T& __getitem__(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;
@ -472,7 +455,7 @@ namespace std {
void __setitem__(K key, const T& x) { void __setitem__(K key, const T& x) {
(*self)[key] = x; (*self)[key] = x;
} }
void __delitem__(K key) { void __delitem__(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())
self->erase(i); self->erase(i);
@ -674,7 +657,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -684,7 +667,7 @@ namespace std {
void __setitem__(const K& key, T x) { void __setitem__(const K& key, T x) {
(*self)[key] = x; (*self)[key] = x;
} }
void __delitem__(const K& key) { void __delitem__(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())
self->erase(i); self->erase(i);
@ -886,7 +869,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T __getitem__(K key) { T __getitem__(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;
@ -896,7 +879,7 @@ namespace std {
void __setitem__(K key, T x) { void __setitem__(K key, T x) {
(*self)[key] = x; (*self)[key] = x;
} }
void __delitem__(K key) { void __delitem__(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())
self->erase(i); self->erase(i);

View file

@ -5,36 +5,7 @@
// //
// MzScheme implementation // MzScheme implementation
%include std_common.i %include <std_common.i>
%include exception.i
// containers
%exception std::vector::ref {
try {
$action
} catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%exception std::vector::set {
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()));
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// std::vector // std::vector
@ -233,21 +204,21 @@ namespace std {
%rename("push!") push_back; %rename("push!") push_back;
void push_back(const T& x); void push_back(const T& x);
%extend { %extend {
T pop() { T pop() throw (std::out_of_range) {
if (self->size() == 0) if (self->size() == 0)
throw std::out_of_range("pop from empty vector"); throw std::out_of_range("pop from empty vector");
T x = self->back(); T x = self->back();
self->pop_back(); self->pop_back();
return x; return x;
} }
T& ref(int i) { T& ref(int i) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
return (*self)[i]; return (*self)[i];
else else
throw std::out_of_range("vector index out of range"); throw std::out_of_range("vector index out of range");
} }
void set(int i, const T& x) { void set(int i, const T& x) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
(*self)[i] = x; (*self)[i] = x;
@ -409,21 +380,21 @@ namespace std {
%rename("push!") push_back; %rename("push!") push_back;
void push_back(T x); void push_back(T x);
%extend { %extend {
T pop() { T pop() throw (std::out_of_range) {
if (self->size() == 0) if (self->size() == 0)
throw std::out_of_range("pop from empty vector"); throw std::out_of_range("pop from empty vector");
T x = self->back(); T x = self->back();
self->pop_back(); self->pop_back();
return x; return x;
} }
T ref(int i) { T ref(int i) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
return (*self)[i]; return (*self)[i];
else else
throw std::out_of_range("vector index out of range"); throw std::out_of_range("vector index out of range");
} }
void set(int i, T x) { void set(int i, T x) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
(*self)[i] = x; (*self)[i] = x;

View file

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

View file

@ -6,6 +6,7 @@
// //
// Python implementation // Python implementation
%include <std_common.i>
%module std_list %module std_list
%{ %{
@ -13,32 +14,6 @@
#include <stdexcept> #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{ namespace std{
template<class T> class list template<class T> class list
@ -86,7 +61,7 @@ namespace std{
%extend %extend
{ {
const_reference __getitem__(int i) const_reference __getitem__(int i) throw (std::out_of_range)
{ {
std::list<T>::iterator first = self->begin(); std::list<T>::iterator first = self->begin();
int size = int(self->size()); int size = int(self->size());
@ -101,7 +76,7 @@ namespace std{
} }
else throw std::out_of_range("list index out of range"); 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(); std::list<T>::iterator first = self->begin();
int size = int(self->size()); int size = int(self->size());
@ -116,7 +91,7 @@ namespace std{
} }
else throw std::out_of_range("list index out of range"); 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(); std::list<T>::iterator first = self->begin();
int size = int(self->size()); int size = int(self->size());

View file

@ -5,24 +5,7 @@
// //
// Common implementation // Common implementation
%include std_common.i %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()));
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// std::map // std::map
@ -47,7 +30,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -57,7 +40,7 @@ namespace std {
void set(const K& key, const T& x) { void set(const K& key, const T& x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -86,7 +69,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T& get(K key) { T& get(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;
@ -96,7 +79,7 @@ namespace std {
void set(K key, const T& x) { void set(K key, const T& x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -122,7 +105,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -132,7 +115,7 @@ namespace std {
void set(const K& key, T x) { void set(const K& key, T x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -159,7 +142,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T get(K key) { T get(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;
@ -169,7 +152,7 @@ namespace std {
void set(K key, T x) { void set(K key, T x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);

View file

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

View file

@ -5,24 +5,7 @@
// //
// Common implementation // Common implementation
%include std_common.i %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()));
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// std::map // std::map
@ -48,7 +31,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -58,7 +41,7 @@ namespace std {
void set(const K& key, const T& x) { void set(const K& key, const T& x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -87,7 +70,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T& get(K key) { T& get(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;
@ -97,7 +80,7 @@ namespace std {
void set(K key, const T& x) { void set(K key, const T& x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -123,7 +106,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -133,7 +116,7 @@ namespace std {
void set(const K& key, T x) { void set(const K& key, T x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -160,7 +143,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T get(K key) { T get(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;
@ -170,7 +153,7 @@ namespace std {
void set(K key, T x) { void set(K key, T x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);

View file

@ -9,36 +9,7 @@
// //
// Perl implementation // Perl implementation
%include std_common.i %include <std_common.i>
%include exception.i
// containers
// methods which can raise are caused to throw an IndexError
%exception std::vector::get {
try {
$action
} catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%exception std::vector::set {
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()));
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// std::vector // std::vector
@ -226,21 +197,21 @@ namespace std {
%rename(push) push_back; %rename(push) push_back;
void push_back(const T& x); void push_back(const T& x);
%extend { %extend {
T pop() { T pop() throw (std::out_of_range) {
if (self->size() == 0) if (self->size() == 0)
throw std::out_of_range("pop from empty vector"); throw std::out_of_range("pop from empty vector");
T x = self->back(); T x = self->back();
self->pop_back(); self->pop_back();
return x; return x;
} }
T& get(int i) { T& get(int i) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
return (*self)[i]; return (*self)[i];
else else
throw std::out_of_range("vector index out of range"); throw std::out_of_range("vector index out of range");
} }
void set(int i, const T& x) { void set(int i, const T& x) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
(*self)[i] = x; (*self)[i] = x;
@ -397,21 +368,21 @@ namespace std {
%rename(push) push_back; %rename(push) push_back;
void push_back(T x); void push_back(T x);
%extend { %extend {
T pop() { T pop() throw (std::out_of_range) {
if (self->size() == 0) if (self->size() == 0)
throw std::out_of_range("pop from empty vector"); throw std::out_of_range("pop from empty vector");
T x = self->back(); T x = self->back();
self->pop_back(); self->pop_back();
return x; return x;
} }
T get(int i) { T get(int i) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
return (*self)[i]; return (*self)[i];
else else
throw std::out_of_range("vector index out of range"); throw std::out_of_range("vector index out of range");
} }
void set(int i, T x) { void set(int i, T x) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
(*self)[i] = x; (*self)[i] = x;

View file

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

View file

@ -5,24 +5,7 @@
// //
// Common implementation // Common implementation
%include std_common.i %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()));
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// std::map // std::map
@ -48,7 +31,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -58,7 +41,7 @@ namespace std {
void set(const K& key, const T& x) { void set(const K& key, const T& x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -87,7 +70,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T& get(K key) { T& get(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;
@ -97,7 +80,7 @@ namespace std {
void set(K key, const T& x) { void set(K key, const T& x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -123,7 +106,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -133,7 +116,7 @@ namespace std {
void set(const K& key, T x) { void set(const K& key, T x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -160,7 +143,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T get(K key) { T get(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;
@ -170,7 +153,7 @@ namespace std {
void set(K key, T x) { void set(K key, T x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);

View file

@ -5,35 +5,7 @@
// //
// PHP implementation // PHP implementation
%include exception.i %include <std_common.i>
// containers
// methods which can raise are caused to throw an IndexError
%exception std::vector::get {
try {
$action
} catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%exception std::vector::set {
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()));
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// std::vector // std::vector
@ -79,21 +51,21 @@ namespace std {
%rename(push) push_back; %rename(push) push_back;
void push_back(const T& x); void push_back(const T& x);
%extend { %extend {
T pop() { T pop() throw (std::out_of_range) {
if (self->size() == 0) if (self->size() == 0)
throw std::out_of_range("pop from empty vector"); throw std::out_of_range("pop from empty vector");
T x = self->back(); T x = self->back();
self->pop_back(); self->pop_back();
return x; return x;
} }
T& get(int i) { T& get(int i) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
return (*self)[i]; return (*self)[i];
else else
throw std::out_of_range("vector index out of range"); throw std::out_of_range("vector index out of range");
} }
void set(int i, const T& x) { void set(int i, const T& x) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
(*self)[i] = x; (*self)[i] = x;
@ -117,21 +89,21 @@ namespace std {
%rename(push) push_back; %rename(push) push_back;
void push_back(T x); void push_back(T x);
%extend { %extend {
T pop() { T pop() throw (std::out_of_range) {
if (self->size() == 0) if (self->size() == 0)
throw std::out_of_range("pop from empty vector"); throw std::out_of_range("pop from empty vector");
T x = self->back(); T x = self->back();
self->pop_back(); self->pop_back();
return x; return x;
} }
T get(int i) { T get(int i) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
return (*self)[i]; return (*self)[i];
else else
throw std::out_of_range("vector index out of range"); throw std::out_of_range("vector index out of range");
} }
void set(int i, T x) { void set(int i, T x) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i>=0 && i<size) if (i>=0 && i<size)
(*self)[i] = x; (*self)[i] = x;

View file

@ -357,99 +357,6 @@ namespace swig
%define %swig_container_methods(Container...) %define %swig_container_methods(Container...)
// __getitem__ is required to raise an IndexError for for-loops to work
// other methods which can raise are made to throw an IndexError as well
%exception __getitem__ {
try { $action }
catch (std::out_of_range& e) {
if (!PyErr_Occurred()) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
} else {
SWIG_fail;
}
}
SWIG_CATCH_UNKNOWN
}
%exception __setitem__ {
try { $action }
catch (std::out_of_range& e) {
if (!PyErr_Occurred()) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
} else {
SWIG_fail;
}
}
SWIG_CATCH_UNKNOWN
}
%exception __getslice__ {
try { $action }
catch (std::out_of_range& e) {
if (!PyErr_Occurred()) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
} else {
SWIG_fail;
}
}
SWIG_CATCH_UNKNOWN
}
%exception __setslice__ {
try { $action }
catch (std::out_of_range& e) {
if (!PyErr_Occurred()) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
} else {
SWIG_fail;
}
}
catch (std::invalid_argument& e) {
if (!PyErr_Occurred()) {
SWIG_exception(SWIG_TypeError,const_cast<char*>(e.what()));
} else {
SWIG_fail;
}
}
SWIG_CATCH_UNKNOWN
}
%exception __delslice__ {
try { $action }
catch (std::out_of_range& e) {
if (!PyErr_Occurred()) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
} else {
SWIG_fail;
}
}
SWIG_CATCH_UNKNOWN
}
%exception __delitem__ {
try { $action }
catch (std::out_of_range& e) {
if (!PyErr_Occurred()) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
} else {
SWIG_fail;
}
}
SWIG_CATCH_UNKNOWN
}
%exception pop {
try { $action }
catch (std::out_of_range& e) {
if (!PyErr_Occurred()) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
} else {
SWIG_fail;
}
}
SWIG_CATCH_UNKNOWN
}
%newobject __getslice__; %newobject __getslice__;
@ -469,7 +376,7 @@ namespace swig
%fragment("PySequence_Base"); %fragment("PySequence_Base");
%extend { %extend {
value_type pop() { value_type pop() throw (std::out_of_range) {
if (self->size() == 0) if (self->size() == 0)
throw std::out_of_range("pop from empty container"); throw std::out_of_range("pop from empty container");
Sequence::value_type x = self->back(); Sequence::value_type x = self->back();
@ -477,19 +384,19 @@ namespace swig
return x; return x;
} }
Sequence* __getslice__(difference_type i, difference_type j) { Sequence* __getslice__(difference_type i, difference_type j) throw (std::out_of_range) {
return swig::getslice(self, i, j); return swig::getslice(self, i, j);
} }
void __setslice__(difference_type i, difference_type j, const Sequence& v) { void __setslice__(difference_type i, difference_type j, const Sequence& v) throw (std::out_of_range, std::invalid_argument) {
swig::setslice(self, i, j, v); swig::setslice(self, i, j, v);
} }
void __delslice__(difference_type i, difference_type j) { void __delslice__(difference_type i, difference_type j) throw (std::out_of_range) {
swig::delslice(self, i, j); swig::delslice(self, i, j);
} }
void __delitem__(difference_type i) { void __delitem__(difference_type i) throw (std::out_of_range) {
self->erase(swig::getpos(self,i)); self->erase(swig::getpos(self,i));
} }
} }
@ -498,11 +405,11 @@ namespace swig
%define %swig_sequence_methods(Sequence...) %define %swig_sequence_methods(Sequence...)
%swig_sequence_methods_common(SWIG_arg(Sequence)) %swig_sequence_methods_common(SWIG_arg(Sequence))
%extend { %extend {
const value_type& __getitem__(difference_type i) const { const value_type& __getitem__(difference_type i) const throw (std::out_of_range) {
return *(swig::cgetpos(self, i)); return *(swig::cgetpos(self, i));
} }
void __setitem__(difference_type i, const value_type& x) { void __setitem__(difference_type i, const value_type& x) throw (std::out_of_range) {
*(swig::getpos(self,i)) = x; *(swig::getpos(self,i)) = x;
} }
@ -515,11 +422,11 @@ namespace swig
%define %swig_sequence_methods_val(Sequence...) %define %swig_sequence_methods_val(Sequence...)
%swig_sequence_methods_common(SWIG_arg(Sequence)) %swig_sequence_methods_common(SWIG_arg(Sequence))
%extend { %extend {
value_type __getitem__(difference_type i) { value_type __getitem__(difference_type i) throw (std::out_of_range) {
return *(swig::cgetpos(self, i)); return *(swig::cgetpos(self, i));
} }
void __setitem__(difference_type i, value_type x) { void __setitem__(difference_type i, value_type x) throw (std::out_of_range) {
*(swig::getpos(self,i)) = x; *(swig::getpos(self,i)) = x;
} }

View file

@ -1,3 +1,4 @@
%include <std/std_except.i>
%include <pystdcommon.swg> %include <pystdcommon.swg>
%include <std/std_common.i> %include <std/std_common.i>

View file

@ -1 +1,79 @@
%include <std/std_except.i> %include <std/std_except.i>
%include <std_string.i>
%{
#include <stdexcept>
%}
namespace std {
/* Mark all of them as exception classes */
%feature("exceptionclass") exception;
%feature("exceptionclass") bad_exception;
%feature("exceptionclass") logic_error;
%feature("exceptionclass") domain_error;
%feature("exceptionclass") invalid_argument;
%feature("exceptionclass") length_error;
%feature("exceptionclass") out_of_range;
%feature("exceptionclass") runtime_error;
%feature("exceptionclass") range_error;
%feature("exceptionclass") overflow_error;
%feature("exceptionclass") underflow_error;
}
namespace std {
struct exception
{
virtual ~exception() throw();
virtual const char* what() const throw();
};
struct bad_exception : exception
{
};
struct logic_error : exception
{
logic_error(const string& msg);
};
struct domain_error : logic_error
{
domain_error(const string& msg);
};
struct invalid_argument : logic_error
{
invalid_argument(const string& msg);
};
struct length_error : logic_error
{
length_error(const string& msg);
};
struct out_of_range : logic_error
{
out_of_range(const string& msg);
};
struct runtime_error : exception
{
runtime_error(const string& msg);
};
struct range_error : runtime_error
{
range_error(const string& msg);
};
struct overflow_error : runtime_error
{
overflow_error(const string& msg);
};
struct underflow_error : runtime_error
{
underflow_error(const string& msg);
};
}

View file

@ -61,7 +61,7 @@
%swig_container_methods(Map) %swig_container_methods(Map)
%extend { %extend {
mapped_type __getitem__(const key_type& key) const { mapped_type __getitem__(const key_type& key) const throw (std::out_of_range) {
Map::const_iterator i = self->find(key); Map::const_iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -69,11 +69,11 @@
throw std::out_of_range("key not found"); throw std::out_of_range("key not found");
} }
void __setitem__(const key_type& key, const mapped_type& x) { void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) {
self->insert(Map::value_type(key,x)); self->insert(Map::value_type(key,x));
} }
void __delitem__(const key_type& key) { void __delitem__(const key_type& key) throw (std::out_of_range) {
Map::iterator i = self->find(key); Map::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);

View file

@ -47,7 +47,7 @@
return self->find(x) != self->end(); return self->find(x) != self->end();
} }
value_type __getitem__(difference_type i) const { value_type __getitem__(difference_type i) const throw (std::out_of_range) {
return *(swig::cgetpos(self, i)); return *(swig::cgetpos(self, i));
} }
}; };

View file

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

View file

@ -5,24 +5,7 @@
// //
// Ruby implementation // Ruby implementation
%include std_common.i %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()));
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// std::map // std::map
@ -192,7 +175,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -202,7 +185,7 @@ namespace std {
void __setitem__(const K& key, const T& x) { void __setitem__(const K& key, const T& x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) { if (i != self->end()) {
T x = i->second; T x = i->second;
@ -396,7 +379,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T& __getitem__(K key) { T& __getitem__(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;
@ -406,7 +389,7 @@ namespace std {
void __setitem__(K key, const T& x) { void __setitem__(K key, const T& x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) { if (i != self->end()) {
T x = i->second; T x = i->second;
@ -594,7 +577,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -604,7 +587,7 @@ namespace std {
void __setitem__(const K& key, T x) { void __setitem__(const K& key, T x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) { if (i != self->end()) {
T x = i->second; T x = i->second;
@ -779,7 +762,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T __getitem__(K key) { T __getitem__(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;
@ -789,7 +772,7 @@ namespace std {
void __setitem__(K key, T x) { void __setitem__(K key, T x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) { if (i != self->end()) {
T x = i->second; T x = i->second;

View file

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

View file

@ -1,79 +1,35 @@
%include <std_string.i> // Typemaps used by the STL wrappers that throw exceptions.
%include <exception.i> // These typemaps are used when methods are declared with an STL exception specification, such as
// size_t at() const throw (std::out_of_range);
%{ #if defined(SWIGJAVA)
#include <stdexcept> %typemap(throws) std::out_of_range %{
%} SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, _e.what());
return $null; %}
namespace std { #elif defined(SWIGCSHARP)
/* Mark all of them as exception classes */ %typemap(throws, canthrow=1) std::out_of_range %{
%feature("exceptionclass") exception; SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, _e.what());
%feature("exceptionclass") bad_exception; return $null; %}
%feature("exceptionclass") logic_error; %typemap(throws, canthrow=1) std::invalid_argument %{
%feature("exceptionclass") domain_error; SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentException, _e.what(), "");
%feature("exceptionclass") invalid_argument; return $null; %}
%feature("exceptionclass") length_error; #elif defined(SWIGPYTHON)
%feature("exceptionclass") out_of_range; %include "exception.i"
%feature("exceptionclass") runtime_error; %typemap(throws) std::out_of_range %{
%feature("exceptionclass") range_error; if (!PyErr_Occurred()) {
%feature("exceptionclass") overflow_error; SWIG_exception(SWIG_IndexError, _e.what());
%feature("exceptionclass") underflow_error; } else {
} SWIG_fail;
} %}
namespace std { %typemap(throws) std::invalid_argument %{
struct exception if (!PyErr_Occurred()) {
{ SWIG_exception(SWIG_TypeError, _e.what());
virtual ~exception() throw(); } else {
virtual const char* what() const throw(); SWIG_fail;
}; } %}
#elif
struct bad_exception : exception %include "exception.i"
{ %typemap(throws) std::out_of_range %{
}; SWIG_exception(SWIG_IndexError, _e.what()); %}
#endif
struct logic_error : exception
{
logic_error(const string& msg);
};
struct domain_error : logic_error
{
domain_error(const string& msg);
};
struct invalid_argument : logic_error
{
invalid_argument(const string& msg);
};
struct length_error : logic_error
{
length_error(const string& msg);
};
struct out_of_range : logic_error
{
out_of_range(const string& msg);
};
struct runtime_error : exception
{
runtime_error(const string& msg);
};
struct range_error : runtime_error
{
range_error(const string& msg);
};
struct overflow_error : runtime_error
{
overflow_error(const string& msg);
};
struct underflow_error : runtime_error
{
underflow_error(const string& msg);
};
}

View file

@ -5,6 +5,8 @@
// //
// Tcl implementation // Tcl implementation
%include <std/std_except.i>
%types(std::size_t); %types(std::size_t);
%apply size_t { std::size_t }; %apply size_t { std::size_t };
%apply const unsigned long& { const std::size_t& }; %apply const unsigned long& { const std::size_t& };

View file

@ -5,24 +5,7 @@
// //
// Common implementation // Common implementation
%include std_common.i %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()));
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// std::map // std::map
@ -48,7 +31,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -58,7 +41,7 @@ namespace std {
void set(const K& key, const T& x) { void set(const K& key, const T& x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -87,7 +70,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T& get(K key) { T& get(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;
@ -97,7 +80,7 @@ namespace std {
void set(K key, const T& x) { void set(K key, const T& x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -123,7 +106,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
@ -133,7 +116,7 @@ namespace std {
void set(const K& key, T x) { void set(const K& key, T x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
@ -160,7 +143,7 @@ namespace std {
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
T get(K key) { T get(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;
@ -170,7 +153,7 @@ namespace std {
void set(K key, T x) { void set(K key, T x) {
(*self)[key] = 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); std::map<K,T >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);

View file

@ -5,36 +5,7 @@
// //
// Tcl implementation // Tcl implementation
%include <std_common.i>
%include exception.i
// containers
// methods which can raise are caused to throw an IndexError
%exception std::vector::get {
try {
$action
} catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%exception std::vector::set {
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()));
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// std::vector // std::vector
@ -241,14 +212,14 @@ namespace std {
%rename(push) push_back; %rename(push) push_back;
void push_back(const T& x); void push_back(const T& x);
%extend { %extend {
T pop() { T pop() throw (std::out_of_range) {
if (self->size() == 0) if (self->size() == 0)
throw std::out_of_range("pop from empty vector"); throw std::out_of_range("pop from empty vector");
T x = self->back(); T x = self->back();
self->pop_back(); self->pop_back();
return x; return x;
} }
T& get(int i) { T& get(int i) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i<0) i += size; if (i<0) i += size;
if (i>=0 && i<size) if (i>=0 && i<size)
@ -256,7 +227,7 @@ namespace std {
else else
throw std::out_of_range("vector index out of range"); throw std::out_of_range("vector index out of range");
} }
void set(int i, const T& x) { void set(int i, const T& x) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i<0) i+= size; if (i<0) i+= size;
if (i>=0 && i<size) if (i>=0 && i<size)
@ -392,14 +363,14 @@ namespace std {
%rename(push) push_back; %rename(push) push_back;
void push_back(T x); void push_back(T x);
%extend { %extend {
T pop() { T pop() throw (std::out_of_range) {
if (self->size() == 0) if (self->size() == 0)
throw std::out_of_range("pop from empty vector"); throw std::out_of_range("pop from empty vector");
T x = self->back(); T x = self->back();
self->pop_back(); self->pop_back();
return x; return x;
} }
T get(int i) { T get(int i) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i<0) i += size; if (i<0) i += size;
if (i>=0 && i<size) if (i>=0 && i<size)
@ -407,7 +378,7 @@ namespace std {
else else
throw std::out_of_range("vector index out of range"); throw std::out_of_range("vector index out of range");
} }
void set(int i, T x) { void set(int i, T x) throw (std::out_of_range) {
int size = int(self->size()); int size = int(self->size());
if (i<0) i+= size; if (i<0) i+= size;
if (i>=0 && i<size) if (i>=0 && i<size)