My Project
UDK 3.2.7 C/C++ API Reference
 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  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 #ifndef _CPPUHELPER_PROPTYPEHLP_HXX
29 #define _CPPUHELPER_PROPTYPEHLP_HXX
30 
31 #include <cppuhelper/proptypehlp.h>
32 
33 namespace cppu
34 {
35 
43 template < class target >
44 inline void SAL_CALL convertPropertyValue( target &value , const ::com::sun::star::uno::Any & a)
45 {
46 
47  if( !( a >>= value ) ) {
48  throw ::com::sun::star::lang::IllegalArgumentException();
49  }
50 }
51 
52 
53 // This template is needed at least for msci4 compiler
54 template < class target >
55 inline void SAL_CALL convertPropertyValue( target &value , ::com::sun::star::uno::Any & a)
56 {
57  convertPropertyValue( value , (const ::com::sun::star::uno::Any & ) a );
58 }
59 
63 inline void SAL_CALL convertPropertyValue( sal_Bool & b , const ::com::sun::star::uno::Any & a )
64  SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
65 {
66  const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
67 
68  if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
69  sal_Int32 i32 = 0;
70  a >>= i32;
71  b = ( sal_Bool )i32;
72  }
73  else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
74  sal_Unicode c = *(sal_Unicode*) a.getValue();
75  b = ( sal_Bool ) c;
76  }
77  else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
78  sal_Int16 i16 = 0;
79  a >>= i16;
80  b = ( sal_Bool ) i16;
81  }
82  else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
83  b = *((sal_Bool*)a.getValue());
84  }
85  else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
86  sal_Int8 i8 = 0;
87  a >>= i8;
88  b = ( sal_Bool ) i8;
89  }
90  else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
91  sal_uInt16 i16 = 0;
92  a >>= i16;
93  b = ( sal_Bool ) i16;
94  }
95  else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
96  sal_uInt32 i32 = 0;
97  a >>= i32;
98  b = ( sal_Bool ) i32;
99  }
100  else {
101  throw ::com::sun::star::lang::IllegalArgumentException();
102  }
103 }
104 
105 inline void SAL_CALL convertPropertyValue( sal_Int64 & i , const ::com::sun::star::uno::Any & a )
106  SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
107 {
108  const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
109 
110  if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
111  a >>= i;
112  }
113  else if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) {
114  sal_uInt64 i64 = 0;
115  a >>= i64;
116  i = ( sal_Int64 ) i64;
117  }
118  else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
119  sal_Int32 i32 = 0;
120  a >>= i32;
121  i = ( sal_Int64 )i32;
122  }
123  else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
124  sal_Unicode c;
125  c = *(sal_Unicode *)a.getValue();
126  i = ( sal_Int64 ) c;
127  }
128  else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
129  sal_Int16 i16 = 0;
130  a >>= i16;
131  i = ( sal_Int64 ) i16;
132  }
133  else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
134  sal_Bool b;
135  b = *((sal_Bool * )a.getValue());
136  i = ( sal_Int64 ) b;
137  }
138  else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
139  sal_Int8 i8 = 0;
140  a >>= i8;
141  i = ( sal_Int64 ) i8;
142  }
143  else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
144  sal_uInt16 i16 = 0;
145  a >>= i16;
146  i = ( sal_Int64 ) i16;
147  }
148  else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
149  sal_uInt32 i32 = 0;
150  a >>= i32;
151  i = ( sal_Int64 ) i32;
152  }
153  else {
154  throw ::com::sun::star::lang::IllegalArgumentException();
155  }
156 }
157 
158 
159 inline void SAL_CALL convertPropertyValue( sal_uInt64 & i , const ::com::sun::star::uno::Any & a )
160  SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
161 {
162  const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
163 
164  if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) {
165  a >>= i;
166  }
167  if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
168  sal_Int64 i64;
169  a >>= i64;
170  i = ( sal_uInt64 ) i64;
171  }
172  else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
173  sal_Int32 i32;
174  a >>= i32;
175  i = ( sal_uInt64 )i32;
176  }
177  else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
178  sal_Unicode c;
179  c = *( sal_Unicode * ) a.getValue() ;
180  i = ( sal_uInt64 ) c;
181  }
182  else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
183  sal_Int16 i16;
184  a >>= i16;
185  i = ( sal_uInt64 ) i16;
186  }
187  else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
188  sal_Bool b;
189  b = *((sal_Bool * )a.getValue());
190  i = ( sal_uInt64 ) b;
191  }
192  else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
193  sal_Int8 i8;
194  a >>= i8;
195  i = ( sal_uInt64 ) i8;
196  }
197  else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
198  sal_uInt16 i16;
199  a >>= i16;
200  i = ( sal_uInt64 ) i16;
201  }
202  else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
203  sal_uInt32 i32;
204  a >>= i32;
205  i = ( sal_uInt64 ) i32;
206  }
207  else {
208  throw ::com::sun::star::lang::IllegalArgumentException();
209  }
210 }
211 
212 // the basic types
213 // sal_Int32
214 inline void SAL_CALL convertPropertyValue( sal_Int32 & i , const ::com::sun::star::uno::Any & a )
215  SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
216 {
217  const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
218 
219  if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
220  a >>= i;
221  }
222  else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
223  sal_Unicode c;
224  c = *(sal_Unicode*) a.getValue();
225  i = ( sal_Int32 ) c;
226  }
227  else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
228  sal_Int16 i16 = 0;
229  a >>= i16;
230  i = ( sal_Int32 ) i16;
231  }
232  else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
233  sal_Bool b;
234  b = *((sal_Bool * )a.getValue());
235  i = ( sal_Int32 ) b;
236  }
237  else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
238  sal_Int8 i8 = 0;
239  a >>= i8;
240  i = ( sal_Int32 ) i8;
241  }
242  else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
243  sal_uInt16 i16 = 0;
244  a >>= i16;
245  i = ( sal_Int32 ) i16;
246  }
247  else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
248  sal_uInt32 i32 = 0;
249  a >>= i32;
250  i = ( sal_Int32 ) i32;
251  }
252  else {
253  throw ::com::sun::star::lang::IllegalArgumentException();
254  }
255 }
256 
257 inline void SAL_CALL convertPropertyValue( sal_uInt32 & i , const ::com::sun::star::uno::Any & a )
258  SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
259 {
260  const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
261 
262  if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
263  a >>= i;
264  }
265  else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
266  sal_Int32 i32;
267  a >>= i32;
268  i = (sal_uInt32 ) i32;
269  }
270  else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
271  sal_Unicode c;
272  c = *(sal_Unicode*) a.getValue();
273  i = ( sal_uInt32 ) c;
274  }
275  else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
276  sal_Int16 i16;
277  a >>= i16;
278  i = ( sal_uInt32 ) i16;
279  }
280  else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
281  sal_Bool b;
282  b = *((sal_Bool * )a.getValue());
283  i = ( sal_uInt32 ) b;
284  }
285  else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
286  sal_Int8 i8;
287  a >>= i8;
288  i = ( sal_uInt32 ) i8;
289  }
290  else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
291  sal_uInt16 i16;
292  a >>= i16;
293  i = ( sal_uInt32 ) i16;
294  }
295  else {
296  throw ::com::sun::star::lang::IllegalArgumentException();
297  }
298 }
299 
300 
301 inline void SAL_CALL convertPropertyValue( sal_Int16 & i , const ::com::sun::star::uno::Any & a )
302  SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
303 {
304  const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
305 
306  if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
307  a >>= i;
308  }
309  else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
310  sal_Unicode c;
311  c = *(sal_Unicode*) a.getValue();
312  i = ( sal_Int16 ) c;
313  }
314  else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
315  sal_Bool b;
316  b = *((sal_Bool * )a.getValue());
317  i = ( sal_Int16 ) b;
318  }
319  else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
320  sal_Int8 i8 = 0;
321  a >>= i8;
322  i = ( sal_Int16 ) i8;
323  }
324  else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
325  sal_uInt16 i16 = 0;
326  a >>= i16;
327  i = ( sal_Int16 ) i16;
328  }
329  else {
330  throw ::com::sun::star::lang::IllegalArgumentException();
331  }
332 }
333 
334 inline void SAL_CALL convertPropertyValue( sal_uInt16 & i , const ::com::sun::star::uno::Any & a )
335  SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
336 {
337  const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
338 
339  if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
340  a >>= i;
341  }
342  else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
343  sal_Unicode c;
344  c = *(sal_Unicode *) a.getValue();
345  i = ( sal_Int16 ) c;
346  }
347  else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
348  sal_Bool b;
349  b = *((sal_Bool * )a.getValue());
350  i = ( sal_Int16 ) b;
351  }
352  else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
353  sal_Int8 i8 = 0;
354  a >>= i8;
355  i = ( sal_Int16 ) i8;
356  }
357  else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
358  sal_Int16 i16 = 0;
359  a >>= i16;
360  i = ( sal_Int16 ) i16;
361  }
362  else {
363  throw ::com::sun::star::lang::IllegalArgumentException();
364  }
365 }
366 
367 inline void SAL_CALL convertPropertyValue( sal_Int8 & i , const ::com::sun::star::uno::Any & a )
368  SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
369 {
370  const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
371 
372  if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
373  a >>= i;
374  }
375  else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
376  sal_Bool b;
377  b = *((sal_Bool * )a.getValue());
378  i = ( sal_Int8 ) b;
379  }
380  else {
381  throw ::com::sun::star::lang::IllegalArgumentException();
382  }
383 }
384 
385 inline void SAL_CALL convertPropertyValue( float &f , const ::com::sun::star::uno::Any &a )
386  SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
387 {
388  const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
389 
390  if ( ::com::sun::star::uno::TypeClass_FLOAT == tc ) {
391  a >>= f;
392  }
393  else if( ::com::sun::star::uno::TypeClass_DOUBLE == tc ) {
394  double d = 0;
395  a >>= d;
396  f = ( float ) d;
397  }
398  else if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
399  sal_Int64 i64 = 0;
400  a >>= i64;
401  f = ( float ) i64;
402  }
403  // msci 4 does not support this conversion
404 /* else if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) {
405  sal_uInt64 i64;
406  a >>= i64;
407  f = ( float ) i64;
408  }
409 */ else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
410  sal_Int32 i32 = 0;
411  a >>= i32;
412  f = ( float )i32;
413  }
414  else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
415  sal_Unicode c;
416  c = *(sal_Unicode*) a.getValue();
417  f = ( float ) c;
418  }
419  else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
420  sal_Int16 i16 = 0;
421  a >>= i16;
422  f = ( float ) i16;
423  }
424  else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
425  sal_Bool b;
426  b = *((sal_Bool * )a.getValue());
427  f = ( float ) b;
428  }
429  else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
430  sal_Int8 i8 = 0;
431  a >>= i8;
432  f = ( float ) i8;
433  }
434  else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
435  sal_uInt16 i16 = 0;
436  a >>= i16;
437  f = ( float ) i16;
438  }
439  else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
440  sal_uInt32 i32 = 0;
441  a >>= i32;
442  f = ( float ) i32;
443  }
444  else {
445  throw ::com::sun::star::lang::IllegalArgumentException();
446  }
447 }
448 
449 
450 inline void SAL_CALL convertPropertyValue( double &d , const ::com::sun::star::uno::Any &a )
451  SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
452 {
453  const enum ::com::sun::star::uno::TypeClass tc = a.getValueType().getTypeClass();
454 
455  if( ::com::sun::star::uno::TypeClass_DOUBLE == tc ) {
456  float f;
457  a >>= f;
458  d = ( double ) f;
459  }
460  else if ( ::com::sun::star::uno::TypeClass_FLOAT == tc ) {
461  float f;
462  a >>= f;
463  d = (double) f;
464  }
465  else if( ::com::sun::star::uno::TypeClass_HYPER == tc ) {
466  sal_Int64 i64;
467  a >>= i64;
468  d = (double) i64;
469  }
470  // msci 4 does not support this
471 /* else if( ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER == tc ) {
472  sal_uInt64 i64;
473  a >>= i64;
474  d = (double) i64;
475  }
476 */ else if( ::com::sun::star::uno::TypeClass_LONG == tc ) {
477  sal_Int32 i32;
478  a >>= i32;
479  d = (double)i32;
480  }
481  else if ( ::com::sun::star::uno::TypeClass_CHAR == tc ) {
482  sal_Unicode c;
483  c = *(sal_Unicode*) a.getValue();
484  d = (double) c;
485  }
486  else if ( ::com::sun::star::uno::TypeClass_SHORT == tc ) {
487  sal_Int16 i16;
488  a >>= i16;
489  d = (double) i16;
490  }
491  else if ( ::com::sun::star::uno::TypeClass_BOOLEAN == tc ) {
492  sal_Bool b;
493  b = *((sal_Bool * )a.getValue());
494  d = (double) b;
495  }
496  else if ( ::com::sun::star::uno::TypeClass_BYTE == tc ) {
497  sal_Int8 i8;
498  a >>= i8;
499  d = (double) i8;
500  }
501  else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT == tc ) {
502  sal_uInt16 i16;
503  a >>= i16;
504  d = (double) i16;
505  }
506  else if ( ::com::sun::star::uno::TypeClass_UNSIGNED_LONG == tc ) {
507  sal_uInt32 i32;
508  a >>= i32;
509  d = (double) i32;
510  }
511  else {
512  throw ::com::sun::star::lang::IllegalArgumentException();
513  }
514 }
515 
516 inline void SAL_CALL convertPropertyValue( ::rtl::OUString &ow , const ::com::sun::star::uno::Any &a )
517  SAL_THROW( (::com::sun::star::lang::IllegalArgumentException) )
518 {
519  if( ::com::sun::star::uno::TypeClass_STRING == a.getValueType().getTypeClass() ) {
520  a >>= ow;
521  }
522  else {
523  throw ::com::sun::star::lang::IllegalArgumentException();
524  }
525 }
526 
527 } // end namespace cppu
528 
529 #endif
530 
531 
532 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */