Add support for SmartIF templated with a concrete type
This is another attempt at #344 (closed).
Instead of addressing the specific case of ServiceHandle, I operated at a lower level, so that SmartIF can work either via queryInterface or via dynamic_cast. Ideally, we should replace every direct use of queryInterface with IInterface::cast and ensure that all custom implementations of queryInterface are replaced with custom implementations of IInterface::i_cast.
Because I changed ServiceHandle to rely on SmartIF, I broke ServiceHandle<const T>
, so I decided to fix #20 (closed) here.
Changes:
- improved and extended IInterface::cast to work either via i_cast or dynamic_cast
- with a fallback on queryInterface while we replace queryInterface with i_cast
- the fallback required a hepler method to decrease the refcount without deleting the object
- modified SmartIF to leverage on IInterface::cast
- modified ServiceHandle to rely on SmartIF
- modified Gaudi::Cast to use IInterface::cast (for consistency)
- added unit tests for SmartIF
- fixed support for SmartIF<const T> (#20 (closed))
- changed the default implementation of
IInterface::release
to avoid possible race conditions
As a bonus, I made SmartIF constructible from unique_ptr, with the idea of later on deprecate creation from bare pointers.
Closes #344 (closed), #20 (closed)
Edited by Marco Clemencic