diff --git a/Lib/_std_deque.i b/Lib/_std_deque.i index 907450719..8c6dfb440 100644 --- a/Lib/_std_deque.i +++ b/Lib/_std_deque.i @@ -3,36 +3,13 @@ * this file to generate wrappers. */ +%include + %{ #include #include %} -%include "exception.i" - -%exception std::deque::getitem { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - -%exception std::deque::setitem { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - -%exception std::deque::delitem { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} /* This macro defines all of the standard methods for a deque. This is defined as a macro to simplify the task of specialization. For @@ -69,7 +46,7 @@ /* Some useful extensions */ %extend { - const_reference getitem(int i) { + const_reference getitem(int i) throw (std::out_of_range) { int size = int(self->size()); if (i<0) i += size; if (i>=0 && isize()); if (i<0) i+= size; if (i>=0 && isize()); if (i<0) i+= size; if (i>=0 && i %apply size_t { std::size_t }; diff --git a/Lib/csharp/std_map.i b/Lib/csharp/std_map.i index 600c9ef27..006a62efd 100644 --- a/Lib/csharp/std_map.i +++ b/Lib/csharp/std_map.i @@ -5,26 +5,7 @@ // // Common implementation -%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(e.what())); - return $null; - } -} - -%exception std::map::del { - try { - $action - } catch (std::out_of_range& e) { - SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpIndexOutOfRangeException, const_cast(e.what())); - return $null; - } -} +%include // ------------------------------------------------------------------------ // std::map @@ -50,7 +31,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::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -60,7 +41,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -89,7 +70,7 @@ namespace std { bool empty() const; void clear(); %extend { - T& get(K key) { + T& get(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -99,7 +80,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -125,7 +106,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::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -135,7 +116,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -162,7 +143,7 @@ namespace std { bool empty() const; void clear(); %extend { - T get(K key) { + T get(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -172,7 +153,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i index a9cdf1ae6..d6eec7e94 100755 --- a/Lib/csharp/std_vector.i +++ b/Lib/csharp/std_vector.i @@ -8,6 +8,8 @@ * Warning: heavy macro usage in this file. Use swig -E to get a sane view on the real file contents! */ +%include + // MACRO for use within the std::vector class body // CSTYPE and CTYPE respectively correspond to the types in the cstype and ctype typemaps %define SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE...) @@ -172,7 +174,7 @@ %newobject Repeat(const CTYPE& value, int count); vector(); %extend { - vector(int capacity) { + vector(int capacity) throw (std::out_of_range) { std::vector* pv = 0; if (capacity >= 0) { pv = new std::vector(); @@ -182,19 +184,19 @@ } return pv; } - CTYPE getitemcopy(int index) { + CTYPE getitemcopy(int index) throw (std::out_of_range) { if (index>=0 && index<(int)self->size()) return (*self)[index]; else 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()) return (*self)[index]; else 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()) (*self)[index] = value; else @@ -205,44 +207,44 @@ self->insert(self->end(), values.begin(), values.end()); } // Takes a deep copy of the elements unlike ArrayList.GetRange - std::vector *GetRange(int index, int count) { + std::vector *GetRange(int index, int count) throw (std::out_of_range, std::invalid_argument) { if (index < 0) throw std::out_of_range("index"); if (count < 0) throw std::out_of_range("count"); if (index >= (int)self->size()+1 || index+count > (int)self->size()) - throw "invalid range"; + throw std::invalid_argument("invalid range"); return new std::vector(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) self->insert(self->begin()+index, value); else throw std::out_of_range("index"); } // Takes a deep copy of the elements unlike ArrayList.InsertRange - void InsertRange(int index, const std::vector& values) { + void InsertRange(int index, const std::vector& values) throw (std::out_of_range) { if (index>=0 && index<(int)self->size()+1) self->insert(self->begin()+index, values.begin(), values.end()); else 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()) self->erase(self->begin() + index); else 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) throw std::out_of_range("index"); if (count < 0) throw std::out_of_range("count"); 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); } - static std::vector *Repeat(const CTYPE& value, int count) { + static std::vector *Repeat(const CTYPE& value, int count) throw (std::out_of_range) { if (count < 0) throw std::out_of_range("count"); return new std::vector(count, value); @@ -250,17 +252,17 @@ void Reverse() { 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) throw std::out_of_range("index"); if (count < 0) throw std::out_of_range("count"); 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); } // Takes a deep copy of the elements unlike ArrayList.SetRange - void SetRange(int index, const std::vector& values) { + void SetRange(int index, const std::vector& values) throw (std::out_of_range) { if (index < 0) throw std::out_of_range("index"); if (index+values.size() > self->size()) @@ -319,125 +321,6 @@ namespace std { %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 #include diff --git a/Lib/guile/std_common.i b/Lib/guile/std_common.i index 2ceb87f10..f54947d3d 100644 --- a/Lib/guile/std_common.i +++ b/Lib/guile/std_common.i @@ -5,6 +5,8 @@ // // Guile implementation +%include + %apply size_t { std::size_t }; #define SWIG_bool2scm(b) gh_bool2scm(b ? 1 : 0) diff --git a/Lib/guile/std_map.i b/Lib/guile/std_map.i index ab6cdf274..f6c97f83a 100644 --- a/Lib/guile/std_map.i +++ b/Lib/guile/std_map.i @@ -5,24 +5,7 @@ // // Guile 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(e.what())); - } -} - -%exception std::map::__delitem__ { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} +%include // ------------------------------------------------------------------------ // std::map @@ -242,7 +225,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::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -252,7 +235,7 @@ namespace std { void __setitem__(const K& key, const T& x) { (*self)[key] = x; } - void __delitem__(const K& key) { + void __delitem__(const K& key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -462,7 +445,7 @@ namespace std { bool empty() const; void clear(); %extend { - T& __getitem__(K key) { + T& __getitem__(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -472,7 +455,7 @@ namespace std { void __setitem__(K key, const T& x) { (*self)[key] = x; } - void __delitem__(K key) { + void __delitem__(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -674,7 +657,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::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -684,7 +667,7 @@ namespace std { void __setitem__(const K& key, T x) { (*self)[key] = x; } - void __delitem__(const K& key) { + void __delitem__(const K& key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -886,7 +869,7 @@ namespace std { bool empty() const; void clear(); %extend { - T __getitem__(K key) { + T __getitem__(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -896,7 +879,7 @@ namespace std { void __setitem__(K key, T x) { (*self)[key] = x; } - void __delitem__(K key) { + void __delitem__(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) self->erase(i); diff --git a/Lib/guile/std_vector.i b/Lib/guile/std_vector.i index ea17eef7c..cb0da4cd5 100644 --- a/Lib/guile/std_vector.i +++ b/Lib/guile/std_vector.i @@ -5,33 +5,7 @@ // // Guile implementation -%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(e.what())); - } -} - -%exception std::vector::set { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - -%exception std::vector::pop { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - +%include // ------------------------------------------------------------------------ // std::vector @@ -228,21 +202,21 @@ 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& ref(int i) { + T& ref(int i) throw (std::out_of_range) { int size = int(self->size()); if (i>=0 && isize()); if (i>=0 && isize() == 0) throw std::out_of_range("pop from empty vector"); T x = self->back(); self->pop_back(); return x; } - T ref(int i) { + T ref(int i) throw (std::out_of_range) { int size = int(self->size()); if (i>=0 && isize()); if (i>=0 && i + %apply size_t { std::size_t }; diff --git a/Lib/java/std_map.i b/Lib/java/std_map.i index 001b718c4..006a62efd 100644 --- a/Lib/java/std_map.i +++ b/Lib/java/std_map.i @@ -5,26 +5,7 @@ // // Common implementation -%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(e.what())); - return $null; - } -} - -%exception std::map::del { - try { - $action - } catch (std::out_of_range& e) { - SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, const_cast(e.what())); - return $null; - } -} +%include // ------------------------------------------------------------------------ // std::map @@ -50,7 +31,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::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -60,7 +41,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -89,7 +70,7 @@ namespace std { bool empty() const; void clear(); %extend { - T& get(K key) { + T& get(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -99,7 +80,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -125,7 +106,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::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -135,7 +116,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -162,7 +143,7 @@ namespace std { bool empty() const; void clear(); %extend { - T get(K key) { + T get(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -172,7 +153,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); diff --git a/Lib/java/std_vector.i b/Lib/java/std_vector.i index 2cd929e9f..fb945d986 100644 --- a/Lib/java/std_vector.i +++ b/Lib/java/std_vector.i @@ -5,27 +5,7 @@ // // Java implementation - -%include exception.i - -%exception std::vector::get { - try { - $action - } catch (std::out_of_range& e) { - SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, const_cast(e.what())); - return $null; - } -} - -%exception std::vector::set { - try { - $action - } catch (std::out_of_range& e) { - SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, const_cast(e.what())); - return $null; - } -} - +%include // ------------------------------------------------------------------------ // std::vector @@ -73,14 +53,14 @@ namespace std { %rename(add) push_back; void push_back(const T& x); %extend { - T& get(int i) { + T& get(int i) throw (std::out_of_range) { int size = int(self->size()); if (i>=0 && isize()); if (i>=0 && isize()); if (i>=0 && isize()); if (i>=0 && i + %apply size_t { std::size_t }; %{ diff --git a/Lib/mzscheme/std_map.i b/Lib/mzscheme/std_map.i index 86374c5bc..808c343f5 100644 --- a/Lib/mzscheme/std_map.i +++ b/Lib/mzscheme/std_map.i @@ -5,24 +5,7 @@ // // MzScheme 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(e.what())); - } -} - -%exception std::map::__delitem__ { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} +%include // ------------------------------------------------------------------------ // std::map @@ -242,7 +225,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::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -252,7 +235,7 @@ namespace std { void __setitem__(const K& key, const T& x) { (*self)[key] = x; } - void __delitem__(const K& key) { + void __delitem__(const K& key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -462,7 +445,7 @@ namespace std { bool empty() const; void clear(); %extend { - T& __getitem__(K key) { + T& __getitem__(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -472,7 +455,7 @@ namespace std { void __setitem__(K key, const T& x) { (*self)[key] = x; } - void __delitem__(K key) { + void __delitem__(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -674,7 +657,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::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -684,7 +667,7 @@ namespace std { void __setitem__(const K& key, T x) { (*self)[key] = x; } - void __delitem__(const K& key) { + void __delitem__(const K& key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -886,7 +869,7 @@ namespace std { bool empty() const; void clear(); %extend { - T __getitem__(K key) { + T __getitem__(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -896,7 +879,7 @@ namespace std { void __setitem__(K key, T x) { (*self)[key] = x; } - void __delitem__(K key) { + void __delitem__(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) self->erase(i); diff --git a/Lib/mzscheme/std_vector.i b/Lib/mzscheme/std_vector.i index be8923b33..409c66fc6 100644 --- a/Lib/mzscheme/std_vector.i +++ b/Lib/mzscheme/std_vector.i @@ -5,36 +5,7 @@ // // MzScheme implementation -%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(e.what())); - } -} - -%exception std::vector::set { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - -%exception std::vector::pop { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - +%include // ------------------------------------------------------------------------ // std::vector @@ -233,21 +204,21 @@ 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& ref(int i) { + T& ref(int i) throw (std::out_of_range) { int size = int(self->size()); if (i>=0 && isize()); if (i>=0 && isize() == 0) throw std::out_of_range("pop from empty vector"); T x = self->back(); self->pop_back(); return x; } - T ref(int i) { + T ref(int i) throw (std::out_of_range) { int size = int(self->size()); if (i>=0 && isize()); if (i>=0 && i + %apply size_t { std::size_t }; %{ diff --git a/Lib/ocaml/std_list.i b/Lib/ocaml/std_list.i index 8cf5354e4..957ab35d3 100644 --- a/Lib/ocaml/std_list.i +++ b/Lib/ocaml/std_list.i @@ -6,6 +6,7 @@ // // Python implementation +%include %module std_list %{ @@ -13,32 +14,6 @@ #include %} -%include "exception.i" - -%exception std::list::__getitem__ { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - -%exception std::list::__setitem__ { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - -%exception std::list::__delitem__ { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - namespace std{ template 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::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::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::iterator first = self->begin(); int size = int(self->size()); diff --git a/Lib/ocaml/std_map.i b/Lib/ocaml/std_map.i index aae944c2e..1fd74ef3e 100644 --- a/Lib/ocaml/std_map.i +++ b/Lib/ocaml/std_map.i @@ -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(e.what())); - } -} - -%exception std::map::del { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} +%include // ------------------------------------------------------------------------ // 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::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::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::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::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::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::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::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::iterator i = self->find(key); if (i != self->end()) self->erase(i); diff --git a/Lib/perl5/std_common.i b/Lib/perl5/std_common.i index e5d3dd927..86b38f5f8 100644 --- a/Lib/perl5/std_common.i +++ b/Lib/perl5/std_common.i @@ -5,6 +5,8 @@ // // Perl implementation +%include + %apply size_t { std::size_t }; %{ diff --git a/Lib/perl5/std_map.i b/Lib/perl5/std_map.i index 38a063e95..006a62efd 100644 --- a/Lib/perl5/std_map.i +++ b/Lib/perl5/std_map.i @@ -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(e.what())); - } -} - -%exception std::map::del { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} +%include // ------------------------------------------------------------------------ // std::map @@ -48,7 +31,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::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -58,7 +41,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -87,7 +70,7 @@ namespace std { bool empty() const; void clear(); %extend { - T& get(K key) { + T& get(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -97,7 +80,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -123,7 +106,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::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -133,7 +116,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -160,7 +143,7 @@ namespace std { bool empty() const; void clear(); %extend { - T get(K key) { + T get(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -170,7 +153,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); diff --git a/Lib/perl5/std_vector.i b/Lib/perl5/std_vector.i index e39c66b2f..09d5f40c5 100644 --- a/Lib/perl5/std_vector.i +++ b/Lib/perl5/std_vector.i @@ -9,36 +9,7 @@ // // Perl 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(e.what())); - } -} - -%exception std::vector::set { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - -%exception std::vector::pop { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - +%include // ------------------------------------------------------------------------ // std::vector @@ -226,21 +197,21 @@ 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& get(int i) { + T& get(int i) throw (std::out_of_range) { int size = int(self->size()); if (i>=0 && isize()); if (i>=0 && isize() == 0) throw std::out_of_range("pop from empty vector"); T x = self->back(); self->pop_back(); return x; } - T get(int i) { + T get(int i) throw (std::out_of_range) { int size = int(self->size()); if (i>=0 && isize()); if (i>=0 && i + %apply size_t { std::size_t }; diff --git a/Lib/php4/std_map.i b/Lib/php4/std_map.i index 38a063e95..006a62efd 100644 --- a/Lib/php4/std_map.i +++ b/Lib/php4/std_map.i @@ -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(e.what())); - } -} - -%exception std::map::del { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} +%include // ------------------------------------------------------------------------ // std::map @@ -48,7 +31,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::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -58,7 +41,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -87,7 +70,7 @@ namespace std { bool empty() const; void clear(); %extend { - T& get(K key) { + T& get(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -97,7 +80,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -123,7 +106,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::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -133,7 +116,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -160,7 +143,7 @@ namespace std { bool empty() const; void clear(); %extend { - T get(K key) { + T get(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -170,7 +153,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); diff --git a/Lib/php4/std_vector.i b/Lib/php4/std_vector.i index f17fbce1c..0904a9c83 100644 --- a/Lib/php4/std_vector.i +++ b/Lib/php4/std_vector.i @@ -5,35 +5,7 @@ // // PHP implementation -%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(e.what())); - } -} - -%exception std::vector::set { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - -%exception std::vector::pop { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - +%include // ------------------------------------------------------------------------ // std::vector @@ -79,21 +51,21 @@ 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& get(int i) { + T& get(int i) throw (std::out_of_range) { int size = int(self->size()); if (i>=0 && isize()); if (i>=0 && isize() == 0) throw std::out_of_range("pop from empty vector"); T x = self->back(); self->pop_back(); return x; } - T get(int i) { + T get(int i) throw (std::out_of_range) { int size = int(self->size()); if (i>=0 && isize()); if (i>=0 && i(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(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(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(e.what())); - } else { - SWIG_fail; - } - } - catch (std::invalid_argument& e) { - if (!PyErr_Occurred()) { - SWIG_exception(SWIG_TypeError,const_cast(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(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(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(e.what())); - } else { - SWIG_fail; - } - } - SWIG_CATCH_UNKNOWN - } %newobject __getslice__; @@ -469,7 +376,7 @@ namespace swig %fragment("PySequence_Base"); %extend { - value_type pop() { + value_type pop() throw (std::out_of_range) { if (self->size() == 0) throw std::out_of_range("pop from empty container"); Sequence::value_type x = self->back(); @@ -477,19 +384,19 @@ namespace swig 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); } - 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); } - 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); } - void __delitem__(difference_type i) { + void __delitem__(difference_type i) throw (std::out_of_range) { self->erase(swig::getpos(self,i)); } } @@ -498,11 +405,11 @@ namespace swig %define %swig_sequence_methods(Sequence...) %swig_sequence_methods_common(SWIG_arg(Sequence)) %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)); } - 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; } @@ -515,11 +422,11 @@ namespace swig %define %swig_sequence_methods_val(Sequence...) %swig_sequence_methods_common(SWIG_arg(Sequence)) %extend { - value_type __getitem__(difference_type i) { + value_type __getitem__(difference_type i) throw (std::out_of_range) { 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; } diff --git a/Lib/python/std_common.i b/Lib/python/std_common.i index 5a03fc2b6..37aa24419 100644 --- a/Lib/python/std_common.i +++ b/Lib/python/std_common.i @@ -1,3 +1,4 @@ +%include %include %include diff --git a/Lib/python/std_except.i b/Lib/python/std_except.i index d85c60337..8f7ce4ebb 100644 --- a/Lib/python/std_except.i +++ b/Lib/python/std_except.i @@ -1 +1,79 @@ %include +%include + +%{ +#include +%} + +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); + }; +} + diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i index 2f79bceb8..723ae48cf 100644 --- a/Lib/python/std_map.i +++ b/Lib/python/std_map.i @@ -61,7 +61,7 @@ %swig_container_methods(Map) %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); if (i != self->end()) return i->second; @@ -69,11 +69,11 @@ 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)); } - void __delitem__(const key_type& key) { + void __delitem__(const key_type& key) throw (std::out_of_range) { Map::iterator i = self->find(key); if (i != self->end()) self->erase(i); diff --git a/Lib/python/std_set.i b/Lib/python/std_set.i index cf9b9b47c..c5f43dd68 100644 --- a/Lib/python/std_set.i +++ b/Lib/python/std_set.i @@ -47,7 +47,7 @@ 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)); } }; diff --git a/Lib/ruby/std_common.i b/Lib/ruby/std_common.i index 163a7556e..abb9f6e2c 100644 --- a/Lib/ruby/std_common.i +++ b/Lib/ruby/std_common.i @@ -5,6 +5,8 @@ // // Ruby implementation +%include + %apply size_t { std::size_t }; %{ diff --git a/Lib/ruby/std_map.i b/Lib/ruby/std_map.i index 345196fc6..c2e054758 100644 --- a/Lib/ruby/std_map.i +++ b/Lib/ruby/std_map.i @@ -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(e.what())); - } -} - -%exception std::map::__delitem__ { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} +%include // ------------------------------------------------------------------------ // 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::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::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::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::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::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::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::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::iterator i = self->find(key); if (i != self->end()) { T x = i->second; diff --git a/Lib/ruby/std_vector.i b/Lib/ruby/std_vector.i index 7829755de..a9fccca51 100644 --- a/Lib/ruby/std_vector.i +++ b/Lib/ruby/std_vector.i @@ -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(e.what())); - } -} - -%exception std::vector::__setitem__ { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - -%exception std::vector::pop { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - +%include // ------------------------------------------------------------------------ // 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 && isize()); if (i<0) i+= size; if (i>=0 && isize() == 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 && isize()); if (i<0) i+= size; if (i>=0 && isize() == 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 && isize()); if (i<0) i+= size; if (i>=0 && i -%include +// Typemaps used by the STL wrappers that throw exceptions. +// These typemaps are used when methods are declared with an STL exception specification, such as +// size_t at() const throw (std::out_of_range); -%{ -#include -%} - -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); - }; -} +#if defined(SWIGJAVA) + %typemap(throws) std::out_of_range %{ + SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, _e.what()); + return $null; %} +#elif defined(SWIGCSHARP) + %typemap(throws, canthrow=1) std::out_of_range %{ + SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, 0, _e.what()); + return $null; %} + %typemap(throws, canthrow=1) std::invalid_argument %{ + SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentException, _e.what(), ""); + return $null; %} +#elif defined(SWIGPYTHON) + %include "exception.i" + %typemap(throws) std::out_of_range %{ + if (!PyErr_Occurred()) { + SWIG_exception(SWIG_IndexError, _e.what()); + } else { + SWIG_fail; + } %} + %typemap(throws) std::invalid_argument %{ + if (!PyErr_Occurred()) { + SWIG_exception(SWIG_TypeError, _e.what()); + } else { + SWIG_fail; + } %} +#elif + %include "exception.i" + %typemap(throws) std::out_of_range %{ + SWIG_exception(SWIG_IndexError, _e.what()); %} +#endif diff --git a/Lib/tcl/std_common.i b/Lib/tcl/std_common.i index 9d3df61c8..d3798f8f7 100644 --- a/Lib/tcl/std_common.i +++ b/Lib/tcl/std_common.i @@ -5,6 +5,8 @@ // // Tcl implementation +%include + %types(std::size_t); %apply size_t { std::size_t }; %apply const unsigned long& { const std::size_t& }; diff --git a/Lib/tcl/std_map.i b/Lib/tcl/std_map.i index 38a063e95..006a62efd 100644 --- a/Lib/tcl/std_map.i +++ b/Lib/tcl/std_map.i @@ -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(e.what())); - } -} - -%exception std::map::del { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} +%include // ------------------------------------------------------------------------ // std::map @@ -48,7 +31,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::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -58,7 +41,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -87,7 +70,7 @@ namespace std { bool empty() const; void clear(); %extend { - T& get(K key) { + T& get(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -97,7 +80,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -123,7 +106,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::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -133,7 +116,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); @@ -160,7 +143,7 @@ namespace std { bool empty() const; void clear(); %extend { - T get(K key) { + T get(K key) throw (std::out_of_range) { std::map::iterator i = self->find(key); if (i != self->end()) return i->second; @@ -170,7 +153,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::iterator i = self->find(key); if (i != self->end()) self->erase(i); diff --git a/Lib/tcl/std_vector.i b/Lib/tcl/std_vector.i index 897a19732..2b79b7b13 100644 --- a/Lib/tcl/std_vector.i +++ b/Lib/tcl/std_vector.i @@ -5,36 +5,7 @@ // // Tcl implementation - -%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(e.what())); - } -} - -%exception std::vector::set { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - -%exception std::vector::pop { - try { - $action - } catch (std::out_of_range& e) { - SWIG_exception(SWIG_IndexError,const_cast(e.what())); - } -} - +%include // ------------------------------------------------------------------------ // std::vector @@ -241,14 +212,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& get(int i) { + T& get(int i) throw (std::out_of_range) { int size = int(self->size()); if (i<0) i += size; if (i>=0 && isize()); if (i<0) i+= size; if (i>=0 && isize() == 0) throw std::out_of_range("pop from empty vector"); T x = self->back(); self->pop_back(); return x; } - T get(int i) { + T get(int i) throw (std::out_of_range) { int size = int(self->size()); if (i<0) i += size; if (i>=0 && isize()); if (i<0) i+= size; if (i>=0 && i