LCOV - code coverage report
Current view: top level - dbaccess/source/inc - registrationhelper.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 7 7 100.0 %
Date: 2014-11-03 Functions: 66 66 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef _REGISTRATIONHELPER_INCLUDED_INDIRECTLY_
      21             : #error "don't include this file directly! use dbu_reghelper.hxx instead!"
      22             : #endif
      23             : 
      24             : typedef ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > (SAL_CALL *FactoryInstantiation)
      25             :         (
      26             :             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rServiceManager,
      27             :             const OUString & _rComponentName,
      28             :             ::cppu::ComponentInstantiation _pCreateFunction,
      29             :             const ::com::sun::star::uno::Sequence< OUString > & _rServiceNames,
      30             :             rtl_ModuleCount*
      31             :         );
      32             : 
      33             : class OModuleRegistration
      34             : {
      35             :     static  ::com::sun::star::uno::Sequence< OUString >*
      36             :         s_pImplementationNames;
      37             :     static  ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< OUString > >*
      38             :         s_pSupportedServices;
      39             :     static  ::com::sun::star::uno::Sequence< sal_Int64 >*
      40             :         s_pCreationFunctionPointers;
      41             :     static  ::com::sun::star::uno::Sequence< sal_Int64 >*
      42             :         s_pFactoryFunctionPointers;
      43             : 
      44             :     // no direct instantiation, only static members/methods
      45             :     OModuleRegistration() { }
      46             : 
      47             : public:
      48             :     /** register a component implementing a service with the given data.
      49             :         @param      _rImplementationName        the implementation name of the component
      50             :         @param      _rServiceNames              the services the component supports
      51             :         @param      _pCreateFunction            a function for creating an instance of the component
      52             :         @param      _pFactoryFunction           a function for creating a factory for that component
      53             :         @see revokeComponent
      54             :     */
      55             :     static void registerComponent(
      56             :         const OUString& _rImplementationName,
      57             :         const ::com::sun::star::uno::Sequence< OUString >& _rServiceNames,
      58             :         ::cppu::ComponentInstantiation _pCreateFunction,
      59             :         FactoryInstantiation _pFactoryFunction);
      60             : 
      61             :     /** revoke the registration for the specified component
      62             :         @param      _rImplementationName        the implementation name of the component
      63             :     */
      64             :     static void revokeComponent(
      65             :         const OUString& _rImplementationName);
      66             : 
      67             :     /** creates a Factory for the component with the given implementation name. Usually used from within component_getFactory.
      68             :         @param      _rxServiceManager       a pointer to an XMultiServiceFactory interface as got in component_getFactory
      69             :         @param      _pImplementationName    the implementation name of the component
      70             :         @return                             the XInterface access to a factory for the component
      71             :     */
      72             :     static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getComponentFactory(
      73             :         const OUString& _rImplementationName,
      74             :         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxServiceManager
      75             :         );
      76             : };
      77             : 
      78             : template <class TYPE>
      79             : class OMultiInstanceAutoRegistration
      80             : {
      81             : public:
      82             :     /** assumed that the template argument has the three methods<BR>
      83             :         <code>static OUString getImplementationName_Static()</code><BR>
      84             :         <code>static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_Static()</code><BR>
      85             :         and<BR>
      86             :         <code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
      87             :             Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code><BR>
      88             :         the instantiation of this object will automatically register the class via <code>OModuleRegistration::registerComponent</code>.
      89             :         The factory creation function used is <code>::cppu::createSingleFactory</code>.<BR>
      90             :         @see OOneInstanceAutoRegistration
      91             :     */
      92             :     OMultiInstanceAutoRegistration();
      93             :     ~OMultiInstanceAutoRegistration();
      94             : };
      95             : 
      96             : template <class TYPE>
      97         816 : OMultiInstanceAutoRegistration<TYPE>::OMultiInstanceAutoRegistration()
      98             : {
      99         816 :     OModuleRegistration::registerComponent(
     100             :         TYPE::getImplementationName_Static(),
     101             :         TYPE::getSupportedServiceNames_Static(),
     102             :         TYPE::Create,
     103             :         ::cppu::createSingleFactory
     104        1632 :         );
     105         816 : }
     106             : 
     107             : template <class TYPE>
     108         816 : OMultiInstanceAutoRegistration<TYPE>::~OMultiInstanceAutoRegistration()
     109             : {
     110         816 :     OModuleRegistration::revokeComponent(TYPE::getImplementationName_Static());
     111         816 : }
     112             : 
     113             : template <class TYPE>
     114             : class OOneInstanceAutoRegistration
     115             : {
     116             : public:
     117             :     /** provided that the template argument has three methods<BR>
     118             :         <code>static OUString getImplementationName_Static()</code><BR>
     119             :         <code>static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_Static()</code><BR>
     120             :         and<BR>
     121             :         <code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
     122             :             Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code><BR>
     123             :         the instantiation of this object will automatically register the class via <code>OModuleRegistration::registerComponent</code>.
     124             :         The factory creation function used is <code>::cppu::createSingleFactory</code>.<BR>
     125             :         @see OMultiInstanceAutoRegistration
     126             :     */
     127             :     OOneInstanceAutoRegistration();
     128             :     ~OOneInstanceAutoRegistration();
     129             : };
     130             : 
     131             : template <class TYPE>
     132             : OOneInstanceAutoRegistration<TYPE>::OOneInstanceAutoRegistration()
     133             : {
     134             :     OModuleRegistration::registerComponent(
     135             :         TYPE::getImplementationName_Static(),
     136             :         TYPE::getSupportedServiceNames_Static(),
     137             :         TYPE::Create,
     138             :         ::cppu::createOneInstanceFactory
     139             :         );
     140             : }
     141             : 
     142             : template <class TYPE>
     143             : OOneInstanceAutoRegistration<TYPE>::~OOneInstanceAutoRegistration()
     144             : {
     145             :     OModuleRegistration::revokeComponent(TYPE::getImplementationName_Static());
     146             : }
     147             : 
     148             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10