LibreOffice LibreOffice 4.4 SDK C/C++ API Reference

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

- File List
- File Members

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 INCLUDED_CPPUHELPER_PROPTYPEHLP_HXX
20 #define INCLUDED_CPPUHELPER_PROPTYPEHLP_HXX
21
22 #include <cppuhelper/proptypehlp.h>
23 #include <com/sun/star/lang/IllegalArgumentException.hpp>
24 #include <com/sun/star/uno/TypeClass.hpp>
25
26 namespace cppu
27 {
28
36 template < class target >
37 inline void SAL_CALL convertPropertyValue( target &value , const ::com::sun::star::uno::Any & a)
38 {
39
40 if( !( a >>= value ) ) {
41 throw ::com::sun::star::lang::IllegalArgumentException();
42 }
43 }
44
45
46 // This template is needed at least for msci4 compiler
47 template < class target >
48 inline void SAL_CALL convertPropertyValue( target &value , ::com::sun::star::uno::Any & a)
49 {
50 convertPropertyValue( value , (const ::com::sun::star::uno::Any & ) a );
51 }
52
56 inline void SAL_CALL convertPropertyValue( sal_Bool & b , const ::com::sun::star::uno::Any & a )
57 {
58 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
59
60 if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
61 sal_Int32 i32 = 0;
62 a >>= i32;
63 b = i32 != 0;
64 }
65 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
66 sal_Unicode c = *(sal_Unicode*) a.getValue();
67 b = c != 0;
68 }
69 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
70 sal_Int16 i16 = 0;
71 a >>= i16;
72 b = i16 != 0;
73 }
74 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
75 b = *((sal_Bool*)a.getValue());
76 }
77 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
78 sal_Int8 i8 = 0;
79 a >>= i8;
80 b = i8 != 0;
81 }
82 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
83 sal_uInt16 i16 = 0;
84 a >>= i16;
85 b = i16 != 0;
86 }
87 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
88 sal_uInt32 i32 = 0;
89 a >>= i32;
90 b = i32 != 0;
91 }
92 else {
93 throw ::com::sun::star::lang::IllegalArgumentException();
94 }
95 }
96
97 inline void SAL_CALL convertPropertyValue( sal_Int64 & i , const ::com::sun::star::uno::Any & a )
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 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 {
152 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
153
154 if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) {
155 a >>= i;
156 }
157 if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
158 sal_Int64 i64;
159 a >>= i64;
160 i = ( sal_uInt64 ) i64;
161 }
162 else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
163 sal_Int32 i32;
164 a >>= i32;
165 i = ( sal_uInt64 )i32;
166 }
167 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
168 sal_Unicode c;
169 c = *( sal_Unicode * ) a.getValue() ;
170 i = ( sal_uInt64 ) c;
171 }
172 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
173 sal_Int16 i16;
174 a >>= i16;
175 i = ( sal_uInt64 ) i16;
176 }
177 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
178 bool b;
179 b = *((sal_Bool * )a.getValue());
180 i = ( sal_uInt64 ) b;
181 }
182 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
183 sal_Int8 i8;
184 a >>= i8;
185 i = ( sal_uInt64 ) i8;
186 }
187 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
188 sal_uInt16 i16;
189 a >>= i16;
190 i = ( sal_uInt64 ) i16;
191 }
192 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
193 sal_uInt32 i32;
194 a >>= i32;
195 i = ( sal_uInt64 ) i32;
196 }
197 else {
198 throw ::com::sun::star::lang::IllegalArgumentException();
199 }
200 }
201
202 // the basic types
203 // sal_Int32
204 inline void SAL_CALL convertPropertyValue( sal_Int32 & i , const ::com::sun::star::uno::Any & a )
205 {
206 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
207
208 if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
209 a >>= i;
210 }
211 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
212 sal_Unicode c;
213 c = *(sal_Unicode*) a.getValue();
214 i = ( sal_Int32 ) c;
215 }
216 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
217 sal_Int16 i16 = 0;
218 a >>= i16;
219 i = ( sal_Int32 ) i16;
220 }
221 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
222 bool b;
223 b = *((sal_Bool * )a.getValue());
224 i = ( sal_Int32 ) b;
225 }
226 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
227 sal_Int8 i8 = 0;
228 a >>= i8;
229 i = ( sal_Int32 ) i8;
230 }
231 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
232 sal_uInt16 i16 = 0;
233 a >>= i16;
234 i = ( sal_Int32 ) i16;
235 }
236 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
237 sal_uInt32 i32 = 0;
238 a >>= i32;
239 i = ( sal_Int32 ) i32;
240 }
241 else {
242 throw ::com::sun::star::lang::IllegalArgumentException();
243 }
244 }
245
246 inline void SAL_CALL convertPropertyValue( sal_uInt32 & i , const ::com::sun::star::uno::Any & a )
247 {
248 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
249
250 if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
251 a >>= i;
252 }
253 else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
254 sal_Int32 i32;
255 a >>= i32;
256 i = (sal_uInt32 ) i32;
257 }
258 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
259 sal_Unicode c;
260 c = *(sal_Unicode*) a.getValue();
261 i = ( sal_uInt32 ) c;
262 }
263 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
264 sal_Int16 i16;
265 a >>= i16;
266 i = ( sal_uInt32 ) i16;
267 }
268 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
269 bool b;
270 b = *((sal_Bool * )a.getValue());
271 i = ( sal_uInt32 ) b;
272 }
273 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
274 sal_Int8 i8;
275 a >>= i8;
276 i = ( sal_uInt32 ) i8;
277 }
278 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
279 sal_uInt16 i16;
280 a >>= i16;
281 i = ( sal_uInt32 ) i16;
282 }
283 else {
284 throw ::com::sun::star::lang::IllegalArgumentException();
285 }
286 }
287
288
289 inline void SAL_CALL convertPropertyValue( sal_Int16 & i , const ::com::sun::star::uno::Any & a )
290 {
291 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
292
293 if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
294 a >>= i;
295 }
296 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
297 sal_Unicode c;
298 c = *(sal_Unicode*) a.getValue();
299 i = ( sal_Int16 ) c;
300 }
301 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
302 bool b;
303 b = *((sal_Bool * )a.getValue());
304 i = ( sal_Int16 ) b;
305 }
306 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
307 sal_Int8 i8 = 0;
308 a >>= i8;
309 i = ( sal_Int16 ) i8;
310 }
311 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
312 sal_uInt16 i16 = 0;
313 a >>= i16;
314 i = ( sal_Int16 ) i16;
315 }
316 else {
317 throw ::com::sun::star::lang::IllegalArgumentException();
318 }
319 }
320
321 inline void SAL_CALL convertPropertyValue( sal_uInt16 & i , const ::com::sun::star::uno::Any & a )
322 {
323 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
324
325 if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
326 a >>= i;
327 }
328 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
329 sal_Unicode c;
330 c = *(sal_Unicode *) a.getValue();
331 i = ( sal_Int16 ) c;
332 }
333 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
334 bool b;
335 b = *((sal_Bool * )a.getValue());
336 i = ( sal_Int16 ) b;
337 }
338 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
339 sal_Int8 i8 = 0;
340 a >>= i8;
341 i = ( sal_Int16 ) i8;
342 }
343 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
344 sal_Int16 i16 = 0;
345 a >>= i16;
346 i = ( sal_Int16 ) i16;
347 }
348 else {
349 throw ::com::sun::star::lang::IllegalArgumentException();
350 }
351 }
352
353 inline void SAL_CALL convertPropertyValue( sal_Int8 & i , const ::com::sun::star::uno::Any & a )
354 {
355 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
356
357 if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
358 a >>= i;
359 }
360 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
361 bool b;
362 b = *((sal_Bool * )a.getValue());
363 i = ( sal_Int8 ) b;
364 }
365 else {
366 throw ::com::sun::star::lang::IllegalArgumentException();
367 }
368 }
369
370 inline void SAL_CALL convertPropertyValue( float &f , const ::com::sun::star::uno::Any &a )
371 {
372 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
373
374 if ( ::com::sun::star::uno::TypeClass_FLOAT == tc ) {
375 a >>= f;
376 }
377 else if( ::com::sun::star::uno::TypeClass_DOUBLE == tc ) {
378 double d = 0;
379 a >>= d;
380 f = ( float ) d;
381 }
382 else if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
383 sal_Int64 i64 = 0;
384 a >>= i64;
385 f = ( float ) i64;
386 }
387 // msci 4 does not support this conversion
388 /* else if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) {
389 sal_uInt64 i64;
390 a >>= i64;
391 f = ( float ) i64;
392 }
393 */ else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
394 sal_Int32 i32 = 0;
395 a >>= i32;
396 f = ( float )i32;
397 }
398 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
399 sal_Unicode c;
400 c = *(sal_Unicode*) a.getValue();
401 f = ( float ) c;
402 }
403 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
404 sal_Int16 i16 = 0;
405 a >>= i16;
406 f = ( float ) i16;
407 }
408 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
409 bool b;
410 b = *((sal_Bool * )a.getValue());
411 f = ( float ) b;
412 }
413 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
414 sal_Int8 i8 = 0;
415 a >>= i8;
416 f = ( float ) i8;
417 }
418 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
419 sal_uInt16 i16 = 0;
420 a >>= i16;
421 f = ( float ) i16;
422 }
423 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
424 sal_uInt32 i32 = 0;
425 a >>= i32;
426 f = ( float ) i32;
427 }
428 else {
429 throw ::com::sun::star::lang::IllegalArgumentException();
430 }
431 }
432
433
434 inline void SAL_CALL convertPropertyValue( double &d , const ::com::sun::star::uno::Any &a )
435 {
436 const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
437
438 if( ::com::sun::star::uno::TypeClass_DOUBLE == tc ) {
439 float f;
440 a >>= f;
441 d = ( double ) f;
442 }
443 else if ( ::com::sun::star::uno::TypeClass_FLOAT == tc ) {
444 float f;
445 a >>= f;
446 d = (double) f;
447 }
448 else if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
449 sal_Int64 i64;
450 a >>= i64;
451 d = (double) i64;
452 }
453 // msci 4 does not support this
454 /* else if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) {
455 sal_uInt64 i64;
456 a >>= i64;
457 d = (double) i64;
458 }
459 */ else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
460 sal_Int32 i32;
461 a >>= i32;
462 d = (double)i32;
463 }
464 else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
465 sal_Unicode c;
466 c = *(sal_Unicode*) a.getValue();
467 d = (double) c;
468 }
469 else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
470 sal_Int16 i16;
471 a >>= i16;
472 d = (double) i16;
473 }
474 else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
475 bool b;
476 b = *((sal_Bool * )a.getValue());
477 d = (double) b;
478 }
479 else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
480 sal_Int8 i8;
481 a >>= i8;
482 d = (double) i8;
483 }
484 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
485 sal_uInt16 i16;
486 a >>= i16;
487 d = (double) i16;
488 }
489 else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
490 sal_uInt32 i32;
491 a >>= i32;
492 d = (double) i32;
493 }
494 else {
495 throw ::com::sun::star::lang::IllegalArgumentException();
496 }
497 }
498
499 inline void SAL_CALL convertPropertyValue( ::rtl::OUString &ow , const ::com::sun::star::uno::Any &a )
500 {
501 if( ::com::sun::star::uno::TypeClass_STRING == a.getValueType().getTypeClass() ) {
502 a >>= ow;
503 }
504 else {
505 throw ::com::sun::star::lang::IllegalArgumentException();
506 }
507 }
508
509 } // end namespace cppu
510
511 #endif
512
513
514 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Bool
unsigned char sal_Bool
Definition: types.h:48
cppu
Definition: Enterable.hxx:26
proptypehlp.h
sal_Int8
signed char sal_Int8
Definition: types.h:53
com::sun::star::uno::Any
C++ class representing an IDL any.
Definition: Any.h:49
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:81
sal_Unicode
sal_uInt16 sal_Unicode
Definition: types.h:152
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:37