Difference between revisions of "Uno/Cpp/Snippet/Function accepting any kind of parameters"

From Apache OpenOffice Wiki
< Uno‎ | Cpp
Jump to: navigation, search
 
m (Splitted categories.)
Line 31: Line 31:
 
}
 
}
 
...
 
...
</code><noinclude>[[Category:Uno:Cpp:Snippet]]</noinclude>
+
</code><noinclude>[[Category:Cpp]][[Category:Snippet]][[Category:Uno]]</noinclude>

Revision as of 08:33, 29 November 2006

Callee: [cpp] // 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++ OBI and is thread-unsafe
 unsafeEnv_Obj->set(new MyUnsafeObject());

}

Caller: [cpp] ... {

 // 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);

} ...

Personal tools