Difference between revisions of "Development/Cpp/Helper/ServiceDecl"
m (→Example) |
m (→Example) |
||
Line 23: | Line 23: | ||
namespace sdecl = comphelper::service_decl; | namespace sdecl = comphelper::service_decl; | ||
const sdecl::ServiceDecl serviceDecl2( | const sdecl::ServiceDecl serviceDecl2( | ||
− | + | sdecl::class_<SomeUNOInterface>(), | |
− | + | "com.sun.star.comp.stuff.MyImplName1", | |
− | + | "com.sun.star.stuff.MyServiceName1" ); | |
const sdecl::ServiceDecl serviceDecl2( | const sdecl::ServiceDecl serviceDecl2( | ||
− | + | sdecl::class_<SomeOtherUNOInterface>(), | |
− | + | "com.sun.star.comp.stuff.MyImplName2", | |
− | + | "com.sun.star.stuff.MyServiceName2" ); | |
// The C shared lib entry points | // The C shared lib entry points |
Revision as of 10:36, 30 November 2007
Class Name | Purpose | Location |
---|---|---|
ServiceDecl | is a helper class for providing the UNO component service factory boilerplate (the three exported C functions and associated code) | comphelper/servicedecl.hxx
|
Contents
Description
A ServiceDecl provides the service factory entry points for a UNO component.
Interface
Example
The following example provides two services to the UNO runtime.
[cpp]
- include <comphelper/servicedecl.hxx>
class Foo : public SomeUNOInterface {...}; class Bar : public SomeOtherUNOInterface {...};
namespace sdecl = comphelper::service_decl; const sdecl::ServiceDecl serviceDecl2(
sdecl::class_<SomeUNOInterface>(), "com.sun.star.comp.stuff.MyImplName1", "com.sun.star.stuff.MyServiceName1" );
const sdecl::ServiceDecl serviceDecl2(
sdecl::class_<SomeOtherUNOInterface>(), "com.sun.star.comp.stuff.MyImplName2", "com.sun.star.stuff.MyServiceName2" );
// The C shared lib entry points COMPHELPER_SERVICEDECL_EXPORTS2(serviceDecl1,serviceDecl2)
This is the perfect world example. In real world, we still have ports using gcc3.3 or less with that old parser bug. To be portable, the code should rather look like this (only slightly more obfuscated):
[cpp]
- include <comphelper/servicedecl.hxx>
class Foo : public SomeUNOInterface {...}; class Bar : public SomeOtherUNOInterface {...};
namespace sdecl = comphelper::service_decl;
- if defined (__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ <= 3)
sdecl::class_<SomeUNOInterface> serviceImpl; const sdecl::ServiceDecl serviceDecl1( serviceImpl,
- else
const sdecl::ServiceDecl serviceDecl2( sdecl::class_<SomeUNOInterface>(),
- endif
"com.sun.star.comp.stuff.MyImplName1", "com.sun.star.stuff.MyServiceName1" );
- if defined (__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ <= 3)
sdecl::class_<SomeOtherUNOInterface> serviceImpl; const sdecl::ServiceDecl serviceDecl2( serviceImpl,
- else
const sdecl::ServiceDecl serviceDecl2( sdecl::class_<SomeOtherUNOInterface>(),
- endif
"com.sun.star.comp.stuff.MyImplName2", "com.sun.star.stuff.MyServiceName2" );
// The C shared lib entry points COMPHELPER_SERVICEDECL_EXPORTS2(serviceDecl1,serviceDecl2)