Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / cppuhelper / proptypehlp.hxx
blob339c3910e2a75afb60b99617130e7194e95df474
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
31 namespace cppu
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)
45 if( a >>= b )
46 return;
48 switch( a.getValueType().getTypeClass() ) {
49 case css::uno::TypeClass_BYTE:
50 b = a.get<sal_Int8>() != 0;
51 break;
52 case css::uno::TypeClass_SHORT:
53 b = a.get<sal_Int16>() != 0;
54 break;
55 case css::uno::TypeClass_UNSIGNED_SHORT:
57 sal_uInt16 i16 = 0;
58 a >>= i16;
59 b = i16 != 0;
60 break;
62 case css::uno::TypeClass_LONG:
63 b = a.get<sal_Int32>() != 0;
64 break;
65 case css::uno::TypeClass_UNSIGNED_LONG:
66 b = a.get<sal_uInt32>() != 0;
67 break;
68 case css::uno::TypeClass_CHAR:
70 sal_Unicode c = *static_cast<sal_Unicode const *>(a.getValue());
71 b = c != 0;
72 break;
74 default:
75 throw css::lang::IllegalArgumentException();
79 void convertPropertyValue(sal_Bool & target, css::uno::Any const & source) {
80 bool b;
81 convertPropertyValue(b, source);
82 target = b;
85 inline void SAL_CALL convertPropertyValue( sal_Int64 & i , const css::uno::Any & a )
87 if( !(a >>= i) ) {
88 switch( a.getValueType().getTypeClass() ) {
89 case css::uno::TypeClass_BOOLEAN:
90 i = static_cast<sal_Int64>(a.get<bool>());
91 break;
92 case css::uno::TypeClass_CHAR:
94 sal_Unicode c;
95 c = *static_cast<sal_Unicode const *>(a.getValue());
96 i = static_cast<sal_Int64>(c);
97 break;
99 default:
100 throw css::lang::IllegalArgumentException();
106 inline void SAL_CALL convertPropertyValue( sal_uInt64 & i , const css::uno::Any & a )
108 if( !(a >>= i) ) {
109 switch( a.getValueType().getTypeClass() ) {
110 case css::uno::TypeClass_BOOLEAN:
111 i = static_cast<sal_uInt64>(a.get<bool>());
112 break;
113 case css::uno::TypeClass_CHAR:
115 sal_Unicode c;
116 c = *static_cast<sal_Unicode const *>(a.getValue());
117 i = static_cast<sal_uInt64>(c);
118 break;
120 default:
121 throw css::lang::IllegalArgumentException();
126 inline void SAL_CALL convertPropertyValue( sal_Int32 & i , const css::uno::Any & a )
128 if( !(a >>= i) ) {
129 switch( a.getValueType().getTypeClass() ) {
130 case css::uno::TypeClass_BOOLEAN:
131 i = static_cast<sal_Int32>(a.get<bool>());
132 break;
133 case css::uno::TypeClass_CHAR:
135 sal_Unicode c;
136 c = *static_cast<sal_Unicode const *>(a.getValue());
137 i = static_cast<sal_Int32>(c);
138 break;
140 default:
141 throw css::lang::IllegalArgumentException();
146 inline void SAL_CALL convertPropertyValue( sal_uInt32 & i , const css::uno::Any & a )
148 if( !(a >>= i) ) {
149 switch( a.getValueType().getTypeClass() ) {
150 case css::uno::TypeClass_BOOLEAN:
151 i = static_cast<sal_uInt32>(a.get<bool>());
152 break;
153 case css::uno::TypeClass_CHAR:
155 sal_Unicode c;
156 c = *static_cast<sal_Unicode const *>(a.getValue());
157 i = static_cast<sal_uInt32>(c);
158 break;
160 default:
161 throw css::lang::IllegalArgumentException();
166 inline void SAL_CALL convertPropertyValue( sal_Int16 & i , const css::uno::Any & a )
168 if( !(a >>= i) ) {
169 switch( a.getValueType().getTypeClass() ) {
170 case css::uno::TypeClass_BOOLEAN:
171 i = static_cast<sal_Int16>(a.get<bool>());
172 break;
173 case css::uno::TypeClass_CHAR:
175 sal_Unicode c;
176 c = *static_cast<sal_Unicode const *>(a.getValue());
177 i = static_cast<sal_Int16>(c);
178 break;
180 default:
181 throw css::lang::IllegalArgumentException();
186 inline void SAL_CALL convertPropertyValue( sal_uInt16 & i , const css::uno::Any & a )
188 if( !(a >>= i) ) {
189 switch( a.getValueType().getTypeClass() ) {
190 case css::uno::TypeClass_BOOLEAN:
191 i = static_cast<sal_uInt16>(a.get<bool>());
192 break;
193 case css::uno::TypeClass_CHAR:
195 sal_Unicode c;
196 c = *static_cast<sal_Unicode const *>(a.getValue());
197 i = static_cast<sal_Int16>(c);
198 break;
200 default:
201 throw css::lang::IllegalArgumentException();
206 inline void SAL_CALL convertPropertyValue( sal_Int8 & i , const css::uno::Any & a )
208 if( !(a >>= i) ) {
209 switch( a.getValueType().getTypeClass() ) {
210 case css::uno::TypeClass_BOOLEAN:
211 i = static_cast<sal_Int8>(a.get<bool>());
212 break;
213 default:
214 throw css::lang::IllegalArgumentException();
219 inline void SAL_CALL convertPropertyValue( float &f , const css::uno::Any &a )
221 if( a >>= f )
222 return;
224 switch( a.getValueType().getTypeClass() ) {
225 case css::uno::TypeClass_BOOLEAN:
226 f = static_cast<float>(a.get<bool>());
227 break;
228 case css::uno::TypeClass_LONG:
229 f = static_cast<float>(a.get<sal_Int32>());
230 break;
231 case css::uno::TypeClass_UNSIGNED_LONG:
232 f = static_cast<float>(a.get<sal_uInt32>());
233 break;
234 case css::uno::TypeClass_HYPER:
235 f = static_cast<float>(a.get<sal_Int64>());
236 break;
237 case css::uno::TypeClass_UNSIGNED_HYPER:
238 f = static_cast<float>(a.get<sal_uInt64>());
239 break;
240 case css::uno::TypeClass_DOUBLE:
241 f = static_cast<float>(a.get<double>());
242 break;
243 case css::uno::TypeClass_CHAR:
245 sal_Unicode c;
246 c = *static_cast<sal_Unicode const *>(a.getValue());
247 f = static_cast<float>(c);
248 break;
250 default:
251 throw css::lang::IllegalArgumentException();
255 inline void SAL_CALL convertPropertyValue( double &d , const css::uno::Any &a )
257 if( a >>= d )
258 return;
260 switch( a.getValueType().getTypeClass() ) {
261 case css::uno::TypeClass_BOOLEAN:
262 d = static_cast<double>(a.get<bool>());
263 break;
264 case css::uno::TypeClass_HYPER:
265 d = static_cast<double>(a.get<sal_Int64>());
266 break;
267 case css::uno::TypeClass_UNSIGNED_HYPER:
268 d = static_cast<double>(a.get<sal_uInt64>());
269 break;
270 case css::uno::TypeClass_CHAR:
272 sal_Unicode c;
273 c = *static_cast<sal_Unicode const *>(a.getValue());
274 d = static_cast<double>(c);
275 break;
277 default:
278 throw css::lang::IllegalArgumentException();
282 } // end namespace cppu
284 #endif
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */