Uno/Cpp/Snippet/Function accepting any kind of parameters
From Apache OpenOffice Wiki
Callee:
// This function is environment specialized on "c++<purpose>*".
void takeAnyObject(uno::Reference<...> const & rObj) {
// We need to remember the callers environment, to "map-out/in"
// the parameters and return values properly.
uno::Environment outerEnv(uno::getCurrent());
// We now activate (enter) the "c++:unsafe" environment.
// Note: Any other environment suiteable for "MyUnsafeObject" would work as well.
cppu::EnvGuard unsafeGuard(uno::Environment(rtl::OUString(RTL_CONSTASCII_PARAM("c++:unsafe"))));
// We "mapIn" the parameter.
uno::Reference<...> unsafeEnv_Obj.set(cppu::mapIn(rObj, outerEnv), SAL_NO_ACQUIRE);
// MyUnsafeObj has a C++ [[Uno/Term/Object Binary Interface|OBI]] and is thread-unsafe
unsafeEnv_Obj->set(new MyUnsafeObject());
}
Caller:
...
{
// Whatever "c++<purpose>*" we enter, the parameter passed to "takeAnyObject" will
// always match.
cppu::EnvGuard cppDebug_Guard(rtl::OUString(RTL_CONSTASCII_PARAM("c++:debug")));
uno::Reference<...> obj(...);
takeAnyObject(obj);
}
...