LibreOffice: cppuhelper/proptypehlp.hxx Source File

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