[cairo] cairomm RefPtr

Larry Lewis lewislp at yahoo.com
Sat Dec 1 11:49:13 PST 2007


--- Bertram Felgenhauer <bertram.felgenhauer at googlemail.com> wrote:

> Larry Lewis wrote:
> > Is there a specific reason why cairomm's RefPtr implementation
> (along
> > with glibmm) does not provide the T_CppObject& operator*() and
> > T_CppObject* get() methods?  Both reference-counting pointer
> > implementations I use on a regular basis (boost::shared_ptr and
> > Poco::SharedPtr) provide this functionality, which is extremely
> > useful for passing the object by reference or directly accessing
> > the raw pointer.  It's unfortunate to have to resort to the ugly
> > operator->() syntax to access the pointer.
> 
> Woops sorry, I misread that, apparently you want the C++ object, not
> the C one. But why would you need the pointer to the C++ object? It
> only contains is a pointer.
> 
> RefPtr is really designed to be used with wrapper objects like these,
> not for arbitrary C++ objects.
> 

I agree that they're not intended for use as general-purpose
reference-counting pointers. It would be nice, however, to allow
developers to write API that accepts types such as Cairo::Surface and
Cairo::Context by reference. Using const Cairo::RefPtr<Cairo::Context>
causes a copy while const Cairo::RefPtr<Cairo::Context>& adds another
layer of indirection. Both force the function writer to perform a NULL
check, which is contrary to my (and others' I suppose) convention of
passing by reference to enforce non-NULL parameters. To get a simple
reference, syntax such as *context.operator->() is required.

> (Btw, that's all my opinion, I'm not speaking for the cairomm
> developers.)
> 
> Bertram

Just a minor gripe. Thanks for the great library.

Larry


More information about the cairo mailing list