LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/inc - registrationhelper.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 7 100.0 %
Date: 2013-07-09 Functions: 64 64 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             : //==========================================================================
      34             : class OModuleRegistration
      35             : {
      36             :     static  ::com::sun::star::uno::Sequence< OUString >*
      37             :         s_pImplementationNames;
      38             :     static  ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< OUString > >*
      39             :         s_pSupportedServices;
      40             :     static  ::com::sun::star::uno::Sequence< sal_Int64 >*
      41             :         s_pCreationFunctionPointers;
      42             :     static  ::com::sun::star::uno::Sequence< sal_Int64 >*
      43             :         s_pFactoryFunctionPointers;
      44             : 
      45             :     // no direct instantiation, only static members/methods
      46             :     OModuleRegistration() { }
      47             : 
      48             : public:
      49             :     /** register a component implementing a service with the given data.
      50             :         @param      _rImplementationName        the implementation name of the component
      51             :         @param      _rServiceNames              the services the component supports
      52             :         @param      _pCreateFunction            a function for creating an instance of the component
      53             :         @param      _pFactoryFunction           a function for creating a factory for that component
      54             :         @see revokeComponent
      55             :     */
      56             :     static void registerComponent(
      57             :         const OUString& _rImplementationName,
      58             :         const ::com::sun::star::uno::Sequence< OUString >& _rServiceNames,
      59             :         ::cppu::ComponentInstantiation _pCreateFunction,
      60             :         FactoryInstantiation _pFactoryFunction);
      61             : 
      62             :     /** revoke the registration for the specified component
      63             :         @param      _rImplementationName        the implementation name of the component
      64             :     */
      65             :     static void revokeComponent(
      66             :         const OUString& _rImplementationName);
      67             : 
      68             :     /** creates a Factory for the component with the given implementation name. Usually used from within component_getFactory.
      69             :         @param      _rxServiceManager       a pointer to an XMultiServiceFactory interface as got in component_getFactory
      70             :         @param      _pImplementationName    the implementation name of the component
      71             :         @return                             the XInterface access to a factory for the component
      72             :     */
      73             :     static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getComponentFactory(
      74             :         const OUString& _rImplementationName,
      75             :         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxServiceManager
      76             :         );
      77             : };
      78             : 
      79             : //==========================================================================
      80             : template <class TYPE>
      81             : class OMultiInstanceAutoRegistration
      82             : {
      83             : public:
      84             :     /** assumed that the template argument has the three methods<BR>
      85             :         <code>static OUString getImplementationName_Static()</code><BR>
      86             :         <code>static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_Static()</code><BR>
      87             :         and<BR>
      88             :         <code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
      89             :             Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code><BR>
      90             :         the instantiation of this object will automatically register the class via <code>OModuleRegistration::registerComponent</code>.
      91             :         The factory creation function used is <code>::cppu::createSingleFactory</code>.<BR>
      92             :         @see OOneInstanceAutoRegistration
      93             :     */
      94             :     OMultiInstanceAutoRegistration();
      95             :     ~OMultiInstanceAutoRegistration();
      96             : };
      97             : 
      98             : template <class TYPE>
      99         140 : OMultiInstanceAutoRegistration<TYPE>::OMultiInstanceAutoRegistration()
     100             : {
     101         140 :     OModuleRegistration::registerComponent(
     102             :         TYPE::getImplementationName_Static(),
     103             :         TYPE::getSupportedServiceNames_Static(),
     104             :         TYPE::Create,
     105             :         ::cppu::createSingleFactory
     106         280 :         );
     107         140 : }
     108             : 
     109             : template <class TYPE>
     110         140 : OMultiInstanceAutoRegistration<TYPE>::~OMultiInstanceAutoRegistration()
     111             : {
     112         140 :     OModuleRegistration::revokeComponent(TYPE::getImplementationName_Static());
     113         140 : }
     114             : 
     115             : //==========================================================================
     116             : template <class TYPE>
     117             : class OOneInstanceAutoRegistration
     118             : {
     119             : public:
     120             :     /** provided that the template argument has three methods<BR>
     121             :         <code>static OUString getImplementationName_Static()</code><BR>
     122             :         <code>static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_Static()</code><BR>
     123             :         and<BR>
     124             :         <code>static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
     125             :             Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&)</code><BR>
     126             :         the instantiation of this object will automatically register the class via <code>OModuleRegistration::registerComponent</code>.
     127             :         The factory creation function used is <code>::cppu::createSingleFactory</code>.<BR>
     128             :         @see OMultiInstanceAutoRegistration
     129             :     */
     130             :     OOneInstanceAutoRegistration();
     131             :     ~OOneInstanceAutoRegistration();
     132             : };
     133             : 
     134             : template <class TYPE>
     135             : OOneInstanceAutoRegistration<TYPE>::OOneInstanceAutoRegistration()
     136             : {
     137             :     OModuleRegistration::registerComponent(
     138             :         TYPE::getImplementationName_Static(),
     139             :         TYPE::getSupportedServiceNames_Static(),
     140             :         TYPE::Create,
     141             :         ::cppu::createOneInstanceFactory
     142             :         );
     143             : }
     144             : 
     145             : template <class TYPE>
     146             : OOneInstanceAutoRegistration<TYPE>::~OOneInstanceAutoRegistration()
     147             : {
     148             :     OModuleRegistration::revokeComponent(TYPE::getImplementationName_Static());
     149             : }
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10