Fixed VALUE less compare function to be a good GC_VALUE
less compare function. This is used for hashing. Moved the functor over to rubyclasses to avoid bloat when GC_VALUE is not used. Updated std::map test to check for equivalence. Updated CHANGES.current a tad to move the STL stuff as last and merge two feature updates as one. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9740 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
8564ff90c0
commit
a6fa331dae
5 changed files with 161 additions and 73 deletions
|
|
@ -125,6 +125,48 @@ namespace swig {
|
|||
|
||||
typedef GC_VALUE LANGUAGE_OBJ;
|
||||
}
|
||||
|
||||
|
||||
namespace std {
|
||||
template <>
|
||||
struct less< swig::GC_VALUE >: public binary_function< swig::GC_VALUE,
|
||||
swig::GC_VALUE, bool >
|
||||
{
|
||||
static ID cmp_id;
|
||||
static ID hash_id;
|
||||
|
||||
bool
|
||||
operator()( const swig::GC_VALUE& v, const swig::GC_VALUE& w ) const
|
||||
{
|
||||
// SWIG_RUBY_THREAD_BEGIN_BLOCK;
|
||||
|
||||
VALUE ret = Qnil;
|
||||
|
||||
// First, try to compare using the <=> operator if present
|
||||
if ( rb_respond_to( v, cmp_id ) == Qtrue )
|
||||
{
|
||||
ret = rb_funcall(VALUE(v), cmp_id, 1, VALUE(w));
|
||||
}
|
||||
|
||||
bool res;
|
||||
// If that fails, try to use the two object's hash function to compare.
|
||||
if ( ret == Qnil ) {
|
||||
VALUE a = rb_funcall( VALUE(v), hash_id, 0 );
|
||||
VALUE b = rb_funcall( VALUE(w), hash_id, 0 );
|
||||
res = a < b; // as shifted integers
|
||||
}
|
||||
else
|
||||
{
|
||||
res = NUM2INT( ret ) < 0;
|
||||
}
|
||||
// SWIG_RUBY_THREAD_END_BLOCK;
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
ID less< swig::GC_VALUE >::cmp_id = rb_intern("<=>");
|
||||
ID less< swig::GC_VALUE >::hash_id = rb_intern("hash");
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue