Re: hand wrapping cluttermm functions



Hi Ian,

I think that the only thing that's really wrong with your code is that
you should have take_copy = true in the call to Glib::wrap_auto(). You
create a new Glib::RefPtr object, but clutter_animator_set_key() does
not increase the reference count.

But the code is unnecessarily complex. You already know the C++ wrapper.
It's this, i.e. the pointer to the current C++ object. The code can be
simplified to
  Glib::RefPtr<Clutter::Animator> pWrapper =
    Glib::RefPtr<Clutter::Animator> (this);
or even
  Glib::RefPtr<Clutter::Animator> pWrapper(this);

I prefer the name pWrapper rather than wrapper, since it's actually a
pointer to the wrapper.

Unfortunately the Glib::RefPtr constructor does not have a take_copy
parameter. You have to add
  reference();
or, if you prefer,
  this->reference();
or
  pWrapper->reference();

Conversion between C++ enums and C enums shouldn't be a problem. In most
cases (perhaps all cases) there are no special conversion functions. But
a C++ enum should be identical to the corresponding C enum except for
the names of the declared enum constants (like Gtk::FOO instead of
GTK_FOO). If you need to explicitly convert, you can use a cast.

Kjell

sön 2011-09-11 klockan 23:02 +1200 skrev Ian Martin:
> Hi,
> How do I return a RefPtr to the object when hand- wrapping a function?  
> I'm pretty certain this is the wrong way to do it.
> 
> Alternatively, are there any hand-wrapped functions that return a RefPtr 
> (to the object being called from) in other libraries so I can see how 
> it's been done?
> 
> I also can't figure out how to convert a C++ enum to a C enum, although 
> does it matter in this context?  ( it's being passed in as a guint, so 
> presumably it should correlate?)
> 
> code(a modified cluttermm/clutter/src/animator.hg):
> 
> 
> template <class ValueType>
> Glib::RefPtr<Animator> Animator::set_key(const 
> Glib::RefPtr<Glib::Object>& object,
>                                  const Glib::ustring& property_name,
>                                  guint mode,
>                                  double progress,
>                                  const ValueType& value)
> {
>    ClutterAnimator* animator_ptr = this->gobj();
> 
>    Glib::Value<ValueType> property_value;
>    property_value.init(Glib::Value<ValueType>::value_type());
>    property_value.set(value);
> 
>    std::string prop_name = property_name;
> 
>    clutter_animator_set_key(animator_ptr,
>                          object->gobj(),
>                          prop_name.c_str(),
>                          mode,
>                          progress,
>                          property_value.gobj() );
> 
>    //returning a RefPtr.  Can't seem to just call wrap() therefore 
> copied the function.
>    Glib::RefPtr<Clutter::Animator> wrapper = 
> Glib::RefPtr<Clutter::Animator> (dynamic_cast<Clutter::Animator*> 
> (Glib::wrap_auto ((GObject*)(animator_ptr), false)) );
> 
>    return wrapper;
> }
> 
> Ian
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]