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 .
21 * This file is part of LibreOffice published API.
24 #ifndef INCLUDED_CPPUHELPER_PROPTYPEHLP_HXX
25 #define INCLUDED_CPPUHELPER_PROPTYPEHLP_HXX
27 #include "cppuhelper/proptypehlp.h"
28 #include "com/sun/star/lang/IllegalArgumentException.hpp"
29 #include "com/sun/star/uno/TypeClass.hpp"
34 template < class target
>
35 inline void SAL_CALL
convertPropertyValue( target
&value
, const css::uno::Any
& a
)
38 if( !( a
>>= value
) ) {
39 throw css::lang::IllegalArgumentException();
43 void convertPropertyValue(bool & b
, const css::uno::Any
& a
)
48 switch( a
.getValueType().getTypeClass() ) {
49 case css::uno::TypeClass_BYTE
:
50 b
= a
.get
<sal_Int8
>() != 0;
52 case css::uno::TypeClass_SHORT
:
53 b
= a
.get
<sal_Int16
>() != 0;
55 case css::uno::TypeClass_UNSIGNED_SHORT
:
62 case css::uno::TypeClass_LONG
:
63 b
= a
.get
<sal_Int32
>() != 0;
65 case css::uno::TypeClass_UNSIGNED_LONG
:
66 b
= a
.get
<sal_uInt32
>() != 0;
68 case css::uno::TypeClass_CHAR
:
70 sal_Unicode c
= *static_cast<sal_Unicode
const *>(a
.getValue());
75 throw css::lang::IllegalArgumentException();
79 void convertPropertyValue(sal_Bool
& target
, css::uno::Any
const & source
) {
81 convertPropertyValue(b
, source
);
85 inline void SAL_CALL
convertPropertyValue( sal_Int64
& i
, const css::uno::Any
& a
)
88 switch( a
.getValueType().getTypeClass() ) {
89 case css::uno::TypeClass_BOOLEAN
:
90 i
= static_cast<sal_Int64
>(a
.get
<bool>());
92 case css::uno::TypeClass_CHAR
:
95 c
= *static_cast<sal_Unicode
const *>(a
.getValue());
96 i
= static_cast<sal_Int64
>(c
);
100 throw css::lang::IllegalArgumentException();
106 inline void SAL_CALL
convertPropertyValue( sal_uInt64
& i
, const css::uno::Any
& a
)
109 switch( a
.getValueType().getTypeClass() ) {
110 case css::uno::TypeClass_BOOLEAN
:
111 i
= static_cast<sal_uInt64
>(a
.get
<bool>());
113 case css::uno::TypeClass_CHAR
:
116 c
= *static_cast<sal_Unicode
const *>(a
.getValue());
117 i
= static_cast<sal_uInt64
>(c
);
121 throw css::lang::IllegalArgumentException();
126 inline void SAL_CALL
convertPropertyValue( sal_Int32
& i
, const css::uno::Any
& a
)
129 switch( a
.getValueType().getTypeClass() ) {
130 case css::uno::TypeClass_BOOLEAN
:
131 i
= static_cast<sal_Int32
>(a
.get
<bool>());
133 case css::uno::TypeClass_CHAR
:
136 c
= *static_cast<sal_Unicode
const *>(a
.getValue());
137 i
= static_cast<sal_Int32
>(c
);
141 throw css::lang::IllegalArgumentException();
146 inline void SAL_CALL
convertPropertyValue( sal_uInt32
& i
, const css::uno::Any
& a
)
149 switch( a
.getValueType().getTypeClass() ) {
150 case css::uno::TypeClass_BOOLEAN
:
151 i
= static_cast<sal_uInt32
>(a
.get
<bool>());
153 case css::uno::TypeClass_CHAR
:
156 c
= *static_cast<sal_Unicode
const *>(a
.getValue());
157 i
= static_cast<sal_uInt32
>(c
);
161 throw css::lang::IllegalArgumentException();
166 inline void SAL_CALL
convertPropertyValue( sal_Int16
& i
, const css::uno::Any
& a
)
169 switch( a
.getValueType().getTypeClass() ) {
170 case css::uno::TypeClass_BOOLEAN
:
171 i
= static_cast<sal_Int16
>(a
.get
<bool>());
173 case css::uno::TypeClass_CHAR
:
176 c
= *static_cast<sal_Unicode
const *>(a
.getValue());
177 i
= static_cast<sal_Int16
>(c
);
181 throw css::lang::IllegalArgumentException();
186 inline void SAL_CALL
convertPropertyValue( sal_uInt16
& i
, const css::uno::Any
& a
)
189 switch( a
.getValueType().getTypeClass() ) {
190 case css::uno::TypeClass_BOOLEAN
:
191 i
= static_cast<sal_uInt16
>(a
.get
<bool>());
193 case css::uno::TypeClass_CHAR
:
196 c
= *static_cast<sal_Unicode
const *>(a
.getValue());
197 i
= static_cast<sal_Int16
>(c
);
201 throw css::lang::IllegalArgumentException();
206 inline void SAL_CALL
convertPropertyValue( sal_Int8
& i
, const css::uno::Any
& a
)
209 switch( a
.getValueType().getTypeClass() ) {
210 case css::uno::TypeClass_BOOLEAN
:
211 i
= static_cast<sal_Int8
>(a
.get
<bool>());
214 throw css::lang::IllegalArgumentException();
219 inline void SAL_CALL
convertPropertyValue( float &f
, const css::uno::Any
&a
)
224 switch( a
.getValueType().getTypeClass() ) {
225 case css::uno::TypeClass_BOOLEAN
:
226 f
= static_cast<float>(a
.get
<bool>());
228 case css::uno::TypeClass_LONG
:
229 f
= static_cast<float>(a
.get
<sal_Int32
>());
231 case css::uno::TypeClass_UNSIGNED_LONG
:
232 f
= static_cast<float>(a
.get
<sal_uInt32
>());
234 case css::uno::TypeClass_HYPER
:
235 f
= static_cast<float>(a
.get
<sal_Int64
>());
237 case css::uno::TypeClass_UNSIGNED_HYPER
:
238 f
= static_cast<float>(a
.get
<sal_uInt64
>());
240 case css::uno::TypeClass_DOUBLE
:
241 f
= static_cast<float>(a
.get
<double>());
243 case css::uno::TypeClass_CHAR
:
246 c
= *static_cast<sal_Unicode
const *>(a
.getValue());
247 f
= static_cast<float>(c
);
251 throw css::lang::IllegalArgumentException();
255 inline void SAL_CALL
convertPropertyValue( double &d
, const css::uno::Any
&a
)
260 switch( a
.getValueType().getTypeClass() ) {
261 case css::uno::TypeClass_BOOLEAN
:
262 d
= static_cast<double>(a
.get
<bool>());
264 case css::uno::TypeClass_HYPER
:
265 d
= static_cast<double>(a
.get
<sal_Int64
>());
267 case css::uno::TypeClass_UNSIGNED_HYPER
:
268 d
= static_cast<double>(a
.get
<sal_uInt64
>());
270 case css::uno::TypeClass_CHAR
:
273 c
= *static_cast<sal_Unicode
const *>(a
.getValue());
274 d
= static_cast<double>(c
);
278 throw css::lang::IllegalArgumentException();
282 } // end namespace cppu
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */