LibreOffice: cppuhelper/proptypehlp.hxx Source File

LibreOffice LibreOffice 6.3 SDK C/C++ API Reference

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 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #ifndef INCLUDED_CPPUHELPER_PROPTYPEHLP_HXX
21 #define INCLUDED_CPPUHELPER_PROPTYPEHLP_HXX
22
23 #include "cppuhelper/proptypehlp.h"
24 #include "com/sun/star/lang/IllegalArgumentException.hpp"
25 #include "com/sun/star/uno/TypeClass.hpp"
26
27 namespace cppu
28 {
29
30 template < class target >
31 inline void SAL_CALL convertPropertyValue( target &value , const css::uno::Any & a)
32 {
33
34 if( !( a >>= value ) ) {
35 throw css::lang::IllegalArgumentException();
36 }
37 }
38
39 void convertPropertyValue(bool & b, const css::uno::Any & a)
40 {
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:
50 {
51 sal_uInt16 i16 = 0;
52 a >>= i16;
53 b = i16 != 0;
54 break;
55 }
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:
63 {
64 sal_Unicode c = *static_cast<sal_Unicode const *>(a.getValue());
65 b = c != 0;
66 break;
67 }
68 default:
69 throw css::lang::IllegalArgumentException();
70 }
71 }
72 }
73
74 void convertPropertyValue(sal_Bool & target, css::uno::Any const & source) {
75 bool b;
76 convertPropertyValue(b, source);
77 target = b;
78 }
79
80 inline void SAL_CALL convertPropertyValue( sal_Int64 & i , const css::uno::Any & a )
81 {
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:
88 {
89 sal_Unicode c;
90 c = *static_cast<sal_Unicode const *>(a.getValue());
91 i = static_cast<sal_Int64>(c);
92 break;
93 }
94 default:
95 throw css::lang::IllegalArgumentException();
96 }
97 }
98 }
99
100
101 inline void SAL_CALL convertPropertyValue( sal_uInt64 & i , const css::uno::Any & a )
102 {
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:
109 {
110 sal_Unicode c;
111 c = *static_cast<sal_Unicode const *>(a.getValue());
112 i = static_cast<sal_uInt64>(c);
113 break;
114 }
115 default:
116 throw css::lang::IllegalArgumentException();
117 }
118 }
119 }
120
121 inline void SAL_CALL convertPropertyValue( sal_Int32 & i , const css::uno::Any & a )
122 {
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:
129 {
130 sal_Unicode c;
131 c = *static_cast<sal_Unicode const *>(a.getValue());
132 i = static_cast<sal_Int32>(c);
133 break;
134 }
135 default:
136 throw css::lang::IllegalArgumentException();
137 }
138 }
139 }
140
141 inline void SAL_CALL convertPropertyValue( sal_uInt32 & i , const css::uno::Any & a )
142 {
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:
149 {
150 sal_Unicode c;
151 c = *static_cast<sal_Unicode const *>(a.getValue());
152 i = static_cast<sal_uInt32>(c);
153 break;
154 }
155 default:
156 throw css::lang::IllegalArgumentException();
157 }
158 }
159 }
160
161 inline void SAL_CALL convertPropertyValue( sal_Int16 & i , const css::uno::Any & a )
162 {
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:
169 {
170 sal_Unicode c;
171 c = *static_cast<sal_Unicode const *>(a.getValue());
172 i = static_cast<sal_Int16>(c);
173 break;
174 }
175 default:
176 throw css::lang::IllegalArgumentException();
177 }
178 }
179 }
180
181 inline void SAL_CALL convertPropertyValue( sal_uInt16 & i , const css::uno::Any & a )
182 {
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:
189 {
190 sal_Unicode c;
191 c = *static_cast<sal_Unicode const *>(a.getValue());
192 i = static_cast<sal_Int16>(c);
193 break;
194 }
195 default:
196 throw css::lang::IllegalArgumentException();
197 }
198 }
199 }
200
201 inline void SAL_CALL convertPropertyValue( sal_Int8 & i , const css::uno::Any & a )
202 {
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();
210 }
211 }
212 }
213
214 inline void SAL_CALL convertPropertyValue( float &f , const css::uno::Any &a )
215 {
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:
237 {
238 sal_Unicode c;
239 c = *static_cast<sal_Unicode const *>(a.getValue());
240 f = static_cast<float>(c);
241 break;
242 }
243 default:
244 throw css::lang::IllegalArgumentException();
245 }
246 }
247 }
248
249 inline void SAL_CALL convertPropertyValue( double &d , const css::uno::Any &a )
250 {
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:
263 {
264 sal_Unicode c;
265 c = *static_cast<sal_Unicode const *>(a.getValue());
266 d = static_cast<double>(c);
267 break;
268 }
269 default:
270 throw css::lang::IllegalArgumentException();
271 }
272 }
273 }
274
275 } // end namespace cppu
276
277 #endif
278
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
cppu::convertPropertyValue
void convertPropertyValue(target &value, const css::uno::Any &a)
Converts the value stored in an any to a concrete C++ type.
Definition: proptypehlp.hxx:31
sal_Bool
unsigned char sal_Bool
Definition: types.h:38
proptypehlp.h
cppu
Definition: Enterable.hxx:27
sal_Unicode
sal_uInt16 sal_Unicode
Definition: types.h:141
sal_Int8
signed char sal_Int8
Definition: types.h:43