Improved GC_VALUE so it gets printed nicely

and works properly with std::pair.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9725 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Gonzalo Garramuno 2007-04-30 19:26:18 +00:00
commit 8ea7856ef3

View file

@ -34,17 +34,27 @@
*/ */
namespace swig { namespace swig {
%ignore GC_VALUE; // we don't ignore it, so it will get printed nicely with inspect
struct GC_VALUE {}; //%ignore GC_VALUE;
// %apply VALUE {GC_VALUE}; struct GC_VALUE {
// %apply VALUE const& {GC_VALUE const&}; VALUE inspect() const;
VALUE to_s() const;
};
%apply VALUE {GC_VALUE};
%apply VALUE const& {GC_VALUE const&};
/* For input */
%typemap(in,noblock=1) GC_VALUE* (GC_VALUE r) {
r = $input; $1 = &r;
}
/* For output */ /* For output */
%typemap(out,noblock=1) GC_VALUE { %typemap(out,noblock=1) GC_VALUE {
$result = (VALUE)$1; $result = (VALUE)$1;
} }
%typemap(out,noblock=1) GC_VALUE const & { %typemap(out,noblock=1) GC_VALUE*, GC_VALUE const & {
$result = (VALUE)*$1; $result = (VALUE)*$1;
} }
@ -61,6 +71,7 @@ namespace swig {
public: public:
GC_VALUE() :_obj( Qnil ) GC_VALUE() :_obj( Qnil )
{ {
GC_register();
} }
GC_VALUE(const GC_VALUE& item) : _obj(item._obj) GC_VALUE(const GC_VALUE& item) : _obj(item._obj)
@ -73,39 +84,48 @@ namespace swig {
GC_register(); GC_register();
} }
GC_VALUE & operator=(const GC_VALUE& item) ~GC_VALUE()
{ {
GC_unregister(); GC_unregister();
}
GC_VALUE & operator=(const GC_VALUE& item)
{
_obj = item._obj; _obj = item._obj;
GC_register();
return *this; return *this;
} }
void GC_register() void GC_register()
{ {
if ( _obj != Qnil )
rb_gc_register_address( &_obj ); rb_gc_register_address( &_obj );
} }
void GC_unregister() void GC_unregister()
{ {
if ( _obj != Qnil )
rb_gc_unregister_address( &_obj ); rb_gc_unregister_address( &_obj );
} }
~GC_VALUE()
{
GC_unregister();
}
operator VALUE() const operator VALUE() const
{ {
return _obj; return _obj;
} }
VALUE inspect() const
{
return rb_inspect(_obj);
}
VALUE to_s() const
{
return rb_inspect(_obj);
}
}; };
typedef GC_VALUE LANGUAGE_OBJ;
} }
%} %}
#endif #endif