LibreOffice: cppuhelper/proptypehlp.hxx Source File

LibreOffice LibreOffice 5.1 SDK C/C++ API Reference

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