1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
24 #define _CPPUHELPER_TYPEPROVIDER_HXX_
25 
26 #include <rtl/alloc.h>
27 #include <rtl/uuid.h>
28 #include <com/sun/star/uno/Sequence.hxx>
29 
30 
31 namespace cppu
32 {
33 
34 /** Helper class to implement ::com::sun::star::lang::XTypeProvider.  Construct a static object
35     of this class with your UNO object's supported types.
36 */
37 class OTypeCollection
38 {
39 	::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > _aTypes;
40 
41 public:
42 	// these are here to force memory de/allocation to sal lib.
43     /** @internal */
operator new(size_t nSize)44 	inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () )
45 		{ return ::rtl_allocateMemory( nSize ); }
46     /** @internal */
operator delete(void * pMem)47 	inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () )
48 		{ ::rtl_freeMemory( pMem ); }
49     /** @internal */
operator new(size_t,void * pMem)50 	inline static void * SAL_CALL operator new( size_t, void * pMem ) SAL_THROW( () )
51 		{ return pMem; }
52     /** @internal */
operator delete(void *,void *)53 	inline static void SAL_CALL operator delete( void *, void * ) SAL_THROW( () )
54 		{}
55 
56 	inline OTypeCollection( const OTypeCollection & rCollection )
57 		SAL_THROW( () )
58 		: _aTypes( rCollection._aTypes )
59 		{}
60 	OTypeCollection(
61 		const ::com::sun::star::uno::Type & rType1,
62 		const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > & rAddTypes = ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >() )
63 		SAL_THROW( () );
64 	OTypeCollection(
65 		const ::com::sun::star::uno::Type & rType1,
66 		const ::com::sun::star::uno::Type & rType2,
67 		const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > & rAddTypes = ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >() )
68 		SAL_THROW( () );
69 	OTypeCollection(
70 		const ::com::sun::star::uno::Type & rType1,
71 		const ::com::sun::star::uno::Type & rType2,
72 		const ::com::sun::star::uno::Type & rType3,
73 		const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > & rAddTypes = ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >() )
74 		SAL_THROW( () );
75 	OTypeCollection(
76 		const ::com::sun::star::uno::Type & rType1,
77 		const ::com::sun::star::uno::Type & rType2,
78 		const ::com::sun::star::uno::Type & rType3,
79 		const ::com::sun::star::uno::Type & rType4,
80 		const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > & rAddTypes = ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >() )
81 		SAL_THROW( () );
82 	OTypeCollection(
83 		const ::com::sun::star::uno::Type & rType1,
84 		const ::com::sun::star::uno::Type & rType2,
85 		const ::com::sun::star::uno::Type & rType3,
86 		const ::com::sun::star::uno::Type & rType4,
87 		const ::com::sun::star::uno::Type & rType5,
88 		const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > & rAddTypes = ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >() )
89 		SAL_THROW( () );
90 	OTypeCollection(
91 		const ::com::sun::star::uno::Type & rType1,
92 		const ::com::sun::star::uno::Type & rType2,
93 		const ::com::sun::star::uno::Type & rType3,
94 		const ::com::sun::star::uno::Type & rType4,
95 		const ::com::sun::star::uno::Type & rType5,
96 		const ::com::sun::star::uno::Type & rType6,
97 		const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > & rAddTypes = ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >() )
98 		SAL_THROW( () );
99 	OTypeCollection(
100 		const ::com::sun::star::uno::Type & rType1,
101 		const ::com::sun::star::uno::Type & rType2,
102 		const ::com::sun::star::uno::Type & rType3,
103 		const ::com::sun::star::uno::Type & rType4,
104 		const ::com::sun::star::uno::Type & rType5,
105 		const ::com::sun::star::uno::Type & rType6,
106 		const ::com::sun::star::uno::Type & rType7,
107 		const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > & rAddTypes = ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >() )
108 		SAL_THROW( () );
109 	OTypeCollection(
110 		const ::com::sun::star::uno::Type & rType1,
111 		const ::com::sun::star::uno::Type & rType2,
112 		const ::com::sun::star::uno::Type & rType3,
113 		const ::com::sun::star::uno::Type & rType4,
114 		const ::com::sun::star::uno::Type & rType5,
115 		const ::com::sun::star::uno::Type & rType6,
116 		const ::com::sun::star::uno::Type & rType7,
117 		const ::com::sun::star::uno::Type & rType8,
118 		const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > & rAddTypes = ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >() )
119 		SAL_THROW( () );
120 	OTypeCollection(
121 		const ::com::sun::star::uno::Type & rType1,
122 		const ::com::sun::star::uno::Type & rType2,
123 		const ::com::sun::star::uno::Type & rType3,
124 		const ::com::sun::star::uno::Type & rType4,
125 		const ::com::sun::star::uno::Type & rType5,
126 		const ::com::sun::star::uno::Type & rType6,
127 		const ::com::sun::star::uno::Type & rType7,
128 		const ::com::sun::star::uno::Type & rType8,
129 		const ::com::sun::star::uno::Type & rType9,
130 		const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > & rAddTypes = ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >() )
131 		SAL_THROW( () );
132 	OTypeCollection(
133 		const ::com::sun::star::uno::Type & rType1,
134 		const ::com::sun::star::uno::Type & rType2,
135 		const ::com::sun::star::uno::Type & rType3,
136 		const ::com::sun::star::uno::Type & rType4,
137 		const ::com::sun::star::uno::Type & rType5,
138 		const ::com::sun::star::uno::Type & rType6,
139 		const ::com::sun::star::uno::Type & rType7,
140 		const ::com::sun::star::uno::Type & rType8,
141 		const ::com::sun::star::uno::Type & rType9,
142 		const ::com::sun::star::uno::Type & rType10,
143 		const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > & rAddTypes = ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >() )
144 		SAL_THROW( () );
145 	OTypeCollection(
146 		const ::com::sun::star::uno::Type & rType1,
147 		const ::com::sun::star::uno::Type & rType2,
148 		const ::com::sun::star::uno::Type & rType3,
149 		const ::com::sun::star::uno::Type & rType4,
150 		const ::com::sun::star::uno::Type & rType5,
151 		const ::com::sun::star::uno::Type & rType6,
152 		const ::com::sun::star::uno::Type & rType7,
153 		const ::com::sun::star::uno::Type & rType8,
154 		const ::com::sun::star::uno::Type & rType9,
155 		const ::com::sun::star::uno::Type & rType10,
156 		const ::com::sun::star::uno::Type & rType11,
157 		const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > & rAddTypes = ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >() )
158 		SAL_THROW( () );
159 	OTypeCollection(
160 		const ::com::sun::star::uno::Type & rType1,
161 		const ::com::sun::star::uno::Type & rType2,
162 		const ::com::sun::star::uno::Type & rType3,
163 		const ::com::sun::star::uno::Type & rType4,
164 		const ::com::sun::star::uno::Type & rType5,
165 		const ::com::sun::star::uno::Type & rType6,
166 		const ::com::sun::star::uno::Type & rType7,
167 		const ::com::sun::star::uno::Type & rType8,
168 		const ::com::sun::star::uno::Type & rType9,
169 		const ::com::sun::star::uno::Type & rType10,
170 		const ::com::sun::star::uno::Type & rType11,
171 		const ::com::sun::star::uno::Type & rType12,
172 		const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > & rAddTypes = ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >() )
173 		SAL_THROW( () );
174 
175     /** Called upon XTypeProvider::getTypes().
176 
177         @return type collection
178     */
getTypes()179 	::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() SAL_THROW( () )
180 		{ return _aTypes; }
181 };
182 
183 /** Helper class to implement ::com::sun::star::lang::XTypeProvider.  Construct a static object
184     of this class for your UNO object's implementation id.
185 */
186 class OImplementationId
187 {
188     /** @internal */
189 	mutable ::com::sun::star::uno::Sequence< sal_Int8 > * _pSeq;
190     /** @internal */
191 	sal_Bool _bUseEthernetAddress;
192 
193 public:
194 	// these are here to force memory de/allocation to sal lib.
195     /** @internal */
operator new(size_t nSize)196 	inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () )
197 		{ return ::rtl_allocateMemory( nSize ); }
198     /** @internal */
operator delete(void * pMem)199 	inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () )
200 		{ ::rtl_freeMemory( pMem ); }
201     /** @internal */
operator new(size_t,void * pMem)202 	inline static void * SAL_CALL operator new( size_t, void * pMem ) SAL_THROW( () )
203 		{ return pMem; }
204     /** @internal */
operator delete(void *,void *)205 	inline static void SAL_CALL operator delete( void *, void * ) SAL_THROW( () )
206 		{}
207 
208     /** @internal */
209 	~OImplementationId() SAL_THROW( () );
210     /** Constructor.
211 
212         @param bUseEthernetAddress whether an ethernet mac address should be taken into account
213     */
214 	inline OImplementationId( sal_Bool bUseEthernetAddress = sal_True ) SAL_THROW( () )
215 		: _pSeq( 0 )
216 		, _bUseEthernetAddress( bUseEthernetAddress )
217 		{}
218     /** Constructor giving implementation id.
219 
220         @param rSeq implementation id
221     */
222 	inline OImplementationId( const ::com::sun::star::uno::Sequence< sal_Int8 > & rSeq ) SAL_THROW( () )
223 		: _pSeq( new ::com::sun::star::uno::Sequence< sal_Int8 >( rSeq ) )
224 		{}
225 	inline OImplementationId( const OImplementationId & rId ) SAL_THROW( () )
226 		: _pSeq( new ::com::sun::star::uno::Sequence< sal_Int8 >( rId.getImplementationId() ) )
227 		{}
228 
229     /** Called upon XTypeProvider::getImplementationId().
230 
231         @return implementation id
232     */
233 	::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() const SAL_THROW( () );
234 };
235 
236 }
237 
238 #endif
239