Demonstrates how to forward a RAII helper class across a wrapper that doesn't expose the definition of the wrapped class
In this example:
AsyncPanZoomController
is the wrapped classAPZSampler
is the wrapper classAutoApplyTestAttributesInternal
is the RAII helper classAutoApplyTestAttributes
is a wrapper for the RAII helper classAsyncCompositionManager.cpp
is the client code that doesn't have access to the definition ofAsyncPanZoomController
The key insights are:
AutoApplyTestAttributesInternal
cannot be nested insideAsyncPanZoomController
, because nested classes cannot be forward-declared, and we needAPZSampler.h
to only forward-declareAutoApplyTestAttributesInternal
.- The destructor of
AutoApplyTestAttributes
needs to be defined out of line. This ensures that the destructor ofunique_ptr<AutoApplyTestAttributesInternal>
, which requiresAutoApplyTestAttributesInternal
to be complete, is instantiated only inAPZSampler.cpp
and not inAsyncCompositionManager.cpp
. (This is also why we need the wrapperAutoApplyTestAttributes
in the first place, and can't just have the client code useunique_ptr<AutoApplyTestAttributesInternal>
directly; there would be no way to avoid the client code trying to instantiate the destructor ofunique_ptr<AutoApplyTestAttributesInternal>
inAsyncCompositionManager.cpp
.)