Branch data 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 : : #ifndef _COM_SUN_STAR_UNO_TYPE_H_
20 : : #define _COM_SUN_STAR_UNO_TYPE_H_
21 : :
22 : : #include <typelib/typedescription.h>
23 : : #include <com/sun/star/uno/TypeClass.hdl>
24 : : #include <cppu/macros.hxx>
25 : : #include <rtl/ustring.hxx>
26 : : #include <rtl/alloc.h>
27 : :
28 : :
29 : : namespace com
30 : : {
31 : : namespace sun
32 : : {
33 : : namespace star
34 : : {
35 : : namespace uno
36 : : {
37 : :
38 : : /** Enum defining UNO_TYPE_NO_ACQUIRE for type description reference transfer.
39 : : */
40 : : enum UnoType_NoAcquire
41 : : {
42 : : /** This enum value can be used for creating a Type object granting a given type description
43 : : reference, i.e. transferring ownership to it.
44 : : */
45 : : UNO_TYPE_NO_ACQUIRE
46 : : };
47 : :
48 : : /** C++ class representing an IDL meta type. This class is used to represent a a type,
49 : : i.e. a type name and its type class.
50 : : Internally the type holds a C type description reference of the runtime.
51 : : You can obtain a full type description of a type by calling member function getDescription().
52 : :
53 : : @see typelib_TypeDescriptionReference
54 : : */
55 : : class Type
56 : : {
57 : : /** the C typelib reference pointer
58 : : */
59 : : typelib_TypeDescriptionReference * _pType;
60 : :
61 : : public:
62 : : /// @cond INTERNAL
63 : : // these are here to force memory de/allocation to sal lib.
64 : 136753 : inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW(())
65 : 136753 : { return ::rtl_allocateMemory( nSize ); }
66 : : inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW(())
67 : : { ::rtl_freeMemory( pMem ); }
68 : : inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW(())
69 : : { return pMem; }
70 : : inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW(())
71 : : {}
72 : : /// @endcond
73 : :
74 : : /** Default Constructor: Type is set to void.
75 : : */
76 : : inline Type() SAL_THROW(());
77 : :
78 : : /** Constructor: Type is constructed by given name and type class.
79 : :
80 : : @param eTypeClass type class of type
81 : : @param rTypeName name of type
82 : : */
83 : : inline Type( TypeClass eTypeClass, const ::rtl::OUString & rTypeName ) SAL_THROW(());
84 : :
85 : : /** Constructor: Type is constructed by given name and type class.
86 : :
87 : : @param eTypeClass type class of type
88 : : @param pTypeName name of type
89 : : */
90 : : inline Type( TypeClass eTypeClass, const sal_Char * pTypeName ) SAL_THROW(());
91 : :
92 : : /** Constructor: Type is (copy) constructed by given C type description reference.
93 : :
94 : : @param pType C type description reference
95 : : */
96 : : inline Type( typelib_TypeDescriptionReference * pType ) SAL_THROW(());
97 : :
98 : : /** Constructor: Type is (copy) constructed by given C type description reference
99 : : without acquiring it.
100 : :
101 : : @param pType C type description reference
102 : : @param dummy UNO_TYPE_NO_ACQUIRE to force obvious distinction to other constructors
103 : : */
104 : : inline Type( typelib_TypeDescriptionReference * pType, UnoType_NoAcquire dummy ) SAL_THROW(());
105 : : /** Constructor: Type is (copy) constructed by given C type description reference
106 : : without acquiring it.
107 : :
108 : : @param pType C type description reference
109 : : @param dummy SAL_NO_ACQUIRE to force obvious distinction to other constructors
110 : : */
111 : : inline Type( typelib_TypeDescriptionReference * pType, __sal_NoAcquire dummy ) SAL_THROW(());
112 : :
113 : : /** Copy constructor: Type is copy constructed by given type.
114 : :
115 : : @param rType another type
116 : : */
117 : : inline Type( const Type & rType ) SAL_THROW(());
118 : :
119 : : /** Destructor: Releases acquired C type description reference.
120 : : */
121 : 9816802 : inline ~Type() SAL_THROW(())
122 : 9816802 : { ::typelib_typedescriptionreference_release( _pType ); }
123 : :
124 : : /** Assignment operator: Acquires right side type and releases previously set type.
125 : :
126 : : @param rType another type (right side)
127 : : @return this type
128 : : */
129 : : inline Type & SAL_CALL operator = ( const Type & rType ) SAL_THROW(());
130 : :
131 : : /** Gets the type class of set type.
132 : :
133 : : @return type class of set type
134 : : */
135 : 20053065 : inline TypeClass SAL_CALL getTypeClass() const SAL_THROW(())
136 : 20053065 : { return (TypeClass)_pType->eTypeClass; }
137 : :
138 : : /** Gets the name of the set type.
139 : :
140 : : @return name of the set type
141 : : */
142 : : inline ::rtl::OUString SAL_CALL getTypeName() const SAL_THROW(());
143 : :
144 : : /** Obtains a full type description of set type.
145 : :
146 : : @param ppDescr [inout] type description
147 : : */
148 : 192468 : inline void SAL_CALL getDescription( typelib_TypeDescription ** ppDescr ) const SAL_THROW(())
149 : 192468 : { ::typelib_typedescriptionreference_getDescription( ppDescr, _pType ); }
150 : :
151 : : /** Gets the C typelib type description reference pointer. Does not acquire the reference!
152 : :
153 : : @return UNacquired type description reference
154 : : */
155 : 157447861 : inline typelib_TypeDescriptionReference * SAL_CALL getTypeLibType() const SAL_THROW(())
156 : 157447861 : { return _pType; }
157 : :
158 : : /** Tests if values of this reflected type can be assigned by values of given type.
159 : : This includes widening conversion (e.g., long assignable from short), as long as there
160 : : is no data loss.
161 : :
162 : : @param rType another type
163 : : @return true if values of this type can be assigned from values of given type,
164 : : false otherwise
165 : : */
166 : 1665 : inline sal_Bool SAL_CALL isAssignableFrom( const Type & rType ) const SAL_THROW(())
167 : 1665 : { return ::typelib_typedescriptionreference_isAssignableFrom( _pType, rType._pType ); }
168 : :
169 : : /** Compares two types.
170 : :
171 : : @param rType another type
172 : : @return true if both types refer the same type, false otherwise
173 : : */
174 : 1260980 : inline sal_Bool SAL_CALL equals( const Type & rType ) const SAL_THROW(())
175 : 1260980 : { return ::typelib_typedescriptionreference_equals( _pType, rType._pType ); }
176 : : /** Equality operator: Compares two types.
177 : :
178 : : @param rType another type
179 : : @return true if both types refer the same type, false otherwise
180 : : */
181 : 78898279 : inline sal_Bool SAL_CALL operator == ( const Type & rType ) const SAL_THROW(())
182 : 78898279 : { return ::typelib_typedescriptionreference_equals( _pType, rType._pType ); }
183 : : /** Unequality operator: Compares two types.
184 : :
185 : : @param rType another type
186 : : @return false if both types refer the same type, true otherwise
187 : : */
188 : 319661 : inline sal_Bool SAL_CALL operator != ( const Type & rType ) const SAL_THROW(())
189 : 319661 : { return (! ::typelib_typedescriptionreference_equals( _pType, rType._pType )); }
190 : : };
191 : :
192 : : /** Helper class to specify a type pointer for idl arrays.
193 : : */
194 : : template< class T >
195 : : class Array
196 : : {
197 : : public:
198 : : static typelib_TypeDescriptionReference * s_pType;
199 : : };
200 : :
201 : : }
202 : : }
203 : : }
204 : : }
205 : :
206 : : /** Gets the meta type of IDL type "type".
207 : :
208 : : There are cases (involving templates) where uses of getCppuType are known to
209 : : not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead.
210 : :
211 : : The dummy parameter is just a typed pointer for function signature.
212 : :
213 : : @return type of IDL type "type"
214 : : */
215 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const ::com::sun::star::uno::Type * ) SAL_THROW(());
216 : :
217 : : /** Gets the meta type of IDL type void.
218 : : @return type of IDL type void
219 : : */
220 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuVoidType() SAL_THROW(());
221 : : /** Gets the meta type of IDL type void.
222 : :
223 : : @return type of IDL type void
224 : : */
225 : : inline const ::com::sun::star::uno::Type & SAL_CALL getVoidCppuType() SAL_THROW(());
226 : :
227 : : /** Gets the meta type of IDL type boolean.
228 : :
229 : : @return type of IDL type boolean
230 : : */
231 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuBooleanType() SAL_THROW(());
232 : : /** Gets the meta type of IDL type boolean.
233 : :
234 : : @return type of IDL type boolean
235 : : */
236 : : inline const ::com::sun::star::uno::Type & SAL_CALL getBooleanCppuType() SAL_THROW(());
237 : : /** Gets the meta type of IDL type boolean.
238 : :
239 : : There are cases (involving templates) where uses of getCppuType are known to
240 : : not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead.
241 : :
242 : : The dummy parameter is just a typed pointer for function signature.
243 : :
244 : : @return type of IDL type boolean
245 : : */
246 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Bool * ) SAL_THROW(());
247 : : /** Gets the meta type of IDL type boolean.
248 : :
249 : : There are cases (involving templates) where uses of getCppuType are known to
250 : : not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead.
251 : :
252 : : The dummy parameter is just a typed pointer for function signature.
253 : :
254 : : @return type of IDL type boolean
255 : : */
256 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType(
257 : : bool const * ) SAL_THROW(());
258 : :
259 : : /** Gets the meta type of IDL type char.
260 : :
261 : : @return type of IDL type char
262 : : */
263 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCharCppuType() SAL_THROW(());
264 : : /** Gets the meta type of IDL type char.
265 : :
266 : : @return type of IDL type char
267 : : */
268 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuCharType() SAL_THROW(());
269 : :
270 : : /** Gets the meta type of IDL type byte.
271 : :
272 : : There are cases (involving templates) where uses of getCppuType are known to
273 : : not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead.
274 : :
275 : : The dummy parameter is just a typed pointer for function signature.
276 : :
277 : : @return type of IDL type byte
278 : : */
279 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int8 * ) SAL_THROW(());
280 : :
281 : : /** Gets the meta type of IDL type string.
282 : :
283 : : There are cases (involving templates) where uses of getCppuType are known to
284 : : not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead.
285 : :
286 : : The dummy parameter is just a typed pointer for function signature.
287 : :
288 : : @return type of IDL type string
289 : : */
290 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const ::rtl::OUString * ) SAL_THROW(());
291 : :
292 : : /** Gets the meta type of IDL type short.
293 : :
294 : : There are cases (involving templates) where uses of getCppuType are known to
295 : : not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead.
296 : :
297 : : The dummy parameter is just a typed pointer for function signature.
298 : :
299 : : @return type of IDL type short
300 : : */
301 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int16 * ) SAL_THROW(());
302 : :
303 : : /** Gets the meta type of IDL type unsigned short.
304 : :
305 : : There are cases (involving templates) where uses of getCppuType are known to
306 : : not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead.
307 : :
308 : : The dummy parameter is just a typed pointer for function signature.
309 : :
310 : : @return type of IDL type unsigned short
311 : : */
312 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt16 * ) SAL_THROW(());
313 : :
314 : : /** Gets the meta type of IDL type long.
315 : :
316 : : There are cases (involving templates) where uses of getCppuType are known to
317 : : not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead.
318 : :
319 : : The dummy parameter is just a typed pointer for function signature.
320 : :
321 : : @return type of IDL type long
322 : : */
323 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int32 * ) SAL_THROW(());
324 : :
325 : : /** Gets the meta type of IDL type unsigned long.
326 : :
327 : : There are cases (involving templates) where uses of getCppuType are known to
328 : : not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead.
329 : :
330 : : The dummy parameter is just a typed pointer for function signature.
331 : :
332 : : @return type of IDL type unsigned long
333 : : */
334 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt32 * ) SAL_THROW(());
335 : :
336 : : /** Gets the meta type of IDL type hyper.
337 : :
338 : : There are cases (involving templates) where uses of getCppuType are known to
339 : : not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead.
340 : :
341 : : The dummy parameter is just a typed pointer for function signature.
342 : :
343 : : @return type of IDL type hyper
344 : : */
345 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int64 * ) SAL_THROW(());
346 : :
347 : : /** Gets the meta type of IDL type unsigned hyper.
348 : :
349 : : There are cases (involving templates) where uses of getCppuType are known to
350 : : not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead.
351 : :
352 : : The dummy parameter is just a typed pointer for function signature.
353 : :
354 : : @return type of IDL type unsigned hyper
355 : : */
356 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt64 * ) SAL_THROW(());
357 : :
358 : : /** Gets the meta type of IDL type float.
359 : :
360 : : There are cases (involving templates) where uses of getCppuType are known to
361 : : not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead.
362 : :
363 : : The dummy parameter is just a typed pointer for function signature.
364 : :
365 : : @return type of IDL type float
366 : : */
367 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const float * ) SAL_THROW(());
368 : :
369 : : /** Gets the meta type of IDL type double.
370 : :
371 : : There are cases (involving templates) where uses of getCppuType are known to
372 : : not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead.
373 : :
374 : : The dummy parameter is just a typed pointer for function signature.
375 : :
376 : : @return type of IDL type double
377 : : */
378 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const double * ) SAL_THROW(());
379 : :
380 : : /** Array template function to get meta type for one-dimensional arrays.
381 : :
382 : : @param pT array pointer
383 : : @return type of array
384 : : */
385 : : template< class T >
386 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType1( T * pT ) SAL_THROW(());
387 : : /** Array template function to get meta type for two-dimensional arrays.
388 : :
389 : : @param pT array pointer
390 : : @return type of array
391 : : */
392 : : template< class T >
393 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType2( T * pT ) SAL_THROW(());
394 : : /** Array template function to get meta type for three-dimensional arrays.
395 : :
396 : : @param pT array pointer
397 : : @return type of array
398 : : */
399 : : template< class T >
400 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType3( T * pT ) SAL_THROW(());
401 : : /** Array template function to get meta type for four-dimensional arrays.
402 : :
403 : : @param pT array pointer
404 : : @return type of array
405 : : */
406 : : template< class T >
407 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType4( T * pT ) SAL_THROW(());
408 : : /** Array template function to get meta type for five-dimensional arrays.
409 : :
410 : : @param pT array pointer
411 : : @return type of array
412 : : */
413 : : template< class T >
414 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType5( T * pT ) SAL_THROW(());
415 : : /** Array template function to get meta type for six-dimensional arrays.
416 : :
417 : : @param pT array pointer
418 : : @return type of array
419 : : */
420 : : template< class T >
421 : : inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType6( T * pT ) SAL_THROW(());
422 : :
423 : : /** Gets the meta type of an IDL type.
424 : :
425 : : The difference between this function template (with a type parameter) and
426 : : the overloaded getCppuType function with a single (dummy) parameter of a
427 : : specific type is that this function template may not work for the UNO type
428 : : "unsigned short" (sal_uInt16 in C++), while the overloaded one-parameter
429 : : function may not work for the UNO type "char" (sal_Unicode in C++, which may
430 : : have the same underlying C++ type as sal_uInt16 on certain platforms).
431 : :
432 : : @return type of the given IDL type
433 : :
434 : : @deprecated
435 : : Use cppu::UnoType instead (or the internal-only cppu::getTypeFavourChar).
436 : : Also note that getCppuType< com::sun::star::uno::Sequence< sal_Unicode > >()
437 : : does not work as expected.
438 : :
439 : : @since UDK 3.2.0
440 : : */
441 : : template< typename T > inline const ::com::sun::star::uno::Type & SAL_CALL
442 : : getCppuType() SAL_THROW(());
443 : :
444 : : /** Gets the meta type of IDL type char.
445 : :
446 : : @return type of IDL type char
447 : :
448 : : @deprecated
449 : : Use cppu::UnoType instead (or the internal-only cppu::getTypeFavourChar).
450 : : Also note that getCppuType< com::sun::star::uno::Sequence< sal_Unicode > >()
451 : : does not work as expected.
452 : :
453 : : @since UDK 3.2.0
454 : : */
455 : : template<> inline const ::com::sun::star::uno::Type & SAL_CALL
456 : : getCppuType< sal_Unicode >() SAL_THROW(());
457 : :
458 : : #endif
459 : :
460 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|