00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _CPPUHELPER_PROPTYPEHLP_HXX
00020 #define _CPPUHELPER_PROPTYPEHLP_HXX
00021
00022 #include <cppuhelper/proptypehlp.h>
00023
00024 namespace cppu
00025 {
00026
00034 template < class target >
00035 inline void SAL_CALL convertPropertyValue( target &value , const ::com::sun::star::uno::Any & a)
00036 {
00037
00038 if( !( a >>= value ) ) {
00039 throw ::com::sun::star::lang::IllegalArgumentException();
00040 }
00041 }
00042
00043
00044
00045 template < class target >
00046 inline void SAL_CALL convertPropertyValue( target &value , ::com::sun::star::uno::Any & a)
00047 {
00048 convertPropertyValue( value , (const ::com::sun::star::uno::Any & ) a );
00049 }
00050
00054 inline void SAL_CALL convertPropertyValue( sal_Bool & b , const ::com::sun::star::uno::Any & a )
00055 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
00056 {
00057 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
00058
00059 if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
00060 sal_Int32 i32 = 0;
00061 a >>= i32;
00062 b = ( sal_Bool )i32;
00063 }
00064 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
00065 sal_Unicode c = *(sal_Unicode*) a.getValue();
00066 b = ( sal_Bool ) c;
00067 }
00068 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
00069 sal_Int16 i16 = 0;
00070 a >>= i16;
00071 b = ( sal_Bool ) i16;
00072 }
00073 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
00074 b = *((sal_Bool*)a.getValue());
00075 }
00076 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
00077 sal_Int8 i8 = 0;
00078 a >>= i8;
00079 b = ( sal_Bool ) i8;
00080 }
00081 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
00082 sal_uInt16 i16 = 0;
00083 a >>= i16;
00084 b = ( sal_Bool ) i16;
00085 }
00086 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
00087 sal_uInt32 i32 = 0;
00088 a >>= i32;
00089 b = ( sal_Bool ) i32;
00090 }
00091 else {
00092 throw ::com::sun::star::lang::IllegalArgumentException();
00093 }
00094 }
00095
00096 inline void SAL_CALL convertPropertyValue( sal_Int64 & i , const ::com::sun::star::uno::Any & a )
00097 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
00098 {
00099 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
00100
00101 if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
00102 a >>= i;
00103 }
00104 else if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) {
00105 sal_uInt64 i64 = 0;
00106 a >>= i64;
00107 i = ( sal_Int64 ) i64;
00108 }
00109 else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
00110 sal_Int32 i32 = 0;
00111 a >>= i32;
00112 i = ( sal_Int64 )i32;
00113 }
00114 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
00115 sal_Unicode c;
00116 c = *(sal_Unicode *)a.getValue();
00117 i = ( sal_Int64 ) c;
00118 }
00119 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
00120 sal_Int16 i16 = 0;
00121 a >>= i16;
00122 i = ( sal_Int64 ) i16;
00123 }
00124 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
00125 sal_Bool b;
00126 b = *((sal_Bool * )a.getValue());
00127 i = ( sal_Int64 ) b;
00128 }
00129 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
00130 sal_Int8 i8 = 0;
00131 a >>= i8;
00132 i = ( sal_Int64 ) i8;
00133 }
00134 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
00135 sal_uInt16 i16 = 0;
00136 a >>= i16;
00137 i = ( sal_Int64 ) i16;
00138 }
00139 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
00140 sal_uInt32 i32 = 0;
00141 a >>= i32;
00142 i = ( sal_Int64 ) i32;
00143 }
00144 else {
00145 throw ::com::sun::star::lang::IllegalArgumentException();
00146 }
00147 }
00148
00149
00150 inline void SAL_CALL convertPropertyValue( sal_uInt64 & i , const ::com::sun::star::uno::Any & a )
00151 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
00152 {
00153 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
00154
00155 if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) {
00156 a >>= i;
00157 }
00158 if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
00159 sal_Int64 i64;
00160 a >>= i64;
00161 i = ( sal_uInt64 ) i64;
00162 }
00163 else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
00164 sal_Int32 i32;
00165 a >>= i32;
00166 i = ( sal_uInt64 )i32;
00167 }
00168 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
00169 sal_Unicode c;
00170 c = *( sal_Unicode * ) a.getValue() ;
00171 i = ( sal_uInt64 ) c;
00172 }
00173 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
00174 sal_Int16 i16;
00175 a >>= i16;
00176 i = ( sal_uInt64 ) i16;
00177 }
00178 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
00179 sal_Bool b;
00180 b = *((sal_Bool * )a.getValue());
00181 i = ( sal_uInt64 ) b;
00182 }
00183 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
00184 sal_Int8 i8;
00185 a >>= i8;
00186 i = ( sal_uInt64 ) i8;
00187 }
00188 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
00189 sal_uInt16 i16;
00190 a >>= i16;
00191 i = ( sal_uInt64 ) i16;
00192 }
00193 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
00194 sal_uInt32 i32;
00195 a >>= i32;
00196 i = ( sal_uInt64 ) i32;
00197 }
00198 else {
00199 throw ::com::sun::star::lang::IllegalArgumentException();
00200 }
00201 }
00202
00203
00204
00205 inline void SAL_CALL convertPropertyValue( sal_Int32 & i , const ::com::sun::star::uno::Any & a )
00206 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
00207 {
00208 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
00209
00210 if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
00211 a >>= i;
00212 }
00213 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
00214 sal_Unicode c;
00215 c = *(sal_Unicode*) a.getValue();
00216 i = ( sal_Int32 ) c;
00217 }
00218 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
00219 sal_Int16 i16 = 0;
00220 a >>= i16;
00221 i = ( sal_Int32 ) i16;
00222 }
00223 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
00224 sal_Bool b;
00225 b = *((sal_Bool * )a.getValue());
00226 i = ( sal_Int32 ) b;
00227 }
00228 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
00229 sal_Int8 i8 = 0;
00230 a >>= i8;
00231 i = ( sal_Int32 ) i8;
00232 }
00233 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
00234 sal_uInt16 i16 = 0;
00235 a >>= i16;
00236 i = ( sal_Int32 ) i16;
00237 }
00238 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
00239 sal_uInt32 i32 = 0;
00240 a >>= i32;
00241 i = ( sal_Int32 ) i32;
00242 }
00243 else {
00244 throw ::com::sun::star::lang::IllegalArgumentException();
00245 }
00246 }
00247
00248 inline void SAL_CALL convertPropertyValue( sal_uInt32 & i , const ::com::sun::star::uno::Any & a )
00249 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
00250 {
00251 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
00252
00253 if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
00254 a >>= i;
00255 }
00256 else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
00257 sal_Int32 i32;
00258 a >>= i32;
00259 i = (sal_uInt32 ) i32;
00260 }
00261 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
00262 sal_Unicode c;
00263 c = *(sal_Unicode*) a.getValue();
00264 i = ( sal_uInt32 ) c;
00265 }
00266 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
00267 sal_Int16 i16;
00268 a >>= i16;
00269 i = ( sal_uInt32 ) i16;
00270 }
00271 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
00272 sal_Bool b;
00273 b = *((sal_Bool * )a.getValue());
00274 i = ( sal_uInt32 ) b;
00275 }
00276 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
00277 sal_Int8 i8;
00278 a >>= i8;
00279 i = ( sal_uInt32 ) i8;
00280 }
00281 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
00282 sal_uInt16 i16;
00283 a >>= i16;
00284 i = ( sal_uInt32 ) i16;
00285 }
00286 else {
00287 throw ::com::sun::star::lang::IllegalArgumentException();
00288 }
00289 }
00290
00291
00292 inline void SAL_CALL convertPropertyValue( sal_Int16 & i , const ::com::sun::star::uno::Any & a )
00293 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
00294 {
00295 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
00296
00297 if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
00298 a >>= i;
00299 }
00300 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
00301 sal_Unicode c;
00302 c = *(sal_Unicode*) a.getValue();
00303 i = ( sal_Int16 ) c;
00304 }
00305 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
00306 sal_Bool b;
00307 b = *((sal_Bool * )a.getValue());
00308 i = ( sal_Int16 ) b;
00309 }
00310 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
00311 sal_Int8 i8 = 0;
00312 a >>= i8;
00313 i = ( sal_Int16 ) i8;
00314 }
00315 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
00316 sal_uInt16 i16 = 0;
00317 a >>= i16;
00318 i = ( sal_Int16 ) i16;
00319 }
00320 else {
00321 throw ::com::sun::star::lang::IllegalArgumentException();
00322 }
00323 }
00324
00325 inline void SAL_CALL convertPropertyValue( sal_uInt16 & i , const ::com::sun::star::uno::Any & a )
00326 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
00327 {
00328 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
00329
00330 if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
00331 a >>= i;
00332 }
00333 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
00334 sal_Unicode c;
00335 c = *(sal_Unicode *) a.getValue();
00336 i = ( sal_Int16 ) c;
00337 }
00338 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
00339 sal_Bool b;
00340 b = *((sal_Bool * )a.getValue());
00341 i = ( sal_Int16 ) b;
00342 }
00343 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
00344 sal_Int8 i8 = 0;
00345 a >>= i8;
00346 i = ( sal_Int16 ) i8;
00347 }
00348 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
00349 sal_Int16 i16 = 0;
00350 a >>= i16;
00351 i = ( sal_Int16 ) i16;
00352 }
00353 else {
00354 throw ::com::sun::star::lang::IllegalArgumentException();
00355 }
00356 }
00357
00358 inline void SAL_CALL convertPropertyValue( sal_Int8 & i , const ::com::sun::star::uno::Any & a )
00359 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
00360 {
00361 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
00362
00363 if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
00364 a >>= i;
00365 }
00366 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
00367 sal_Bool b;
00368 b = *((sal_Bool * )a.getValue());
00369 i = ( sal_Int8 ) b;
00370 }
00371 else {
00372 throw ::com::sun::star::lang::IllegalArgumentException();
00373 }
00374 }
00375
00376 inline void SAL_CALL convertPropertyValue( float &f , const ::com::sun::star::uno::Any &a )
00377 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
00378 {
00379 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
00380
00381 if ( ::com::sun::star::uno::TypeClass_FLOAT == tc ) {
00382 a >>= f;
00383 }
00384 else if( ::com::sun::star::uno::TypeClass_DOUBLE == tc ) {
00385 double d = 0;
00386 a >>= d;
00387 f = ( float ) d;
00388 }
00389 else if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
00390 sal_Int64 i64 = 0;
00391 a >>= i64;
00392 f = ( float ) i64;
00393 }
00394
00395
00396
00397
00398
00399
00400 else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
00401 sal_Int32 i32 = 0;
00402 a >>= i32;
00403 f = ( float )i32;
00404 }
00405 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
00406 sal_Unicode c;
00407 c = *(sal_Unicode*) a.getValue();
00408 f = ( float ) c;
00409 }
00410 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
00411 sal_Int16 i16 = 0;
00412 a >>= i16;
00413 f = ( float ) i16;
00414 }
00415 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
00416 sal_Bool b;
00417 b = *((sal_Bool * )a.getValue());
00418 f = ( float ) b;
00419 }
00420 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
00421 sal_Int8 i8 = 0;
00422 a >>= i8;
00423 f = ( float ) i8;
00424 }
00425 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
00426 sal_uInt16 i16 = 0;
00427 a >>= i16;
00428 f = ( float ) i16;
00429 }
00430 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
00431 sal_uInt32 i32 = 0;
00432 a >>= i32;
00433 f = ( float ) i32;
00434 }
00435 else {
00436 throw ::com::sun::star::lang::IllegalArgumentException();
00437 }
00438 }
00439
00440
00441 inline void SAL_CALL convertPropertyValue( double &d , const ::com::sun::star::uno::Any &a )
00442 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
00443 {
00444 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
00445
00446 if( ::com::sun::star::uno::TypeClass_DOUBLE == tc ) {
00447 float f;
00448 a >>= f;
00449 d = ( double ) f;
00450 }
00451 else if ( ::com::sun::star::uno::TypeClass_FLOAT == tc ) {
00452 float f;
00453 a >>= f;
00454 d = (double) f;
00455 }
00456 else if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
00457 sal_Int64 i64;
00458 a >>= i64;
00459 d = (double) i64;
00460 }
00461
00462
00463
00464
00465
00466
00467 else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
00468 sal_Int32 i32;
00469 a >>= i32;
00470 d = (double)i32;
00471 }
00472 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
00473 sal_Unicode c;
00474 c = *(sal_Unicode*) a.getValue();
00475 d = (double) c;
00476 }
00477 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
00478 sal_Int16 i16;
00479 a >>= i16;
00480 d = (double) i16;
00481 }
00482 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
00483 sal_Bool b;
00484 b = *((sal_Bool * )a.getValue());
00485 d = (double) b;
00486 }
00487 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
00488 sal_Int8 i8;
00489 a >>= i8;
00490 d = (double) i8;
00491 }
00492 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
00493 sal_uInt16 i16;
00494 a >>= i16;
00495 d = (double) i16;
00496 }
00497 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
00498 sal_uInt32 i32;
00499 a >>= i32;
00500 d = (double) i32;
00501 }
00502 else {
00503 throw ::com::sun::star::lang::IllegalArgumentException();
00504 }
00505 }
00506
00507 inline void SAL_CALL convertPropertyValue( ::rtl::OUString &ow , const ::com::sun::star::uno::Any &a )
00508 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
00509 {
00510 if( ::com::sun::star::uno::TypeClass_STRING == a.getValueType().getTypeClass() ) {
00511 a >>= ow;
00512 }
00513 else {
00514 throw ::com::sun::star::lang::IllegalArgumentException();
00515 }
00516 }
00517
00518 }
00519
00520 #endif
00521
00522
00523