bump product version to 4.1.6.2
[LibreOffice.git] / include / cppuhelper / proptypehlp.hxx
blob08107f3b91f7ac9402093eab1cf9ba055e91c384
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef _CPPUHELPER_PROPTYPEHLP_HXX
20 #define _CPPUHELPER_PROPTYPEHLP_HXX
22 #include <cppuhelper/proptypehlp.h>
24 namespace cppu
27 /** Converts the value stored in an any to a concrete C++ type.
28 The function does the same as the operator >>= () at the
29 Any class, except that it throws an IllegalArgumentException in case of
30 failures (the value cannot be extracted without data loss )
32 @exception com::sun::star::lang::IllegalArgumentException when the type could not be converted.
34 template < class target >
35 inline void SAL_CALL convertPropertyValue( target &value , const ::com::sun::star::uno::Any & a)
38 if( !( a >>= value ) ) {
39 throw ::com::sun::star::lang::IllegalArgumentException();
44 // This template is needed at least for msci4 compiler
45 template < class target >
46 inline void SAL_CALL convertPropertyValue( target &value , ::com::sun::star::uno::Any & a)
48 convertPropertyValue( value , (const ::com::sun::star::uno::Any & ) a );
51 /**
52 conversion of basic types
54 inline void SAL_CALL convertPropertyValue( sal_Bool & b , const ::com::sun::star::uno::Any & a )
55 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
57 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
59 if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
60 sal_Int32 i32 = 0;
61 a >>= i32;
62 b = ( sal_Bool )i32;
64 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
65 sal_Unicode c = *(sal_Unicode*) a.getValue();
66 b = ( sal_Bool ) c;
68 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
69 sal_Int16 i16 = 0;
70 a >>= i16;
71 b = ( sal_Bool ) i16;
73 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
74 b = *((sal_Bool*)a.getValue());
76 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
77 sal_Int8 i8 = 0;
78 a >>= i8;
79 b = ( sal_Bool ) i8;
81 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
82 sal_uInt16 i16 = 0;
83 a >>= i16;
84 b = ( sal_Bool ) i16;
86 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
87 sal_uInt32 i32 = 0;
88 a >>= i32;
89 b = ( sal_Bool ) i32;
91 else {
92 throw ::com::sun::star::lang::IllegalArgumentException();
96 inline void SAL_CALL convertPropertyValue( sal_Int64 & i , const ::com::sun::star::uno::Any & a )
97 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
99 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
101 if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
102 a >>= i;
104 else if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) {
105 sal_uInt64 i64 = 0;
106 a >>= i64;
107 i = ( sal_Int64 ) i64;
109 else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
110 sal_Int32 i32 = 0;
111 a >>= i32;
112 i = ( sal_Int64 )i32;
114 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
115 sal_Unicode c;
116 c = *(sal_Unicode *)a.getValue();
117 i = ( sal_Int64 ) c;
119 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
120 sal_Int16 i16 = 0;
121 a >>= i16;
122 i = ( sal_Int64 ) i16;
124 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
125 sal_Bool b;
126 b = *((sal_Bool * )a.getValue());
127 i = ( sal_Int64 ) b;
129 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
130 sal_Int8 i8 = 0;
131 a >>= i8;
132 i = ( sal_Int64 ) i8;
134 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
135 sal_uInt16 i16 = 0;
136 a >>= i16;
137 i = ( sal_Int64 ) i16;
139 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
140 sal_uInt32 i32 = 0;
141 a >>= i32;
142 i = ( sal_Int64 ) i32;
144 else {
145 throw ::com::sun::star::lang::IllegalArgumentException();
150 inline void SAL_CALL convertPropertyValue( sal_uInt64 & i , const ::com::sun::star::uno::Any & a )
151 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
153 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
155 if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) {
156 a >>= i;
158 if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
159 sal_Int64 i64;
160 a >>= i64;
161 i = ( sal_uInt64 ) i64;
163 else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
164 sal_Int32 i32;
165 a >>= i32;
166 i = ( sal_uInt64 )i32;
168 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
169 sal_Unicode c;
170 c = *( sal_Unicode * ) a.getValue() ;
171 i = ( sal_uInt64 ) c;
173 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
174 sal_Int16 i16;
175 a >>= i16;
176 i = ( sal_uInt64 ) i16;
178 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
179 sal_Bool b;
180 b = *((sal_Bool * )a.getValue());
181 i = ( sal_uInt64 ) b;
183 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
184 sal_Int8 i8;
185 a >>= i8;
186 i = ( sal_uInt64 ) i8;
188 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
189 sal_uInt16 i16;
190 a >>= i16;
191 i = ( sal_uInt64 ) i16;
193 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
194 sal_uInt32 i32;
195 a >>= i32;
196 i = ( sal_uInt64 ) i32;
198 else {
199 throw ::com::sun::star::lang::IllegalArgumentException();
203 // the basic types
204 // sal_Int32
205 inline void SAL_CALL convertPropertyValue( sal_Int32 & i , const ::com::sun::star::uno::Any & a )
206 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
208 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
210 if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
211 a >>= i;
213 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
214 sal_Unicode c;
215 c = *(sal_Unicode*) a.getValue();
216 i = ( sal_Int32 ) c;
218 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
219 sal_Int16 i16 = 0;
220 a >>= i16;
221 i = ( sal_Int32 ) i16;
223 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
224 sal_Bool b;
225 b = *((sal_Bool * )a.getValue());
226 i = ( sal_Int32 ) b;
228 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
229 sal_Int8 i8 = 0;
230 a >>= i8;
231 i = ( sal_Int32 ) i8;
233 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
234 sal_uInt16 i16 = 0;
235 a >>= i16;
236 i = ( sal_Int32 ) i16;
238 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
239 sal_uInt32 i32 = 0;
240 a >>= i32;
241 i = ( sal_Int32 ) i32;
243 else {
244 throw ::com::sun::star::lang::IllegalArgumentException();
248 inline void SAL_CALL convertPropertyValue( sal_uInt32 & i , const ::com::sun::star::uno::Any & a )
249 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
251 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
253 if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
254 a >>= i;
256 else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
257 sal_Int32 i32;
258 a >>= i32;
259 i = (sal_uInt32 ) i32;
261 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
262 sal_Unicode c;
263 c = *(sal_Unicode*) a.getValue();
264 i = ( sal_uInt32 ) c;
266 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
267 sal_Int16 i16;
268 a >>= i16;
269 i = ( sal_uInt32 ) i16;
271 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
272 sal_Bool b;
273 b = *((sal_Bool * )a.getValue());
274 i = ( sal_uInt32 ) b;
276 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
277 sal_Int8 i8;
278 a >>= i8;
279 i = ( sal_uInt32 ) i8;
281 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
282 sal_uInt16 i16;
283 a >>= i16;
284 i = ( sal_uInt32 ) i16;
286 else {
287 throw ::com::sun::star::lang::IllegalArgumentException();
292 inline void SAL_CALL convertPropertyValue( sal_Int16 & i , const ::com::sun::star::uno::Any & a )
293 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
295 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
297 if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
298 a >>= i;
300 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
301 sal_Unicode c;
302 c = *(sal_Unicode*) a.getValue();
303 i = ( sal_Int16 ) c;
305 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
306 sal_Bool b;
307 b = *((sal_Bool * )a.getValue());
308 i = ( sal_Int16 ) b;
310 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
311 sal_Int8 i8 = 0;
312 a >>= i8;
313 i = ( sal_Int16 ) i8;
315 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
316 sal_uInt16 i16 = 0;
317 a >>= i16;
318 i = ( sal_Int16 ) i16;
320 else {
321 throw ::com::sun::star::lang::IllegalArgumentException();
325 inline void SAL_CALL convertPropertyValue( sal_uInt16 & i , const ::com::sun::star::uno::Any & a )
326 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
328 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
330 if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
331 a >>= i;
333 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
334 sal_Unicode c;
335 c = *(sal_Unicode *) a.getValue();
336 i = ( sal_Int16 ) c;
338 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
339 sal_Bool b;
340 b = *((sal_Bool * )a.getValue());
341 i = ( sal_Int16 ) b;
343 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
344 sal_Int8 i8 = 0;
345 a >>= i8;
346 i = ( sal_Int16 ) i8;
348 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
349 sal_Int16 i16 = 0;
350 a >>= i16;
351 i = ( sal_Int16 ) i16;
353 else {
354 throw ::com::sun::star::lang::IllegalArgumentException();
358 inline void SAL_CALL convertPropertyValue( sal_Int8 & i , const ::com::sun::star::uno::Any & a )
359 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
361 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
363 if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
364 a >>= i;
366 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
367 sal_Bool b;
368 b = *((sal_Bool * )a.getValue());
369 i = ( sal_Int8 ) b;
371 else {
372 throw ::com::sun::star::lang::IllegalArgumentException();
376 inline void SAL_CALL convertPropertyValue( float &f , const ::com::sun::star::uno::Any &a )
377 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
379 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
381 if ( ::com::sun::star::uno::TypeClass_FLOAT == tc ) {
382 a >>= f;
384 else if( ::com::sun::star::uno::TypeClass_DOUBLE == tc ) {
385 double d = 0;
386 a >>= d;
387 f = ( float ) d;
389 else if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
390 sal_Int64 i64 = 0;
391 a >>= i64;
392 f = ( float ) i64;
394 // msci 4 does not support this conversion
395 /* else if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) {
396 sal_uInt64 i64;
397 a >>= i64;
398 f = ( float ) i64;
400 */ else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
401 sal_Int32 i32 = 0;
402 a >>= i32;
403 f = ( float )i32;
405 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
406 sal_Unicode c;
407 c = *(sal_Unicode*) a.getValue();
408 f = ( float ) c;
410 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
411 sal_Int16 i16 = 0;
412 a >>= i16;
413 f = ( float ) i16;
415 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
416 sal_Bool b;
417 b = *((sal_Bool * )a.getValue());
418 f = ( float ) b;
420 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
421 sal_Int8 i8 = 0;
422 a >>= i8;
423 f = ( float ) i8;
425 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
426 sal_uInt16 i16 = 0;
427 a >>= i16;
428 f = ( float ) i16;
430 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
431 sal_uInt32 i32 = 0;
432 a >>= i32;
433 f = ( float ) i32;
435 else {
436 throw ::com::sun::star::lang::IllegalArgumentException();
441 inline void SAL_CALL convertPropertyValue( double &d , const ::com::sun::star::uno::Any &a )
442 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
444 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
446 if( ::com::sun::star::uno::TypeClass_DOUBLE == tc ) {
447 float f;
448 a >>= f;
449 d = ( double ) f;
451 else if ( ::com::sun::star::uno::TypeClass_FLOAT == tc ) {
452 float f;
453 a >>= f;
454 d = (double) f;
456 else if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
457 sal_Int64 i64;
458 a >>= i64;
459 d = (double) i64;
461 // msci 4 does not support this
462 /* else if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) {
463 sal_uInt64 i64;
464 a >>= i64;
465 d = (double) i64;
467 */ else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
468 sal_Int32 i32;
469 a >>= i32;
470 d = (double)i32;
472 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
473 sal_Unicode c;
474 c = *(sal_Unicode*) a.getValue();
475 d = (double) c;
477 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
478 sal_Int16 i16;
479 a >>= i16;
480 d = (double) i16;
482 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
483 sal_Bool b;
484 b = *((sal_Bool * )a.getValue());
485 d = (double) b;
487 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
488 sal_Int8 i8;
489 a >>= i8;
490 d = (double) i8;
492 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
493 sal_uInt16 i16;
494 a >>= i16;
495 d = (double) i16;
497 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
498 sal_uInt32 i32;
499 a >>= i32;
500 d = (double) i32;
502 else {
503 throw ::com::sun::star::lang::IllegalArgumentException();
507 inline void SAL_CALL convertPropertyValue( ::rtl::OUString &ow , const ::com::sun::star::uno::Any &a )
508 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
510 if( ::com::sun::star::uno::TypeClass_STRING == a.getValueType().getTypeClass() ) {
511 a >>= ow;
513 else {
514 throw ::com::sun::star::lang::IllegalArgumentException();
518 } // end namespace cppu
520 #endif
523 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */