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