UDK 3.2.7 C/C++ API Reference
|
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 00002 /************************************************************************* 00003 * 00004 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 00005 * 00006 * Copyright 2000, 2010 Oracle and/or its affiliates. 00007 * 00008 * OpenOffice.org - a multi-platform office productivity suite 00009 * 00010 * This file is part of OpenOffice.org. 00011 * 00012 * OpenOffice.org is free software: you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 3 00014 * only, as published by the Free Software Foundation. 00015 * 00016 * OpenOffice.org is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License version 3 for more details 00020 * (a copy is included in the LICENSE file that accompanied this code). 00021 * 00022 * You should have received a copy of the GNU Lesser General Public License 00023 * version 3 along with OpenOffice.org. If not, see 00024 * <http://www.openoffice.org/license.html> 00025 * for a copy of the LGPLv3 License. 00026 * 00027 ************************************************************************/ 00028 #ifndef _CPPUHELPER_PROPTYPEHLP_HXX 00029 #define _CPPUHELPER_PROPTYPEHLP_HXX 00030 00031 #include <cppuhelper/proptypehlp.h> 00032 00033 namespace cppu 00034 { 00035 00043 template < class target > 00044 inline void SAL_CALL convertPropertyValue( target &value , const ::com::sun::star::uno::Any & a) 00045 { 00046 00047 if( !( a >>= value ) ) { 00048 throw ::com::sun::star::lang::IllegalArgumentException(); 00049 } 00050 } 00051 00052 00053 // This template is needed at least for msci4 compiler 00054 template < class target > 00055 inline void SAL_CALL convertPropertyValue( target &value , ::com::sun::star::uno::Any & a) 00056 { 00057 convertPropertyValue( value , (const ::com::sun::star::uno::Any & ) a ); 00058 } 00059 00063 inline void SAL_CALL convertPropertyValue( sal_Bool & b , const ::com::sun::star::uno::Any & a ) 00064 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) ) 00065 { 00066 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass(); 00067 00068 if( ::com::sun::star::uno::TypeClass_LONG == tc ) { 00069 sal_Int32 i32 = 0; 00070 a >>= i32; 00071 b = ( sal_Bool )i32; 00072 } 00073 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) { 00074 sal_Unicode c = *(sal_Unicode*) a.getValue(); 00075 b = ( sal_Bool ) c; 00076 } 00077 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) { 00078 sal_Int16 i16 = 0; 00079 a >>= i16; 00080 b = ( sal_Bool ) i16; 00081 } 00082 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) { 00083 b = *((sal_Bool*)a.getValue()); 00084 } 00085 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) { 00086 sal_Int8 i8 = 0; 00087 a >>= i8; 00088 b = ( sal_Bool ) i8; 00089 } 00090 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) { 00091 sal_uInt16 i16 = 0; 00092 a >>= i16; 00093 b = ( sal_Bool ) i16; 00094 } 00095 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) { 00096 sal_uInt32 i32 = 0; 00097 a >>= i32; 00098 b = ( sal_Bool ) i32; 00099 } 00100 else { 00101 throw ::com::sun::star::lang::IllegalArgumentException(); 00102 } 00103 } 00104 00105 inline void SAL_CALL convertPropertyValue( sal_Int64 & i , const ::com::sun::star::uno::Any & a ) 00106 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) ) 00107 { 00108 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass(); 00109 00110 if( ::com::sun::star::uno::TypeClass_HYPER == tc ) { 00111 a >>= i; 00112 } 00113 else if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) { 00114 sal_uInt64 i64 = 0; 00115 a >>= i64; 00116 i = ( sal_Int64 ) i64; 00117 } 00118 else if( ::com::sun::star::uno::TypeClass_LONG == tc ) { 00119 sal_Int32 i32 = 0; 00120 a >>= i32; 00121 i = ( sal_Int64 )i32; 00122 } 00123 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) { 00124 sal_Unicode c; 00125 c = *(sal_Unicode *)a.getValue(); 00126 i = ( sal_Int64 ) c; 00127 } 00128 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) { 00129 sal_Int16 i16 = 0; 00130 a >>= i16; 00131 i = ( sal_Int64 ) i16; 00132 } 00133 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) { 00134 sal_Bool b; 00135 b = *((sal_Bool * )a.getValue()); 00136 i = ( sal_Int64 ) b; 00137 } 00138 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) { 00139 sal_Int8 i8 = 0; 00140 a >>= i8; 00141 i = ( sal_Int64 ) i8; 00142 } 00143 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) { 00144 sal_uInt16 i16 = 0; 00145 a >>= i16; 00146 i = ( sal_Int64 ) i16; 00147 } 00148 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) { 00149 sal_uInt32 i32 = 0; 00150 a >>= i32; 00151 i = ( sal_Int64 ) i32; 00152 } 00153 else { 00154 throw ::com::sun::star::lang::IllegalArgumentException(); 00155 } 00156 } 00157 00158 00159 inline void SAL_CALL convertPropertyValue( sal_uInt64 & i , const ::com::sun::star::uno::Any & a ) 00160 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) ) 00161 { 00162 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass(); 00163 00164 if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) { 00165 a >>= i; 00166 } 00167 if( ::com::sun::star::uno::TypeClass_HYPER == tc ) { 00168 sal_Int64 i64; 00169 a >>= i64; 00170 i = ( sal_uInt64 ) i64; 00171 } 00172 else if( ::com::sun::star::uno::TypeClass_LONG == tc ) { 00173 sal_Int32 i32; 00174 a >>= i32; 00175 i = ( sal_uInt64 )i32; 00176 } 00177 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) { 00178 sal_Unicode c; 00179 c = *( sal_Unicode * ) a.getValue() ; 00180 i = ( sal_uInt64 ) c; 00181 } 00182 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) { 00183 sal_Int16 i16; 00184 a >>= i16; 00185 i = ( sal_uInt64 ) i16; 00186 } 00187 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) { 00188 sal_Bool b; 00189 b = *((sal_Bool * )a.getValue()); 00190 i = ( sal_uInt64 ) b; 00191 } 00192 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) { 00193 sal_Int8 i8; 00194 a >>= i8; 00195 i = ( sal_uInt64 ) i8; 00196 } 00197 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) { 00198 sal_uInt16 i16; 00199 a >>= i16; 00200 i = ( sal_uInt64 ) i16; 00201 } 00202 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) { 00203 sal_uInt32 i32; 00204 a >>= i32; 00205 i = ( sal_uInt64 ) i32; 00206 } 00207 else { 00208 throw ::com::sun::star::lang::IllegalArgumentException(); 00209 } 00210 } 00211 00212 // the basic types 00213 // sal_Int32 00214 inline void SAL_CALL convertPropertyValue( sal_Int32 & i , const ::com::sun::star::uno::Any & a ) 00215 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) ) 00216 { 00217 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass(); 00218 00219 if( ::com::sun::star::uno::TypeClass_LONG == tc ) { 00220 a >>= i; 00221 } 00222 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) { 00223 sal_Unicode c; 00224 c = *(sal_Unicode*) a.getValue(); 00225 i = ( sal_Int32 ) c; 00226 } 00227 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) { 00228 sal_Int16 i16 = 0; 00229 a >>= i16; 00230 i = ( sal_Int32 ) i16; 00231 } 00232 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) { 00233 sal_Bool b; 00234 b = *((sal_Bool * )a.getValue()); 00235 i = ( sal_Int32 ) b; 00236 } 00237 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) { 00238 sal_Int8 i8 = 0; 00239 a >>= i8; 00240 i = ( sal_Int32 ) i8; 00241 } 00242 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) { 00243 sal_uInt16 i16 = 0; 00244 a >>= i16; 00245 i = ( sal_Int32 ) i16; 00246 } 00247 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) { 00248 sal_uInt32 i32 = 0; 00249 a >>= i32; 00250 i = ( sal_Int32 ) i32; 00251 } 00252 else { 00253 throw ::com::sun::star::lang::IllegalArgumentException(); 00254 } 00255 } 00256 00257 inline void SAL_CALL convertPropertyValue( sal_uInt32 & i , const ::com::sun::star::uno::Any & a ) 00258 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) ) 00259 { 00260 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass(); 00261 00262 if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) { 00263 a >>= i; 00264 } 00265 else if( ::com::sun::star::uno::TypeClass_LONG == tc ) { 00266 sal_Int32 i32; 00267 a >>= i32; 00268 i = (sal_uInt32 ) i32; 00269 } 00270 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) { 00271 sal_Unicode c; 00272 c = *(sal_Unicode*) a.getValue(); 00273 i = ( sal_uInt32 ) c; 00274 } 00275 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) { 00276 sal_Int16 i16; 00277 a >>= i16; 00278 i = ( sal_uInt32 ) i16; 00279 } 00280 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) { 00281 sal_Bool b; 00282 b = *((sal_Bool * )a.getValue()); 00283 i = ( sal_uInt32 ) b; 00284 } 00285 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) { 00286 sal_Int8 i8; 00287 a >>= i8; 00288 i = ( sal_uInt32 ) i8; 00289 } 00290 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) { 00291 sal_uInt16 i16; 00292 a >>= i16; 00293 i = ( sal_uInt32 ) i16; 00294 } 00295 else { 00296 throw ::com::sun::star::lang::IllegalArgumentException(); 00297 } 00298 } 00299 00300 00301 inline void SAL_CALL convertPropertyValue( sal_Int16 & i , const ::com::sun::star::uno::Any & a ) 00302 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) ) 00303 { 00304 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass(); 00305 00306 if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) { 00307 a >>= i; 00308 } 00309 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) { 00310 sal_Unicode c; 00311 c = *(sal_Unicode*) a.getValue(); 00312 i = ( sal_Int16 ) c; 00313 } 00314 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) { 00315 sal_Bool b; 00316 b = *((sal_Bool * )a.getValue()); 00317 i = ( sal_Int16 ) b; 00318 } 00319 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) { 00320 sal_Int8 i8 = 0; 00321 a >>= i8; 00322 i = ( sal_Int16 ) i8; 00323 } 00324 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) { 00325 sal_uInt16 i16 = 0; 00326 a >>= i16; 00327 i = ( sal_Int16 ) i16; 00328 } 00329 else { 00330 throw ::com::sun::star::lang::IllegalArgumentException(); 00331 } 00332 } 00333 00334 inline void SAL_CALL convertPropertyValue( sal_uInt16 & i , const ::com::sun::star::uno::Any & a ) 00335 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) ) 00336 { 00337 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass(); 00338 00339 if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) { 00340 a >>= i; 00341 } 00342 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) { 00343 sal_Unicode c; 00344 c = *(sal_Unicode *) a.getValue(); 00345 i = ( sal_Int16 ) c; 00346 } 00347 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) { 00348 sal_Bool b; 00349 b = *((sal_Bool * )a.getValue()); 00350 i = ( sal_Int16 ) b; 00351 } 00352 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) { 00353 sal_Int8 i8 = 0; 00354 a >>= i8; 00355 i = ( sal_Int16 ) i8; 00356 } 00357 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) { 00358 sal_Int16 i16 = 0; 00359 a >>= i16; 00360 i = ( sal_Int16 ) i16; 00361 } 00362 else { 00363 throw ::com::sun::star::lang::IllegalArgumentException(); 00364 } 00365 } 00366 00367 inline void SAL_CALL convertPropertyValue( sal_Int8 & i , const ::com::sun::star::uno::Any & a ) 00368 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) ) 00369 { 00370 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass(); 00371 00372 if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) { 00373 a >>= i; 00374 } 00375 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) { 00376 sal_Bool b; 00377 b = *((sal_Bool * )a.getValue()); 00378 i = ( sal_Int8 ) b; 00379 } 00380 else { 00381 throw ::com::sun::star::lang::IllegalArgumentException(); 00382 } 00383 } 00384 00385 inline void SAL_CALL convertPropertyValue( float &f , const ::com::sun::star::uno::Any &a ) 00386 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) ) 00387 { 00388 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass(); 00389 00390 if ( ::com::sun::star::uno::TypeClass_FLOAT == tc ) { 00391 a >>= f; 00392 } 00393 else if( ::com::sun::star::uno::TypeClass_DOUBLE == tc ) { 00394 double d = 0; 00395 a >>= d; 00396 f = ( float ) d; 00397 } 00398 else if( ::com::sun::star::uno::TypeClass_HYPER == tc ) { 00399 sal_Int64 i64 = 0; 00400 a >>= i64; 00401 f = ( float ) i64; 00402 } 00403 // msci 4 does not support this conversion 00404 /* else if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) { 00405 sal_uInt64 i64; 00406 a >>= i64; 00407 f = ( float ) i64; 00408 } 00409 */ else if( ::com::sun::star::uno::TypeClass_LONG == tc ) { 00410 sal_Int32 i32 = 0; 00411 a >>= i32; 00412 f = ( float )i32; 00413 } 00414 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) { 00415 sal_Unicode c; 00416 c = *(sal_Unicode*) a.getValue(); 00417 f = ( float ) c; 00418 } 00419 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) { 00420 sal_Int16 i16 = 0; 00421 a >>= i16; 00422 f = ( float ) i16; 00423 } 00424 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) { 00425 sal_Bool b; 00426 b = *((sal_Bool * )a.getValue()); 00427 f = ( float ) b; 00428 } 00429 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) { 00430 sal_Int8 i8 = 0; 00431 a >>= i8; 00432 f = ( float ) i8; 00433 } 00434 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) { 00435 sal_uInt16 i16 = 0; 00436 a >>= i16; 00437 f = ( float ) i16; 00438 } 00439 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) { 00440 sal_uInt32 i32 = 0; 00441 a >>= i32; 00442 f = ( float ) i32; 00443 } 00444 else { 00445 throw ::com::sun::star::lang::IllegalArgumentException(); 00446 } 00447 } 00448 00449 00450 inline void SAL_CALL convertPropertyValue( double &d , const ::com::sun::star::uno::Any &a ) 00451 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) ) 00452 { 00453 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass(); 00454 00455 if( ::com::sun::star::uno::TypeClass_DOUBLE == tc ) { 00456 float f; 00457 a >>= f; 00458 d = ( double ) f; 00459 } 00460 else if ( ::com::sun::star::uno::TypeClass_FLOAT == tc ) { 00461 float f; 00462 a >>= f; 00463 d = (double) f; 00464 } 00465 else if( ::com::sun::star::uno::TypeClass_HYPER == tc ) { 00466 sal_Int64 i64; 00467 a >>= i64; 00468 d = (double) i64; 00469 } 00470 // msci 4 does not support this 00471 /* else if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) { 00472 sal_uInt64 i64; 00473 a >>= i64; 00474 d = (double) i64; 00475 } 00476 */ else if( ::com::sun::star::uno::TypeClass_LONG == tc ) { 00477 sal_Int32 i32; 00478 a >>= i32; 00479 d = (double)i32; 00480 } 00481 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) { 00482 sal_Unicode c; 00483 c = *(sal_Unicode*) a.getValue(); 00484 d = (double) c; 00485 } 00486 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) { 00487 sal_Int16 i16; 00488 a >>= i16; 00489 d = (double) i16; 00490 } 00491 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) { 00492 sal_Bool b; 00493 b = *((sal_Bool * )a.getValue()); 00494 d = (double) b; 00495 } 00496 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) { 00497 sal_Int8 i8; 00498 a >>= i8; 00499 d = (double) i8; 00500 } 00501 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) { 00502 sal_uInt16 i16; 00503 a >>= i16; 00504 d = (double) i16; 00505 } 00506 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) { 00507 sal_uInt32 i32; 00508 a >>= i32; 00509 d = (double) i32; 00510 } 00511 else { 00512 throw ::com::sun::star::lang::IllegalArgumentException(); 00513 } 00514 } 00515 00516 inline void SAL_CALL convertPropertyValue( ::rtl::OUString &ow , const ::com::sun::star::uno::Any &a ) 00517 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) ) 00518 { 00519 if( ::com::sun::star::uno::TypeClass_STRING == a.getValueType().getTypeClass() ) { 00520 a >>= ow; 00521 } 00522 else { 00523 throw ::com::sun::star::lang::IllegalArgumentException(); 00524 } 00525 } 00526 00527 } // end namespace cppu 00528 00529 #endif 00530 00531 00532 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */