Development/Cpp/Helper/ServiceDecl

From Apache OpenOffice Wiki
< Development‎ | Cpp‎ | Helper
Revision as of 10:36, 30 November 2007 by Thorsten (Talk | contribs)

Jump to: navigation, search
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


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]

  1. 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]

  1. include <comphelper/servicedecl.hxx>

class Foo : public SomeUNOInterface {...}; class Bar : public SomeOtherUNOInterface {...};

namespace sdecl = comphelper::service_decl;

  1. if defined (__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ <= 3)
sdecl::class_<SomeUNOInterface> serviceImpl;
const sdecl::ServiceDecl serviceDecl1(
    serviceImpl,
  1. else
const sdecl::ServiceDecl serviceDecl2(
    sdecl::class_<SomeUNOInterface>(),
  1. endif
    "com.sun.star.comp.stuff.MyImplName1",
    "com.sun.star.stuff.MyServiceName1" );
  1. if defined (__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ <= 3)
sdecl::class_<SomeOtherUNOInterface> serviceImpl;
const sdecl::ServiceDecl serviceDecl2(
    serviceImpl,
  1. else
const sdecl::ServiceDecl serviceDecl2(
    sdecl::class_<SomeOtherUNOInterface>(),
  1. endif
    "com.sun.star.comp.stuff.MyImplName2",
    "com.sun.star.stuff.MyServiceName2" );

// The C shared lib entry points COMPHELPER_SERVICEDECL_EXPORTS2(serviceDecl1,serviceDecl2)

Personal tools