Bump for 4.0-15
[LibreOffice.git] / dbaccess / source / inc / registrationhelper.hxx
blob8670a9737bbd580d8c28c8e7f284d1ae9b095b39
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 ::rtl::OUString & _rComponentName,
28 ::cppu::ComponentInstantiation _pCreateFunction,
29 const ::com::sun::star::uno::Sequence< ::rtl::OUString > & _rServiceNames,
30 rtl_ModuleCount* _p
33 //==========================================================================
34 class OModuleRegistration
36 static ::com::sun::star::uno::Sequence< ::rtl::OUString >*
37 s_pImplementationNames;
38 static ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::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;
45 // no direct instantiation, only static members/methods
46 OModuleRegistration() { }
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
56 static void registerComponent(
57 const ::rtl::OUString& _rImplementationName,
58 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rServiceNames,
59 ::cppu::ComponentInstantiation _pCreateFunction,
60 FactoryInstantiation _pFactoryFunction);
62 /** revoke the registration for the specified component
63 @param _rImplementationName the implementation name of the component
65 static void revokeComponent(
66 const ::rtl::OUString& _rImplementationName);
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
73 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getComponentFactory(
74 const ::rtl::OUString& _rImplementationName,
75 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxServiceManager
79 //==========================================================================
80 template <class TYPE>
81 class OMultiInstanceAutoRegistration
83 public:
84 /** assumed that the template argument has the three methods<BR>
85 <code>static ::rtl::OUString getImplementationName_Static()</code><BR>
86 <code>static ::com::sun::star::uno::Sequence< ::rtl::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
94 OMultiInstanceAutoRegistration();
95 ~OMultiInstanceAutoRegistration();
98 template <class TYPE>
99 OMultiInstanceAutoRegistration<TYPE>::OMultiInstanceAutoRegistration()
101 OModuleRegistration::registerComponent(
102 TYPE::getImplementationName_Static(),
103 TYPE::getSupportedServiceNames_Static(),
104 TYPE::Create,
105 ::cppu::createSingleFactory
109 template <class TYPE>
110 OMultiInstanceAutoRegistration<TYPE>::~OMultiInstanceAutoRegistration()
112 OModuleRegistration::revokeComponent(TYPE::getImplementationName_Static());
115 //==========================================================================
116 template <class TYPE>
117 class OOneInstanceAutoRegistration
119 public:
120 /** provided that the template argument has three methods<BR>
121 <code>static ::rtl::OUString getImplementationName_Static()</code><BR>
122 <code>static ::com::sun::star::uno::Sequence< ::rtl::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
130 OOneInstanceAutoRegistration();
131 ~OOneInstanceAutoRegistration();
134 template <class TYPE>
135 OOneInstanceAutoRegistration<TYPE>::OOneInstanceAutoRegistration()
137 OModuleRegistration::registerComponent(
138 TYPE::getImplementationName_Static(),
139 TYPE::getSupportedServiceNames_Static(),
140 TYPE::Create,
141 ::cppu::createOneInstanceFactory
145 template <class TYPE>
146 OOneInstanceAutoRegistration<TYPE>::~OOneInstanceAutoRegistration()
148 OModuleRegistration::revokeComponent(TYPE::getImplementationName_Static());
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */