c++-sig@python.org
[Top] [All Lists]

[C++-sig] Little question about ptr()

Subject: [C++-sig] Little question about ptr()
From: Eric Jardim
Date: Thu, 15 Sep 2005 09:56:53 -0300
Just a quick one,

Supposing I have exposed a non-copyable class "Widget", and somewhere in the wrapper class declarations, I have:

struct Widget_Wrapper, wrapper<Widget> {
   ... 
   virtual bool
   mouseClicked(Widget* w) {
      if(override o = this->get_override("mouseClicked")
         return o( ptr(w) ); // <- look at this point
      else
         return this->Widget::mouseClicked(w);
   }
   ...
};

I cannot pass "w" directly because "Widget*" is not registered to be passed by-value (but Widget is), so I must use "ptr()". That's ok, and is working fine, but I don't think it is very explicit in the docs. The "ptr" docs just say it is usefull to pass "expensive" objects. I think that "ptr()" is necessary when passing any unregistered pointer types. Copyable objects may be an exception.

I just want to know if this is the "right" approach, because I think that Pyste, for example, don't handle this. I know that are some other possibilites like defining a "implicitly_convertible<Widget*, object>()", but I must somewhere define it in the class wrapper first. I am dealing with a lot of classes that may be passes as pointer.

I, instead, use a different approach using a metafunction to find if it is a pointer or not, plus some macros to help my job:
http://svn.berlios.de/viewcvs/python-qt4/trunk/PythonQt/Wrapper.h?view=markup

I just want to know if using "ptr()" is the correct approach in this case, or if I am doing "overwork".

Thanks,

[Eric Jardim]
_______________________________________________
C++-sig mailing list
C++-sig@xxxxxxxxxx
http://mail.python.org/mailman/listinfo/c++-sig
<Prev in Thread] Current Thread [Next in Thread>
  • [C++-sig] Little question about ptr(), Eric Jardim <=