Updated CHANGES.current.
Fixed problems with insert() and unshift() functions in std::vector for ruby. Updated Ruby documentation. Improved swig_assert.rb. Added "second" singleton to std_pair in ruby. Modified two tests to follow the new STL stuff. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9721 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
b2a45de097
commit
806d9040c5
11 changed files with 2768 additions and 1075 deletions
|
|
@ -109,6 +109,7 @@
|
|||
template <class T, class U >
|
||||
struct traits_from<std::pair<T,U> > {
|
||||
static PyObject *from(const std::pair<T,U>& val) {
|
||||
fprintf( stderr, "%s %d\n", __PRETTY_FUNCTION__, __LINE__);
|
||||
PyObject* obj = PyTuple_New(2);
|
||||
PyTuple_SetItem(obj,0,swig::from(val.first));
|
||||
PyTuple_SetItem(obj,1,swig::from(val.second));
|
||||
|
|
|
|||
|
|
@ -807,6 +807,7 @@ namespace swig
|
|||
|
||||
|
||||
%define %swig_sequence_front_inserters( Sequence... )
|
||||
|
||||
%extend {
|
||||
|
||||
VALUE shift()
|
||||
|
|
@ -822,35 +823,41 @@ namespace swig
|
|||
$2 = argv + 1;
|
||||
}
|
||||
|
||||
Sequence* insert( difference_type idx, int argc, VALUE* argv, ... )
|
||||
Sequence* insert( difference_type pos, int argc, VALUE* argv, ... )
|
||||
{
|
||||
std::size_t len = $self->size();
|
||||
std::size_t i = swig::check_index( idx, len, true );
|
||||
Sequence::value_type val;
|
||||
std::size_t i = swig::check_index( pos, len, true );
|
||||
Sequence::iterator start;
|
||||
int res = swig::asval( argv[0], &val );
|
||||
if (!SWIG_IsOK(res))
|
||||
SWIG_exception_fail(SWIG_ArgError(res),
|
||||
Ruby_Format_TypeError( "",
|
||||
swig::type_name<Sequence::value_type>(), __FUNCTION__, 2, argv[0] ));
|
||||
if ( i >= len ) {
|
||||
$self->resize(i-1, val);
|
||||
return $self;
|
||||
}
|
||||
start = $self->begin();
|
||||
std::advance( start, i );
|
||||
$self->insert( start++, val );
|
||||
for ( int idx = 1; idx < argc; ++idx )
|
||||
|
||||
VALUE elem = argv[0];
|
||||
int idx = 0;
|
||||
try {
|
||||
Sequence::value_type val = swig::as<Sequence::value_type>( elem, true );
|
||||
if ( i >= len ) {
|
||||
$self->resize(i-1, val);
|
||||
return $self;
|
||||
}
|
||||
start = $self->begin();
|
||||
std::advance( start, i );
|
||||
$self->insert( start++, val );
|
||||
|
||||
for ( ++idx; idx < argc; ++idx )
|
||||
{
|
||||
elem = argv[idx];
|
||||
val = swig::as<Sequence::value_type>( elem );
|
||||
$self->insert( start++, val );
|
||||
}
|
||||
|
||||
}
|
||||
catch( std::invalid_argument )
|
||||
{
|
||||
int res = swig::asval( argv[idx], &val );
|
||||
if (!SWIG_IsOK(res))
|
||||
SWIG_exception_fail(SWIG_ArgError(res),
|
||||
Ruby_Format_TypeError( "",
|
||||
swig::type_name<Sequence::value_type>(), __FUNCTION__, idx+2, argv[idx] ));
|
||||
$self->insert( start++, val );
|
||||
rb_raise( rb_eArgError,
|
||||
Ruby_Format_TypeError( "",
|
||||
swig::type_name<Sequence::value_type>(),
|
||||
__FUNCTION__, idx+2, elem ));
|
||||
}
|
||||
|
||||
fail:
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
@ -861,19 +868,24 @@ namespace swig
|
|||
|
||||
Sequence* unshift( int argc, VALUE* argv, ... )
|
||||
{
|
||||
Sequence::value_type val;
|
||||
for ( int idx = argc-1; idx >= 0; --idx )
|
||||
{
|
||||
int res = swig::asval( argv[idx], &val );
|
||||
if (!SWIG_IsOK(res))
|
||||
SWIG_exception_fail(SWIG_ArgError(res),
|
||||
Ruby_Format_TypeError( "",
|
||||
swig::type_name<Sequence::value_type>(), __FUNCTION__, idx+2, argv[idx] ));
|
||||
Sequence::iterator start = $self->begin();
|
||||
$self->insert( start, val );
|
||||
VALUE elem = argv[idx];
|
||||
Sequence::value_type val;
|
||||
try {
|
||||
Sequence::value_type val = swig::as<Sequence::value_type>( elem, true );
|
||||
$self->insert( start, val );
|
||||
}
|
||||
catch( std::invalid_argument )
|
||||
{
|
||||
rb_raise( rb_eArgError,
|
||||
Ruby_Format_TypeError( "",
|
||||
swig::type_name<Sequence::value_type>(),
|
||||
__FUNCTION__, idx+2, elem ));
|
||||
}
|
||||
}
|
||||
|
||||
fail:
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,22 +50,22 @@ RUBYKW(when);
|
|||
RUBYKW(while);
|
||||
RUBYKW(yield);
|
||||
|
||||
RUBYKW(FalseClass);
|
||||
RUBYKW(TrueClass);
|
||||
RUBYKW(Numeric);
|
||||
RUBYKW(Integer);
|
||||
RUBYKW(Fixnum);
|
||||
RUBYKW(Float);
|
||||
RUBYKW(Range);
|
||||
RUBYKW(Array);
|
||||
RUBYKW(String);
|
||||
RUBYKW(IO);
|
||||
RUBYKW(File);
|
||||
RUBYKW(FileUtils);
|
||||
RUBYKW(Find);
|
||||
RUBYKW(Struct);
|
||||
RUBYKW(OpenStruct);
|
||||
RUBYKW(Regexp);
|
||||
// RUBYKW(FalseClass);
|
||||
// RUBYKW(TrueClass);
|
||||
// RUBYKW(Numeric);
|
||||
// RUBYKW(Integer);
|
||||
// RUBYKW(Fixnum);
|
||||
// RUBYKW(Float);
|
||||
// RUBYKW(Range);
|
||||
// RUBYKW(Array);
|
||||
// RUBYKW(String);
|
||||
// RUBYKW(IO);
|
||||
// RUBYKW(File);
|
||||
// RUBYKW(FileUtils);
|
||||
// RUBYKW(Find);
|
||||
// RUBYKW(Struct);
|
||||
// RUBYKW(OpenStruct);
|
||||
// RUBYKW(Regexp);
|
||||
|
||||
#undef RUBYKW
|
||||
|
||||
|
|
|
|||
|
|
@ -165,10 +165,10 @@ namespace swig {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class Type>
|
||||
inline Type as(VALUE obj, bool te = false) {
|
||||
return traits_as<Type, typename traits<Type>::category>::as(obj, te);
|
||||
return traits_as< Type, typename traits< Type >::category >::as(obj, te);
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
|
|
@ -194,46 +194,6 @@ namespace swig {
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Backward compatibility
|
||||
//
|
||||
|
||||
%define %specialize_std_container(Type,Check,As,From)
|
||||
%{
|
||||
namespace swig {
|
||||
template <> struct traits_asval<Type > {
|
||||
typedef Type value_type;
|
||||
static int asval(VALUE obj, value_type *val) {
|
||||
if (Check(obj)) {
|
||||
if (val) *val = As(obj);
|
||||
return SWIG_OK;
|
||||
}
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
};
|
||||
template <> struct traits_from<Type > {
|
||||
typedef Type value_type;
|
||||
static VALUE from(const value_type& val) {
|
||||
return From(val);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct traits_check<Type, value_category> {
|
||||
static int check(VALUE obj) {
|
||||
int res = Check(obj);
|
||||
return obj && res ? res : 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
%}
|
||||
%enddef
|
||||
|
||||
#define SWIG_RUBY_THREAD_BEGIN_BLOCK
|
||||
#define SWIG_RUBY_THREAD_END_BLOCK
|
||||
|
||||
#define specialize_std_vector(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
|
||||
#define specialize_std_list(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
|
||||
#define specialize_std_deque(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
|
||||
#define specialize_std_set(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
|
||||
#define specialize_std_multiset(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue