Great works Marcus<br><br>Being a heavy user of VTK, Qt and CTK ... vtkScopedPointer usage is consistent with what's done in Qt world. <br><br>It's concise and user/developer friendly ... it give a clear idea of what the goal is. The reference count will be decreased if the object get out of scope ...<br>

<br>Jc<br><br><div class="gmail_quote">On Mon, Jan 24, 2011 at 4:21 PM, Marcus D. Hanwell <span dir="ltr"><<a href="mailto:marcus.hanwell@kitware.com">marcus.hanwell@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

<div><div></div><div class="h5">On Mon, Jan 24, 2011 at 4:11 PM, tom fogal <<a href="mailto:tfogal@sci.utah.edu">tfogal@sci.utah.edu</a>> wrote:<br>
> "Marcus D. Hanwell" <<a href="mailto:marcus.hanwell@kitware.com">marcus.hanwell@kitware.com</a>> writes:<br>
>> On Mon, Jan 24, 2011 at 3:41 PM, tom fogal <<a href="mailto:tfogal@sci.utah.edu">tfogal@sci.utah.edu</a>> wrote:<br>
>> > "Marcus D. Hanwell" <<a href="mailto:marcus.hanwell@kitware.com">marcus.hanwell@kitware.com</a>> writes:<br>
>> >> Some of you may remember my dreams of a concise way of initializing<br>
>> >> VTK objects, that would go out of scope and be destroyed at the<br>
>> >> appropriate time. Inspired by the Qt scoped pointer, [. . .]<br>
>> >><br>
>> >> <a href="http://review.source.kitware.com/759" target="_blank">http://review.source.kitware.com/759</a><br>
>> ><br>
>> > scoped (and other) smart pointers were introduced with tr1, back in<br>
>> > 2003 IIRC. =A0Further boost has had this for quite some time:<br>
>> ><br>
>> > =A0<a href="http://www.boost.org/doc/libs/1_45_0/libs/smart_ptr/scoped_ptr.htm?ses=" target="_blank">http://www.boost.org/doc/libs/1_45_0/libs/smart_ptr/scoped_ptr.htm?ses=</a><br>
>> s=3D94fbb4fa5cfd2b2071c3be193acb355d<br>
>> ><br>
>> > I realize that vtk is a bit stuck because it has already shipped some<br>
>> > smart pointers, and thus probably must continue to do so for some time<br>
>> > due to backward compat requirements, but I'd discourage *extending*<br>
>> > the trend. =A0This is a painful interop problem, especially with larger<br>
>> > software systems -- there's probably some C++ platitude that states,<br>
>> > "Every library eventually evolves a smart pointer implementation."<br>
>> ><br>
>> > Or there is now, at least.<br>
>><br>
>> Would any of these scoped pointers actually work with VTK derived<br>
>> objects? We have private constructors, need to call the static New<br>
>> method,<br>
><br>
> The standard smart pointers accept the pointers; they do not know how<br>
> to allocate them.  So for example:<br>
><br>
>  std::tr1::shared_ptr<vtkDataset> ds =<br>
>    std::tr1::shared_ptr<vtkDataset>(vtkRectilinearGrid::New());<br>
<br>
</div></div>There is something to be said for nicer API, even at the expense of a<br>
little duplication IMHO.<br>
<div class="im">><br>
>> and the Delete method on destruction.<br>
><br>
> Yeah, they accept a function pointer for custom delete implementations<br>
> (the above line would actually fail w/o supplying the custom deleter,<br>
> IIRC).<br>
><br>
>> I also don't see VTK depending on TR1 features, or Boost for<br>
>> quite some time. The class is quite minimal, and I think it would<br>
>> complement the other two pointer classes that help to manage VTK<br>
>> derived objects.<br>
><br>
> Well, I think that's kind of my point.  As long as these things keep<br>
> getting added, they keep getting used, and the impetus for getting<br>
> a better long term solution is lost.  Furthermore, it makes it more<br>
> difficult to switch over when the appropriate time comes, because now<br>
> backwards compatibility is suddenly an issue.<br>
><br>
</div>My counterargument would be for concise, specialized API where it<br>
helps. I think this is one of those cases, although perhaps the naming<br>
is the contentious issue. Having to pass in the construction and<br>
custom deleter really makes the initialization even more verbose than<br>
what we have.<br>
<br>
As with many toolkits, we do not have the luxury of requiring TR1 or<br>
C++0x anytime soon. Even if we did in my opinion supporting a concise<br>
way of constructing scoped objects is important for code readability.<br>
<font color="#888888"><br>
Marcus<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtk-developers" target="_blank">http://www.vtk.org/mailman/listinfo/vtk-developers</a><br>
<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Phone: 1-518-836-2174<br>Ext: 304<br>