On Thu, Feb 9, 2012 at 12:55 PM, Dirk Thomas <dthomas@willowgarage.com> wrote:
That sounds like a very reasonable use case.While I like boost::shared_ptr, it is not always possible to use it nicely.
In rviz I have plugin classes which are subclasses of QWidget (from Qt GUI library). These objects are automatically deleted by Qt when their parent widgets are deleted. I can be notified of their
deletion by Qt, and call an "unload" or "decrement-reference-count" function, but it is not easy to use these QWidget pointers inside boost::shared_ptr without getting double-deletion crashes.
Automatically deleting and unloading is a nice feature but might not always be desired.
Having the option to get a raw pointer (as before) and take care of garbaging stuff manually would be great.
I propose the following names to make clear what the difference is (of course with a more detailed doc-string):pluginlib::ClassLoader could have two interfaces, one which gives a shared_ptr and manages the reference count for the library itself, and another which gives a raw pointer and increments the ref
count and also has a decrement-ref-count function.
boost::shared_ptr<T> getManagedInstance(const std::string& lookup_name)
T* getInstance(const std::string& lookup_name)