Bump version to 6.4-15
[LibreOffice.git] / include / cppuhelper / proptypehlp.hxx
blob5ecdbc5e0411bdf8e1f112a49b641f657db4f018
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 .
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"
27 namespace cppu
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)
41 if( !(a >>= b) ) {
42 switch( a.getValueType().getTypeClass() ) {
43 case css::uno::TypeClass_BYTE:
44 b = a.get<sal_Int8>() != 0;
45 break;
46 case css::uno::TypeClass_SHORT:
47 b = a.get<sal_Int16>() != 0;
48 break;
49 case css::uno::TypeClass_UNSIGNED_SHORT:
51 sal_uInt16 i16 = 0;
52 a >>= i16;
53 b = i16 != 0;
54 break;
56 case css::uno::TypeClass_LONG:
57 b = a.get<sal_Int32>() != 0;
58 break;
59 case css::uno::TypeClass_UNSIGNED_LONG:
60 b = a.get<sal_uInt32>() != 0;
61 break;
62 case css::uno::TypeClass_CHAR:
64 sal_Unicode c = *static_cast<sal_Unicode const *>(a.getValue());
65 b = c != 0;
66 break;
68 default:
69 throw css::lang::IllegalArgumentException();
74 void convertPropertyValue(sal_Bool & target, css::uno::Any const & source) {
75 bool b;
76 convertPropertyValue(b, source);
77 target = b;
80 inline void SAL_CALL convertPropertyValue( sal_Int64 & i , const css::uno::Any & a )
82 if( !(a >>= i) ) {
83 switch( a.getValueType().getTypeClass() ) {
84 case css::uno::TypeClass_BOOLEAN:
85 i = static_cast<sal_Int64>(a.get<bool>());
86 break;
87 case css::uno::TypeClass_CHAR:
89 sal_Unicode c;
90 c = *static_cast<sal_Unicode const *>(a.getValue());
91 i = static_cast<sal_Int64>(c);
92 break;
94 default:
95 throw css::lang::IllegalArgumentException();
101 inline void SAL_CALL convertPropertyValue( sal_uInt64 & i , const css::uno::Any & a )
103 if( !(a >>= i) ) {
104 switch( a.getValueType().getTypeClass() ) {
105 case css::uno::TypeClass_BOOLEAN:
106 i = static_cast<sal_uInt64>(a.get<bool>());
107 break;
108 case css::uno::TypeClass_CHAR:
110 sal_Unicode c;
111 c = *static_cast<sal_Unicode const *>(a.getValue());
112 i = static_cast<sal_uInt64>(c);
113 break;
115 default:
116 throw css::lang::IllegalArgumentException();
121 inline void SAL_CALL convertPropertyValue( sal_Int32 & i , const css::uno::Any & a )
123 if( !(a >>= i) ) {
124 switch( a.getValueType().getTypeClass() ) {
125 case css::uno::TypeClass_BOOLEAN:
126 i = static_cast<sal_Int32>(a.get<bool>());
127 break;
128 case css::uno::TypeClass_CHAR:
130 sal_Unicode c;
131 c = *static_cast<sal_Unicode const *>(a.getValue());
132 i = static_cast<sal_Int32>(c);
133 break;
135 default:
136 throw css::lang::IllegalArgumentException();
141 inline void SAL_CALL convertPropertyValue( sal_uInt32 & i , const css::uno::Any & a )
143 if( !(a >>= i) ) {
144 switch( a.getValueType().getTypeClass() ) {
145 case css::uno::TypeClass_BOOLEAN:
146 i = static_cast<sal_uInt32>(a.get<bool>());
147 break;
148 case css::uno::TypeClass_CHAR:
150 sal_Unicode c;
151 c = *static_cast<sal_Unicode const *>(a.getValue());
152 i = static_cast<sal_uInt32>(c);
153 break;
155 default:
156 throw css::lang::IllegalArgumentException();
161 inline void SAL_CALL convertPropertyValue( sal_Int16 & i , const css::uno::Any & a )
163 if( !(a >>= i) ) {
164 switch( a.getValueType().getTypeClass() ) {
165 case css::uno::TypeClass_BOOLEAN:
166 i = static_cast<sal_Int16>(a.get<bool>());
167 break;
168 case css::uno::TypeClass_CHAR:
170 sal_Unicode c;
171 c = *static_cast<sal_Unicode const *>(a.getValue());
172 i = static_cast<sal_Int16>(c);
173 break;
175 default:
176 throw css::lang::IllegalArgumentException();
181 inline void SAL_CALL convertPropertyValue( sal_uInt16 & i , const css::uno::Any & a )
183 if( !(a >>= i) ) {
184 switch( a.getValueType().getTypeClass() ) {
185 case css::uno::TypeClass_BOOLEAN:
186 i = static_cast<sal_uInt16>(a.get<bool>());
187 break;
188 case css::uno::TypeClass_CHAR:
190 sal_Unicode c;
191 c = *static_cast<sal_Unicode const *>(a.getValue());
192 i = static_cast<sal_Int16>(c);
193 break;
195 default:
196 throw css::lang::IllegalArgumentException();
201 inline void SAL_CALL convertPropertyValue( sal_Int8 & i , const css::uno::Any & a )
203 if( !(a >>= i) ) {
204 switch( a.getValueType().getTypeClass() ) {
205 case css::uno::TypeClass_BOOLEAN:
206 i = static_cast<sal_Int8>(a.get<bool>());
207 break;
208 default:
209 throw css::lang::IllegalArgumentException();
214 inline void SAL_CALL convertPropertyValue( float &f , const css::uno::Any &a )
216 if( !(a >>= f) ) {
217 switch( a.getValueType().getTypeClass() ) {
218 case css::uno::TypeClass_BOOLEAN:
219 f = static_cast<float>(a.get<bool>());
220 break;
221 case css::uno::TypeClass_LONG:
222 f = static_cast<float>(a.get<sal_Int32>());
223 break;
224 case css::uno::TypeClass_UNSIGNED_LONG:
225 f = static_cast<float>(a.get<sal_uInt32>());
226 break;
227 case css::uno::TypeClass_HYPER:
228 f = static_cast<float>(a.get<sal_Int64>());
229 break;
230 case css::uno::TypeClass_UNSIGNED_HYPER:
231 f = static_cast<float>(a.get<sal_uInt64>());
232 break;
233 case css::uno::TypeClass_DOUBLE:
234 f = static_cast<float>(a.get<double>());
235 break;
236 case css::uno::TypeClass_CHAR:
238 sal_Unicode c;
239 c = *static_cast<sal_Unicode const *>(a.getValue());
240 f = static_cast<float>(c);
241 break;
243 default:
244 throw css::lang::IllegalArgumentException();
249 inline void SAL_CALL convertPropertyValue( double &d , const css::uno::Any &a )
251 if( !(a >>= d) ) {
252 switch( a.getValueType().getTypeClass() ) {
253 case css::uno::TypeClass_BOOLEAN:
254 d = static_cast<double>(a.get<bool>());
255 break;
256 case css::uno::TypeClass_HYPER:
257 d = static_cast<double>(a.get<sal_Int64>());
258 break;
259 case css::uno::TypeClass_UNSIGNED_HYPER:
260 d = static_cast<double>(a.get<sal_uInt64>());
261 break;
262 case css::uno::TypeClass_CHAR:
264 sal_Unicode c;
265 c = *static_cast<sal_Unicode const *>(a.getValue());
266 d = static_cast<double>(c);
267 break;
269 default:
270 throw css::lang::IllegalArgumentException();
275 } // end namespace cppu
277 #endif
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */