LibreOffice: cppuhelper/proptypehlp.hxx Source File

LibreOffice LibreOffice 7.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/*
21 * This file is part of LibreOffice published API.
22 */
23
24#ifndef INCLUDED_CPPUHELPER_PROPTYPEHLP_HXX
25#define INCLUDED_CPPUHELPER_PROPTYPEHLP_HXX
26
27#include "cppuhelper/proptypehlp.h"
28#include "com/sun/star/lang/IllegalArgumentException.hpp"
29#include "com/sun/star/uno/TypeClass.hpp"
30
31namespace cppu
32{
33
34template < class target >
35 inline void SAL_CALL convertPropertyValue( target &value , const css::uno::Any & a)
36{
37
38 if( !( a >>= value ) ) {
39 throw css::lang::IllegalArgumentException();
40 }
41}
42
43 void convertPropertyValue(bool & b, const css::uno::Any & a)
44{
45 if( !(a >>= b) ) {
46 switch( a.getValueType().getTypeClass() ) {
47 case css::uno::TypeClass_BYTE:
48 b = a.get<sal_Int8>() != 0;
49 break;
50 case css::uno::TypeClass_SHORT:
51 b = a.get<sal_Int16>() != 0;
52 break;
53 case css::uno::TypeClass_UNSIGNED_SHORT:
54 {
55 sal_uInt16 i16 = 0;
56 a >>= i16;
57 b = i16 != 0;
58 break;
59 }
60 case css::uno::TypeClass_LONG:
61 b = a.get<sal_Int32>() != 0;
62 break;
63 case css::uno::TypeClass_UNSIGNED_LONG:
64 b = a.get<sal_uInt32>() != 0;
65 break;
66 case css::uno::TypeClass_CHAR:
67 {
68 sal_Unicode c = *static_cast<sal_Unicode const *>(a.getValue());
69 b = c != 0;
70 break;
71 }
72 default:
73 throw css::lang::IllegalArgumentException();
74 }
75 }
76}
77
78 void convertPropertyValue(sal_Bool & target, css::uno::Any const & source) {
79 bool b;
80 convertPropertyValue(b, source);
81 target = b;
82}
83
84 inline void SAL_CALL convertPropertyValue( sal_Int64 & i , const css::uno::Any & a )
85{
86 if( !(a >>= i) ) {
87 switch( a.getValueType().getTypeClass() ) {
88 case css::uno::TypeClass_BOOLEAN:
89 i = static_cast<sal_Int64>(a.get<bool>());
90 break;
91 case css::uno::TypeClass_CHAR:
92 {
93 sal_Unicode c;
94 c = *static_cast<sal_Unicode const *>(a.getValue());
95 i = static_cast<sal_Int64>(c);
96 break;
97 }
98 default:
99 throw css::lang::IllegalArgumentException();
100 }
101 }
102}
103
104
105 inline void SAL_CALL convertPropertyValue( sal_uInt64 & i , const css::uno::Any & a )
106{
107 if( !(a >>= i) ) {
108 switch( a.getValueType().getTypeClass() ) {
109 case css::uno::TypeClass_BOOLEAN:
110 i = static_cast<sal_uInt64>(a.get<bool>());
111 break;
112 case css::uno::TypeClass_CHAR:
113 {
114 sal_Unicode c;
115 c = *static_cast<sal_Unicode const *>(a.getValue());
116 i = static_cast<sal_uInt64>(c);
117 break;
118 }
119 default:
120 throw css::lang::IllegalArgumentException();
121 }
122 }
123}
124
125 inline void SAL_CALL convertPropertyValue( sal_Int32 & i , const css::uno::Any & a )
126{
127 if( !(a >>= i) ) {
128 switch( a.getValueType().getTypeClass() ) {
129 case css::uno::TypeClass_BOOLEAN:
130 i = static_cast<sal_Int32>(a.get<bool>());
131 break;
132 case css::uno::TypeClass_CHAR:
133 {
134 sal_Unicode c;
135 c = *static_cast<sal_Unicode const *>(a.getValue());
136 i = static_cast<sal_Int32>(c);
137 break;
138 }
139 default:
140 throw css::lang::IllegalArgumentException();
141 }
142 }
143}
144
145 inline void SAL_CALL convertPropertyValue( sal_uInt32 & i , const css::uno::Any & a )
146{
147 if( !(a >>= i) ) {
148 switch( a.getValueType().getTypeClass() ) {
149 case css::uno::TypeClass_BOOLEAN:
150 i = static_cast<sal_uInt32>(a.get<bool>());
151 break;
152 case css::uno::TypeClass_CHAR:
153 {
154 sal_Unicode c;
155 c = *static_cast<sal_Unicode const *>(a.getValue());
156 i = static_cast<sal_uInt32>(c);
157 break;
158 }
159 default:
160 throw css::lang::IllegalArgumentException();
161 }
162 }
163}
164
165 inline void SAL_CALL convertPropertyValue( sal_Int16 & i , const css::uno::Any & a )
166{
167 if( !(a >>= i) ) {
168 switch( a.getValueType().getTypeClass() ) {
169 case css::uno::TypeClass_BOOLEAN:
170 i = static_cast<sal_Int16>(a.get<bool>());
171 break;
172 case css::uno::TypeClass_CHAR:
173 {
174 sal_Unicode c;
175 c = *static_cast<sal_Unicode const *>(a.getValue());
176 i = static_cast<sal_Int16>(c);
177 break;
178 }
179 default:
180 throw css::lang::IllegalArgumentException();
181 }
182 }
183}
184
185 inline void SAL_CALL convertPropertyValue( sal_uInt16 & i , const css::uno::Any & a )
186{
187 if( !(a >>= i) ) {
188 switch( a.getValueType().getTypeClass() ) {
189 case css::uno::TypeClass_BOOLEAN:
190 i = static_cast<sal_uInt16>(a.get<bool>());
191 break;
192 case css::uno::TypeClass_CHAR:
193 {
194 sal_Unicode c;
195 c = *static_cast<sal_Unicode const *>(a.getValue());
196 i = static_cast<sal_Int16>(c);
197 break;
198 }
199 default:
200 throw css::lang::IllegalArgumentException();
201 }
202 }
203}
204
205 inline void SAL_CALL convertPropertyValue( sal_Int8 & i , const css::uno::Any & a )
206{
207 if( !(a >>= i) ) {
208 switch( a.getValueType().getTypeClass() ) {
209 case css::uno::TypeClass_BOOLEAN:
210 i = static_cast<sal_Int8>(a.get<bool>());
211 break;
212 default:
213 throw css::lang::IllegalArgumentException();
214 }
215 }
216}
217
218 inline void SAL_CALL convertPropertyValue( float &f , const css::uno::Any &a )
219{
220 if( !(a >>= f) ) {
221 switch( a.getValueType().getTypeClass() ) {
222 case css::uno::TypeClass_BOOLEAN:
223 f = static_cast<float>(a.get<bool>());
224 break;
225 case css::uno::TypeClass_LONG:
226 f = static_cast<float>(a.get<sal_Int32>());
227 break;
228 case css::uno::TypeClass_UNSIGNED_LONG:
229 f = static_cast<float>(a.get<sal_uInt32>());
230 break;
231 case css::uno::TypeClass_HYPER:
232 f = static_cast<float>(a.get<sal_Int64>());
233 break;
234 case css::uno::TypeClass_UNSIGNED_HYPER:
235 f = static_cast<float>(a.get<sal_uInt64>());
236 break;
237 case css::uno::TypeClass_DOUBLE:
238 f = static_cast<float>(a.get<double>());
239 break;
240 case css::uno::TypeClass_CHAR:
241 {
242 sal_Unicode c;
243 c = *static_cast<sal_Unicode const *>(a.getValue());
244 f = static_cast<float>(c);
245 break;
246 }
247 default:
248 throw css::lang::IllegalArgumentException();
249 }
250 }
251}
252
253 inline void SAL_CALL convertPropertyValue( double &d , const css::uno::Any &a )
254{
255 if( !(a >>= d) ) {
256 switch( a.getValueType().getTypeClass() ) {
257 case css::uno::TypeClass_BOOLEAN:
258 d = static_cast<double>(a.get<bool>());
259 break;
260 case css::uno::TypeClass_HYPER:
261 d = static_cast<double>(a.get<sal_Int64>());
262 break;
263 case css::uno::TypeClass_UNSIGNED_HYPER:
264 d = static_cast<double>(a.get<sal_uInt64>());
265 break;
266 case css::uno::TypeClass_CHAR:
267 {
268 sal_Unicode c;
269 c = *static_cast<sal_Unicode const *>(a.getValue());
270 d = static_cast<double>(c);
271 break;
272 }
273 default:
274 throw css::lang::IllegalArgumentException();
275 }
276 }
277}
278
279} // end namespace cppu
280
281#endif
282
283/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Bool
unsigned char sal_Bool
Definition: types.h:38
sal_Unicode
sal_uInt16 sal_Unicode
Definition: types.h:123
sal_Int8
signed char sal_Int8
Definition: types.h:43
proptypehlp.h
cppu
Definition: Enterable.hxx:31
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:35