Added more STL (more exceptions, map, size_t), fixed test case: conversion_ns_template.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9628 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
bc08e0f335
commit
515e846e2a
7 changed files with 135 additions and 16 deletions
|
|
@ -43,6 +43,9 @@
|
|||
%typemap(out) enum SWIGTYPE
|
||||
%{ lua_pushnumber(L, (lua_Number)(int)($1)); SWIG_arg++;%}
|
||||
|
||||
// size_t (which is just a unsigned long
|
||||
%apply unsigned long { size_t };
|
||||
|
||||
// boolean (which is a special type in lua)
|
||||
// note: 1 & 0 are not booleans in lua, only true & false
|
||||
%typemap(in,checkfn="lua_isboolean") bool
|
||||
|
|
@ -209,7 +212,8 @@ parmeters match which function
|
|||
const unsigned int &, const unsigned short &, const unsigned long &,
|
||||
const long long &, const unsigned long long &,
|
||||
enum SWIGTYPE, float, double,
|
||||
const float &, const double &
|
||||
const float &, const double&,
|
||||
size_t,const size_t&
|
||||
{
|
||||
$1 = lua_isnumber(L,$input);
|
||||
}
|
||||
|
|
@ -301,6 +305,8 @@ SWIG_NUMBER_BY_CONST_REF(long long);
|
|||
SWIG_NUMBER_BY_CONST_REF(signed long long);
|
||||
SWIG_NUMBER_BY_CONST_REF(unsigned long long);
|
||||
|
||||
%apply const unsigned long & { const size_t & };
|
||||
|
||||
|
||||
// Also needed for object ptrs by const ref
|
||||
// eg const A* ref_pointer(A* const& a);
|
||||
|
|
|
|||
5
Lib/lua/std_common.i
Normal file
5
Lib/lua/std_common.i
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
%include <std_except.i>
|
||||
|
||||
%apply size_t { std::size_t };
|
||||
%apply const size_t& { const std::size_t& };
|
||||
|
||||
|
|
@ -15,11 +15,29 @@
|
|||
%}
|
||||
%include <exception.i>
|
||||
|
||||
%typemap(throws) std::out_of_range %{
|
||||
SWIG_exception(SWIG_IndexError, $1.what()); %}
|
||||
namespace std
|
||||
{
|
||||
%ignore exception; // not sure if I should ignore this...
|
||||
class exception
|
||||
{
|
||||
public:
|
||||
exception() throw() { }
|
||||
virtual ~exception() throw();
|
||||
virtual const char* what() const throw();
|
||||
};
|
||||
}
|
||||
|
||||
%typemap(throws) std::exception %{
|
||||
SWIG_exception(SWIG_SystemError, $1.what()); %}
|
||||
|
||||
%typemap(throws) std::exception& %{
|
||||
SWIG_exception(SWIG_SystemError, ($1)->what()); %}
|
||||
// normally object whihc are thrown are returned to interpreter as errors
|
||||
// (which potentally may have problems if they are not copied)
|
||||
// therefore all classes based upon std::exception are converted to their strings & returned as errors
|
||||
%typemap(throws) std::bad_exception "SWIG_exception(SWIG_RuntimeError, $1.what());"
|
||||
%typemap(throws) std::domain_error "SWIG_exception(SWIG_ValueError, $1.what());"
|
||||
%typemap(throws) std::exception "SWIG_exception(SWIG_SystemError, $1.what());"
|
||||
%typemap(throws) std::invalid_argument "SWIG_exception(SWIG_ValueError, $1.what());"
|
||||
%typemap(throws) std::length_error "SWIG_exception(SWIG_IndexError, $1.what());"
|
||||
%typemap(throws) std::logic_error "SWIG_exception(SWIG_RuntimeError, $1.what());"
|
||||
%typemap(throws) std::out_of_range "SWIG_exception(SWIG_IndexError, $1.what());"
|
||||
%typemap(throws) std::overflow_error "SWIG_exception(SWIG_OverflowError, $1.what());"
|
||||
%typemap(throws) std::range_error "SWIG_exception(SWIG_IndexError, $1.what());"
|
||||
%typemap(throws) std::runtime_error "SWIG_exception(SWIG_RuntimeError, $1.what());"
|
||||
%typemap(throws) std::underflow_error "SWIG_exception(SWIG_RuntimeError, $1.what());"
|
||||
|
|
|
|||
63
Lib/lua/std_map.i
Normal file
63
Lib/lua/std_map.i
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* See the LICENSE file for information on copyright, usage and redistribution
|
||||
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||
*
|
||||
* std_map.i
|
||||
*
|
||||
* SWIG typemaps for std::map
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <std_common.i>
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::map
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%{
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
%}
|
||||
|
||||
// exported class
|
||||
|
||||
namespace std {
|
||||
|
||||
template<class K, class T> class map {
|
||||
// add typemaps here
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef K key_type;
|
||||
typedef T mapped_type;
|
||||
map();
|
||||
map(const map<K,T> &);
|
||||
|
||||
unsigned int size() const;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%extend {
|
||||
const T& get(const K& key) throw (std::out_of_range) {
|
||||
std::map<K,T >::iterator i = self->find(key);
|
||||
if (i != self->end())
|
||||
return i->second;
|
||||
else
|
||||
throw std::out_of_range("key not found");
|
||||
}
|
||||
void set(const K& key, const T& x) {
|
||||
(*self)[key] = x;
|
||||
}
|
||||
void del(const K& key) throw (std::out_of_range) {
|
||||
std::map<K,T >::iterator i = self->find(key);
|
||||
if (i != self->end())
|
||||
self->erase(i);
|
||||
else
|
||||
throw std::out_of_range("key not found");
|
||||
}
|
||||
bool has_key(const K& key) {
|
||||
std::map<K,T >::iterator i = self->find(key);
|
||||
return i != self->end();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
13
Lib/lua/stl.i
Normal file
13
Lib/lua/stl.i
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* See the LICENSE file for information on copyright, usage and redistribution
|
||||
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
|
||||
*
|
||||
* stl.i
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <std_common.i>
|
||||
%include <std_string.i>
|
||||
%include <std_vector.i>
|
||||
%include <std_map.i>
|
||||
%include <std_pair.i>
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue