1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_CPPUHELPER_PROPTYPEHLP_HXX
21 #define INCLUDED_CPPUHELPER_PROPTYPEHLP_HXX
23 #include "cppuhelper/proptypehlp.h"
24 #include "com/sun/star/lang/IllegalArgumentException.hpp"
25 #include "com/sun/star/uno/TypeClass.hpp"
30 template < class target
>
31 inline void SAL_CALL
convertPropertyValue( target
&value
, const css::uno::Any
& a
)
34 if( !( a
>>= value
) ) {
35 throw css::lang::IllegalArgumentException();
39 void convertPropertyValue(bool & b
, const css::uno::Any
& a
)
42 switch( a
.getValueType().getTypeClass() ) {
43 case css::uno::TypeClass_BYTE
:
44 b
= a
.get
<sal_Int8
>() != 0;
46 case css::uno::TypeClass_SHORT
:
47 b
= a
.get
<sal_Int16
>() != 0;
49 case css::uno::TypeClass_UNSIGNED_SHORT
:
56 case css::uno::TypeClass_LONG
:
57 b
= a
.get
<sal_Int32
>() != 0;
59 case css::uno::TypeClass_UNSIGNED_LONG
:
60 b
= a
.get
<sal_uInt32
>() != 0;
62 case css::uno::TypeClass_CHAR
:
64 sal_Unicode c
= *static_cast<sal_Unicode
const *>(a
.getValue());
69 throw css::lang::IllegalArgumentException();
74 void convertPropertyValue(sal_Bool
& target
, css::uno::Any
const & source
) {
76 convertPropertyValue(b
, source
);
80 inline void SAL_CALL
convertPropertyValue( sal_Int64
& i
, const css::uno::Any
& a
)
83 switch( a
.getValueType().getTypeClass() ) {
84 case css::uno::TypeClass_BOOLEAN
:
85 i
= static_cast<sal_Int64
>(a
.get
<bool>());
87 case css::uno::TypeClass_CHAR
:
90 c
= *static_cast<sal_Unicode
const *>(a
.getValue());
91 i
= static_cast<sal_Int64
>(c
);
95 throw css::lang::IllegalArgumentException();
101 inline void SAL_CALL
convertPropertyValue( sal_uInt64
& i
, const css::uno::Any
& a
)
104 switch( a
.getValueType().getTypeClass() ) {
105 case css::uno::TypeClass_BOOLEAN
:
106 i
= static_cast<sal_uInt64
>(a
.get
<bool>());
108 case css::uno::TypeClass_CHAR
:
111 c
= *static_cast<sal_Unicode
const *>(a
.getValue());
112 i
= static_cast<sal_uInt64
>(c
);
116 throw css::lang::IllegalArgumentException();
121 inline void SAL_CALL
convertPropertyValue( sal_Int32
& i
, const css::uno::Any
& a
)
124 switch( a
.getValueType().getTypeClass() ) {
125 case css::uno::TypeClass_BOOLEAN
:
126 i
= static_cast<sal_Int32
>(a
.get
<bool>());
128 case css::uno::TypeClass_CHAR
:
131 c
= *static_cast<sal_Unicode
const *>(a
.getValue());
132 i
= static_cast<sal_Int32
>(c
);
136 throw css::lang::IllegalArgumentException();
141 inline void SAL_CALL
convertPropertyValue( sal_uInt32
& i
, const css::uno::Any
& a
)
144 switch( a
.getValueType().getTypeClass() ) {
145 case css::uno::TypeClass_BOOLEAN
:
146 i
= static_cast<sal_uInt32
>(a
.get
<bool>());
148 case css::uno::TypeClass_CHAR
:
151 c
= *static_cast<sal_Unicode
const *>(a
.getValue());
152 i
= static_cast<sal_uInt32
>(c
);
156 throw css::lang::IllegalArgumentException();
161 inline void SAL_CALL
convertPropertyValue( sal_Int16
& i
, const css::uno::Any
& a
)
164 switch( a
.getValueType().getTypeClass() ) {
165 case css::uno::TypeClass_BOOLEAN
:
166 i
= static_cast<sal_Int16
>(a
.get
<bool>());
168 case css::uno::TypeClass_CHAR
:
171 c
= *static_cast<sal_Unicode
const *>(a
.getValue());
172 i
= static_cast<sal_Int16
>(c
);
176 throw css::lang::IllegalArgumentException();
181 inline void SAL_CALL
convertPropertyValue( sal_uInt16
& i
, const css::uno::Any
& a
)
184 switch( a
.getValueType().getTypeClass() ) {
185 case css::uno::TypeClass_BOOLEAN
:
186 i
= static_cast<sal_uInt16
>(a
.get
<bool>());
188 case css::uno::TypeClass_CHAR
:
191 c
= *static_cast<sal_Unicode
const *>(a
.getValue());
192 i
= static_cast<sal_Int16
>(c
);
196 throw css::lang::IllegalArgumentException();
201 inline void SAL_CALL
convertPropertyValue( sal_Int8
& i
, const css::uno::Any
& a
)
204 switch( a
.getValueType().getTypeClass() ) {
205 case css::uno::TypeClass_BOOLEAN
:
206 i
= static_cast<sal_Int8
>(a
.get
<bool>());
209 throw css::lang::IllegalArgumentException();
214 inline void SAL_CALL
convertPropertyValue( float &f
, const css::uno::Any
&a
)
217 switch( a
.getValueType().getTypeClass() ) {
218 case css::uno::TypeClass_BOOLEAN
:
219 f
= static_cast<float>(a
.get
<bool>());
221 case css::uno::TypeClass_LONG
:
222 f
= static_cast<float>(a
.get
<sal_Int32
>());
224 case css::uno::TypeClass_UNSIGNED_LONG
:
225 f
= static_cast<float>(a
.get
<sal_uInt32
>());
227 case css::uno::TypeClass_HYPER
:
228 f
= static_cast<float>(a
.get
<sal_Int64
>());
230 case css::uno::TypeClass_UNSIGNED_HYPER
:
231 f
= static_cast<float>(a
.get
<sal_uInt64
>());
233 case css::uno::TypeClass_DOUBLE
:
234 f
= static_cast<float>(a
.get
<double>());
236 case css::uno::TypeClass_CHAR
:
239 c
= *static_cast<sal_Unicode
const *>(a
.getValue());
240 f
= static_cast<float>(c
);
244 throw css::lang::IllegalArgumentException();
249 inline void SAL_CALL
convertPropertyValue( double &d
, const css::uno::Any
&a
)
252 switch( a
.getValueType().getTypeClass() ) {
253 case css::uno::TypeClass_BOOLEAN
:
254 d
= static_cast<double>(a
.get
<bool>());
256 case css::uno::TypeClass_HYPER
:
257 d
= static_cast<double>(a
.get
<sal_Int64
>());
259 case css::uno::TypeClass_UNSIGNED_HYPER
:
260 d
= static_cast<double>(a
.get
<sal_uInt64
>());
262 case css::uno::TypeClass_CHAR
:
265 c
= *static_cast<sal_Unicode
const *>(a
.getValue());
266 d
= static_cast<double>(c
);
270 throw css::lang::IllegalArgumentException();
275 } // end namespace cppu
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */