bump product version to 5.0.4.1
[LibreOffice.git] / dbaccess / source / inc / registrationhelper.hxx
blobcef8c004fe5e4ba670db586ccea531141fec7085
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _REGISTRATIONHELPER_INCLUDED_INDIRECTLY_
21 #error "don't include this file directly! use dbu_reghelper.hxx instead!"
22 #endif
24 typedef ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > (SAL_CALL *FactoryInstantiation)
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*
33 class OModuleRegistration
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;
44 // no direct instantiation, only static members/methods
45 OModuleRegistration() { }
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
55 static void registerComponent(
56 const OUString& _rImplementationName,
57 const ::com::sun::star::uno::Sequence< OUString >& _rServiceNames,
58 ::cppu::ComponentInstantiation _pCreateFunction,
59 FactoryInstantiation _pFactoryFunction);
61 /** revoke the registration for the specified component
62 @param _rImplementationName the implementation name of the component
64 static void revokeComponent(
65 const OUString& _rImplementationName);
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
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
78 template <class TYPE>
79 class OMultiInstanceAutoRegistration
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
92 OMultiInstanceAutoRegistration();
93 ~OMultiInstanceAutoRegistration();
96 template <class TYPE>
97 OMultiInstanceAutoRegistration<TYPE>::OMultiInstanceAutoRegistration()
99 OModuleRegistration::registerComponent(
100 TYPE::getImplementationName_Static(),
101 TYPE::getSupportedServiceNames_Static(),
102 TYPE::Create,
103 ::cppu::createSingleFactory
107 template <class TYPE>
108 OMultiInstanceAutoRegistration<TYPE>::~OMultiInstanceAutoRegistration()
110 OModuleRegistration::revokeComponent(TYPE::getImplementationName_Static());
113 template <class TYPE>
114 class OOneInstanceAutoRegistration
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
127 OOneInstanceAutoRegistration();
128 ~OOneInstanceAutoRegistration();
131 template <class TYPE>
132 OOneInstanceAutoRegistration<TYPE>::OOneInstanceAutoRegistration()
134 OModuleRegistration::registerComponent(
135 TYPE::getImplementationName_Static(),
136 TYPE::getSupportedServiceNames_Static(),
137 TYPE::Create,
138 ::cppu::createOneInstanceFactory
142 template <class TYPE>
143 OOneInstanceAutoRegistration<TYPE>::~OOneInstanceAutoRegistration()
145 OModuleRegistration::revokeComponent(TYPE::getImplementationName_Static());
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */