xref: /trunk/main/chart2/source/inc/ServiceMacros.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1*de7b3f82SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*de7b3f82SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*de7b3f82SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*de7b3f82SAndrew Rist  * distributed with this work for additional information
6*de7b3f82SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*de7b3f82SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*de7b3f82SAndrew Rist  * "License"); you may not use this file except in compliance
9*de7b3f82SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*de7b3f82SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*de7b3f82SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*de7b3f82SAndrew Rist  * software distributed under the License is distributed on an
15*de7b3f82SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*de7b3f82SAndrew Rist  * KIND, either express or implied.  See the License for the
17*de7b3f82SAndrew Rist  * specific language governing permissions and limitations
18*de7b3f82SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*de7b3f82SAndrew Rist  *************************************************************/
21*de7b3f82SAndrew Rist 
22*de7b3f82SAndrew Rist 
23cdf0e10cSrcweir #ifndef _APPHELPER_SERVICEMACROS_HXX
24cdf0e10cSrcweir #define _APPHELPER_SERVICEMACROS_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir /*
27cdf0e10cSrcweir to use these macros the supported services and the implementation name needs to be static
28cdf0e10cSrcweir especially you need to implement (declaration is contained in macro already):
29cdf0e10cSrcweir 
30cdf0e10cSrcweir static com::sun::star::uno::Sequence< rtl::OUString >
31cdf0e10cSrcweir     Class::getSupportedServiceNames_Static();
32cdf0e10cSrcweir */
33cdf0e10cSrcweir 
34cdf0e10cSrcweir //=========================================================================
35cdf0e10cSrcweir //
36cdf0e10cSrcweir // XServiceInfo decl
37cdf0e10cSrcweir //
38cdf0e10cSrcweir //=========================================================================
39cdf0e10cSrcweir namespace apphelper
40cdf0e10cSrcweir {
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #define APPHELPER_XSERVICEINFO_DECL()                                                   \
43cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL                                        \
44cdf0e10cSrcweir         getImplementationName()                                             \
45cdf0e10cSrcweir             throw( ::com::sun::star::uno::RuntimeException );               \
46cdf0e10cSrcweir     virtual sal_Bool SAL_CALL                                               \
47cdf0e10cSrcweir         supportsService( const ::rtl::OUString& ServiceName )               \
48cdf0e10cSrcweir             throw( ::com::sun::star::uno::RuntimeException );               \
49cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL     \
50cdf0e10cSrcweir         getSupportedServiceNames()                                          \
51cdf0e10cSrcweir             throw( ::com::sun::star::uno::RuntimeException );               \
52cdf0e10cSrcweir                                                                             \
53cdf0e10cSrcweir     static ::rtl::OUString getImplementationName_Static();                  \
54cdf0e10cSrcweir     static ::com::sun::star::uno::Sequence< ::rtl::OUString >               \
55cdf0e10cSrcweir         getSupportedServiceNames_Static();
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //=========================================================================
58cdf0e10cSrcweir //
59cdf0e10cSrcweir // XServiceInfo impl
60cdf0e10cSrcweir //
61cdf0e10cSrcweir //=========================================================================
62cdf0e10cSrcweir 
63cdf0e10cSrcweir #define APPHELPER_XSERVICEINFO_IMPL( Class, ImplName )                              \
64cdf0e10cSrcweir ::rtl::OUString SAL_CALL Class::getImplementationName()                     \
65cdf0e10cSrcweir     throw( ::com::sun::star::uno::RuntimeException )                        \
66cdf0e10cSrcweir {                                                                           \
67cdf0e10cSrcweir     return getImplementationName_Static();                                  \
68cdf0e10cSrcweir }                                                                           \
69cdf0e10cSrcweir                                                                             \
70cdf0e10cSrcweir ::rtl::OUString Class::getImplementationName_Static()                       \
71cdf0e10cSrcweir {                                                                           \
72cdf0e10cSrcweir     return ImplName;                                                        \
73cdf0e10cSrcweir }                                                                           \
74cdf0e10cSrcweir                                                                             \
75cdf0e10cSrcweir sal_Bool SAL_CALL                                                           \
76cdf0e10cSrcweir Class::supportsService( const ::rtl::OUString& ServiceName )                \
77cdf0e10cSrcweir     throw( ::com::sun::star::uno::RuntimeException )                        \
78cdf0e10cSrcweir {                                                                           \
79cdf0e10cSrcweir     ::com::sun::star::uno::Sequence< ::rtl::OUString > aSNL =               \
80cdf0e10cSrcweir                                         getSupportedServiceNames();         \
81cdf0e10cSrcweir     const ::rtl::OUString* pArray = aSNL.getArray();                        \
82cdf0e10cSrcweir     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )                       \
83cdf0e10cSrcweir     {                                                                       \
84cdf0e10cSrcweir         if( pArray[ i ] == ServiceName )                                    \
85cdf0e10cSrcweir             return sal_True;                                                \
86cdf0e10cSrcweir     }                                                                       \
87cdf0e10cSrcweir                                                                             \
88cdf0e10cSrcweir     return sal_False;                                                       \
89cdf0e10cSrcweir }                                                                           \
90cdf0e10cSrcweir                                                                             \
91cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL                 \
92cdf0e10cSrcweir Class::getSupportedServiceNames()                                           \
93cdf0e10cSrcweir     throw( ::com::sun::star::uno::RuntimeException )                        \
94cdf0e10cSrcweir {                                                                           \
95cdf0e10cSrcweir     return getSupportedServiceNames_Static();                               \
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir //=========================================================================
99cdf0e10cSrcweir //
100cdf0e10cSrcweir // Service factory helper decl+impl
101cdf0e10cSrcweir //
102cdf0e10cSrcweir //to use this macro you need to provide a constructor:
103cdf0e10cSrcweir //class( Reference< XComponentContext > const & xContext )
104cdf0e10cSrcweir //and implement OWeakObject
105cdf0e10cSrcweir //=========================================================================
106cdf0e10cSrcweir 
107cdf0e10cSrcweir #define APPHELPER_SERVICE_FACTORY_HELPER(Class)                                     \
108cdf0e10cSrcweir static ::com::sun::star::uno::Reference<                                    \
109cdf0e10cSrcweir                             ::com::sun::star::uno::XInterface > SAL_CALL    \
110cdf0e10cSrcweir     create( ::com::sun::star::uno::Reference<                               \
111cdf0e10cSrcweir                ::com::sun::star::uno::XComponentContext > const & xContext) \
112cdf0e10cSrcweir     throw(::com::sun::star::uno::Exception)                                 \
113cdf0e10cSrcweir {                                                                           \
114cdf0e10cSrcweir     return (::cppu::OWeakObject *)new Class( xContext );                    \
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir /** This macro contains the default implementation for getImplementationId().
118cdf0e10cSrcweir     Note, that you have to include the header necessary for rtl_createUuid.
119cdf0e10cSrcweir     Insert the following into your file:
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     <code>
122cdf0e10cSrcweir #include <rtl/uuid.h>
123cdf0e10cSrcweir     </code>
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     @param Class the Class-Name for which getImplementationId() should be
126cdf0e10cSrcweir     implemented
127cdf0e10cSrcweir  */
128cdf0e10cSrcweir #define APPHELPER_GETIMPLEMENTATIONID_IMPL(Class) \
129cdf0e10cSrcweir ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL Class::getImplementationId() \
130cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException) \
131cdf0e10cSrcweir { \
132cdf0e10cSrcweir     static ::com::sun::star::uno::Sequence< sal_Int8 > aId; \
133cdf0e10cSrcweir     if( aId.getLength() == 0 ) \
134cdf0e10cSrcweir     { \
135cdf0e10cSrcweir         aId.realloc( 16 ); \
136cdf0e10cSrcweir         rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); \
137cdf0e10cSrcweir     } \
138cdf0e10cSrcweir     return aId; \
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir }//end namespace apphelper
142cdf0e10cSrcweir #endif
143