LibreOffice LibreOffice 4.1 SDK C/C++ API Reference

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
proptypehlp.hxx
Go to the documentation of this file.
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 _CPPUHELPER_PROPTYPEHLP_HXX
20 #define _CPPUHELPER_PROPTYPEHLP_HXX
21
22 #include <cppuhelper/proptypehlp.h>
23
24 namespace cppu
25 {
26
34 template < class target >
35 inline void SAL_CALL convertPropertyValue( target &value , const ::com::sun::star::uno::Any & a)
36 {
37
38 if( !( a >>= value ) ) {
39 throw ::com::sun::star::lang::IllegalArgumentException();
40 }
41 }
42
43
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)
47 {
48 convertPropertyValue( value , (const ::com::sun::star::uno::Any & ) a );
49 }
50
54 inline void SAL_CALL convertPropertyValue( sal_Bool & b , const ::com::sun::star::uno::Any & a )
55 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
56 {
57 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
58
59 if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
60 sal_Int32 i32 = 0;
61 a >>= i32;
62 b = ( sal_Bool )i32;
63 }
64 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
65 sal_Unicode c = *(sal_Unicode*) a.getValue();
66 b = ( sal_Bool ) c;
67 }
68 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
69 sal_Int16 i16 = 0;
70 a >>= i16;
71 b = ( sal_Bool ) i16;
72 }
73 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
74 b = *((sal_Bool*)a.getValue());
75 }
76 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
77 sal_Int8 i8 = 0;
78 a >>= i8;
79 b = ( sal_Bool ) i8;
80 }
81 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
82 sal_uInt16 i16 = 0;
83 a >>= i16;
84 b = ( sal_Bool ) i16;
85 }
86 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
87 sal_uInt32 i32 = 0;
88 a >>= i32;
89 b = ( sal_Bool ) i32;
90 }
91 else {
92 throw ::com::sun::star::lang::IllegalArgumentException();
93 }
94 }
95
96 inline void SAL_CALL convertPropertyValue( sal_Int64 & i , const ::com::sun::star::uno::Any & a )
97 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
98 {
99 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
100
101 if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
102 a >>= i;
103 }
104 else if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) {
105 sal_uInt64 i64 = 0;
106 a >>= i64;
107 i = ( sal_Int64 ) i64;
108 }
109 else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
110 sal_Int32 i32 = 0;
111 a >>= i32;
112 i = ( sal_Int64 )i32;
113 }
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;
118 }
119 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
120 sal_Int16 i16 = 0;
121 a >>= i16;
122 i = ( sal_Int64 ) i16;
123 }
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;
128 }
129 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
130 sal_Int8 i8 = 0;
131 a >>= i8;
132 i = ( sal_Int64 ) i8;
133 }
134 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
135 sal_uInt16 i16 = 0;
136 a >>= i16;
137 i = ( sal_Int64 ) i16;
138 }
139 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
140 sal_uInt32 i32 = 0;
141 a >>= i32;
142 i = ( sal_Int64 ) i32;
143 }
144 else {
145 throw ::com::sun::star::lang::IllegalArgumentException();
146 }
147 }
148
149
150 inline void SAL_CALL convertPropertyValue( sal_uInt64 & i , const ::com::sun::star::uno::Any & a )
151 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
152 {
153 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
154
155 if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) {
156 a >>= i;
157 }
158 if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
159 sal_Int64 i64;
160 a >>= i64;
161 i = ( sal_uInt64 ) i64;
162 }
163 else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
164 sal_Int32 i32;
165 a >>= i32;
166 i = ( sal_uInt64 )i32;
167 }
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;
172 }
173 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
174 sal_Int16 i16;
175 a >>= i16;
176 i = ( sal_uInt64 ) i16;
177 }
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;
182 }
183 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
184 sal_Int8 i8;
185 a >>= i8;
186 i = ( sal_uInt64 ) i8;
187 }
188 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
189 sal_uInt16 i16;
190 a >>= i16;
191 i = ( sal_uInt64 ) i16;
192 }
193 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
194 sal_uInt32 i32;
195 a >>= i32;
196 i = ( sal_uInt64 ) i32;
197 }
198 else {
199 throw ::com::sun::star::lang::IllegalArgumentException();
200 }
201 }
202
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) )
207 {
208 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
209
210 if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
211 a >>= i;
212 }
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;
217 }
218 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
219 sal_Int16 i16 = 0;
220 a >>= i16;
221 i = ( sal_Int32 ) i16;
222 }
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;
227 }
228 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
229 sal_Int8 i8 = 0;
230 a >>= i8;
231 i = ( sal_Int32 ) i8;
232 }
233 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
234 sal_uInt16 i16 = 0;
235 a >>= i16;
236 i = ( sal_Int32 ) i16;
237 }
238 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
239 sal_uInt32 i32 = 0;
240 a >>= i32;
241 i = ( sal_Int32 ) i32;
242 }
243 else {
244 throw ::com::sun::star::lang::IllegalArgumentException();
245 }
246 }
247
248 inline void SAL_CALL convertPropertyValue( sal_uInt32 & i , const ::com::sun::star::uno::Any & a )
249 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
250 {
251 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
252
253 if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
254 a >>= i;
255 }
256 else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
257 sal_Int32 i32;
258 a >>= i32;
259 i = (sal_uInt32 ) i32;
260 }
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;
265 }
266 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
267 sal_Int16 i16;
268 a >>= i16;
269 i = ( sal_uInt32 ) i16;
270 }
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;
275 }
276 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
277 sal_Int8 i8;
278 a >>= i8;
279 i = ( sal_uInt32 ) i8;
280 }
281 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
282 sal_uInt16 i16;
283 a >>= i16;
284 i = ( sal_uInt32 ) i16;
285 }
286 else {
287 throw ::com::sun::star::lang::IllegalArgumentException();
288 }
289 }
290
291
292 inline void SAL_CALL convertPropertyValue( sal_Int16 & i , const ::com::sun::star::uno::Any & a )
293 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
294 {
295 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
296
297 if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
298 a >>= i;
299 }
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;
304 }
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;
309 }
310 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
311 sal_Int8 i8 = 0;
312 a >>= i8;
313 i = ( sal_Int16 ) i8;
314 }
315 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
316 sal_uInt16 i16 = 0;
317 a >>= i16;
318 i = ( sal_Int16 ) i16;
319 }
320 else {
321 throw ::com::sun::star::lang::IllegalArgumentException();
322 }
323 }
324
325 inline void SAL_CALL convertPropertyValue( sal_uInt16 & i , const ::com::sun::star::uno::Any & a )
326 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
327 {
328 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
329
330 if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
331 a >>= i;
332 }
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;
337 }
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;
342 }
343 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
344 sal_Int8 i8 = 0;
345 a >>= i8;
346 i = ( sal_Int16 ) i8;
347 }
348 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
349 sal_Int16 i16 = 0;
350 a >>= i16;
351 i = ( sal_Int16 ) i16;
352 }
353 else {
354 throw ::com::sun::star::lang::IllegalArgumentException();
355 }
356 }
357
358 inline void SAL_CALL convertPropertyValue( sal_Int8 & i , const ::com::sun::star::uno::Any & a )
359 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
360 {
361 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
362
363 if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
364 a >>= i;
365 }
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;
370 }
371 else {
372 throw ::com::sun::star::lang::IllegalArgumentException();
373 }
374 }
375
376 inline void SAL_CALL convertPropertyValue( float &f , const ::com::sun::star::uno::Any &a )
377 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
378 {
379 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
380
381 if ( ::com::sun::star::uno::TypeClass_FLOAT == tc ) {
382 a >>= f;
383 }
384 else if( ::com::sun::star::uno::TypeClass_DOUBLE == tc ) {
385 double d = 0;
386 a >>= d;
387 f = ( float ) d;
388 }
389 else if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
390 sal_Int64 i64 = 0;
391 a >>= i64;
392 f = ( float ) i64;
393 }
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;
399 }
400 */ else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
401 sal_Int32 i32 = 0;
402 a >>= i32;
403 f = ( float )i32;
404 }
405 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
406 sal_Unicode c;
407 c = *(sal_Unicode*) a.getValue();
408 f = ( float ) c;
409 }
410 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
411 sal_Int16 i16 = 0;
412 a >>= i16;
413 f = ( float ) i16;
414 }
415 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
416 sal_Bool b;
417 b = *((sal_Bool * )a.getValue());
418 f = ( float ) b;
419 }
420 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
421 sal_Int8 i8 = 0;
422 a >>= i8;
423 f = ( float ) i8;
424 }
425 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
426 sal_uInt16 i16 = 0;
427 a >>= i16;
428 f = ( float ) i16;
429 }
430 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
431 sal_uInt32 i32 = 0;
432 a >>= i32;
433 f = ( float ) i32;
434 }
435 else {
436 throw ::com::sun::star::lang::IllegalArgumentException();
437 }
438 }
439
440
441 inline void SAL_CALL convertPropertyValue( double &d , const ::com::sun::star::uno::Any &a )
442 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
443 {
444 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
445
446 if( ::com::sun::star::uno::TypeClass_DOUBLE == tc ) {
447 float f;
448 a >>= f;
449 d = ( double ) f;
450 }
451 else if ( ::com::sun::star::uno::TypeClass_FLOAT == tc ) {
452 float f;
453 a >>= f;
454 d = (double) f;
455 }
456 else if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
457 sal_Int64 i64;
458 a >>= i64;
459 d = (double) i64;
460 }
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;
466 }
467 */ else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
468 sal_Int32 i32;
469 a >>= i32;
470 d = (double)i32;
471 }
472 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
473 sal_Unicode c;
474 c = *(sal_Unicode*) a.getValue();
475 d = (double) c;
476 }
477 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
478 sal_Int16 i16;
479 a >>= i16;
480 d = (double) i16;
481 }
482 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
483 sal_Bool b;
484 b = *((sal_Bool * )a.getValue());
485 d = (double) b;
486 }
487 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
488 sal_Int8 i8;
489 a >>= i8;
490 d = (double) i8;
491 }
492 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
493 sal_uInt16 i16;
494 a >>= i16;
495 d = (double) i16;
496 }
497 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
498 sal_uInt32 i32;
499 a >>= i32;
500 d = (double) i32;
501 }
502 else {
503 throw ::com::sun::star::lang::IllegalArgumentException();
504 }
505 }
506
507 inline void SAL_CALL convertPropertyValue( ::rtl::OUString &ow , const ::com::sun::star::uno::Any &a )
508 SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
509 {
510 if( ::com::sun::star::uno::TypeClass_STRING == a.getValueType().getTypeClass() ) {
511 a >>= ow;
512 }
513 else {
514 throw ::com::sun::star::lang::IllegalArgumentException();
515 }
516 }
517
518 } // end namespace cppu
519
520 #endif
521
522
523 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:87
SAL_THROW
#define SAL_THROW(exc)
Definition of function throw clause macros.
Definition: types.h:356
cppu::convertPropertyValue
void convertPropertyValue(target &value, const ::com::sun::star::uno::Any &a)
Converts the value stored in an any to a concrete C++ type.
Definition: proptypehlp.hxx:35
sal_Unicode
sal_uInt16 sal_Unicode
Definition: types.h:134
com::sun::star::uno::Any
C++ class representing an IDL any.
Definition: Any.h:46
sal_Bool
unsigned char sal_Bool
Definition: types.h:37
proptypehlp.h
sal_Int8
signed char sal_Int8
Definition: types.h:42