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