fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / basic / source / sbx / sbxuint.cxx
blobe5f62f287cbd50635a055ae2445d66494276fb9b
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 #include <tools/errcode.hxx>
21 #include <basic/sbx.hxx>
22 #include "sbxconv.hxx"
24 sal_uInt16 ImpGetUShort( const SbxValues* p )
26 SbxValues aTmp;
27 sal_uInt16 nRes;
28 start:
29 switch( +p->eType )
31 case SbxNULL:
32 SbxBase::SetError( SbxERR_CONVERSION );
33 case SbxEMPTY:
34 nRes = 0; break;
35 case SbxCHAR:
36 nRes = p->nChar;
37 break;
38 case SbxBYTE:
39 nRes = p->nByte; break;
40 case SbxINTEGER:
41 case SbxBOOL:
42 if( p->nInteger < 0 )
44 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
46 else
47 nRes = p->nInteger;
48 break;
49 case SbxERROR:
50 case SbxUSHORT:
51 nRes = p->nUShort;
52 break;
53 case SbxLONG:
54 if( p->nLong > SbxMAXUINT )
56 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT;
58 else if( p->nLong < 0 )
60 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
62 else
63 nRes = (sal_uInt16) p->nLong;
64 break;
65 case SbxULONG:
66 if( p->nULong > SbxMAXUINT )
68 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT;
70 else
71 nRes = (sal_uInt16) p->nULong;
72 break;
73 case SbxCURRENCY:
74 if( p->nInt64 / CURRENCY_FACTOR > SbxMAXUINT )
76 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT;
78 else if( p->nInt64 < 0 )
80 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
82 else
83 nRes = (sal_uInt16) (p->nInt64 / CURRENCY_FACTOR);
84 break;
85 case SbxSALINT64:
86 if( p->nInt64 > SbxMAXUINT )
88 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT;
90 else if( p->nInt64 < 0 )
92 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
94 else
95 nRes = (sal_uInt16) p->nInt64;
96 break;
97 case SbxSALUINT64:
98 if( p->uInt64 > SbxMAXUINT )
100 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT;
102 else
103 nRes = (sal_uInt16) p->uInt64;
104 break;
105 case SbxSINGLE:
106 if( p->nSingle > SbxMAXUINT )
108 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT;
110 else if( p->nSingle < 0 )
112 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
114 else
115 nRes = (sal_uInt16) ( p->nSingle + 0.5 );
116 break;
117 case SbxDATE:
118 case SbxDOUBLE:
119 case SbxDECIMAL:
120 case SbxBYREF | SbxDECIMAL:
122 double dVal;
123 if( p->eType == SbxDECIMAL )
125 dVal = 0.0;
126 if( p->pDecimal )
127 p->pDecimal->getDouble( dVal );
129 else
130 dVal = p->nDouble;
132 if( dVal > SbxMAXUINT )
134 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT;
136 else if( dVal < 0 )
138 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
140 else
141 nRes = (sal_uInt16) ( dVal + 0.5 );
142 break;
144 case SbxBYREF | SbxSTRING:
145 case SbxSTRING:
146 case SbxLPSTR:
147 if( !p->pOUString )
148 nRes = 0;
149 else
151 double d;
152 SbxDataType t;
153 if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
154 nRes = 0;
155 else if( d > SbxMAXUINT )
157 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT;
159 else if( d < 0 )
161 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
163 else
164 nRes = (sal_uInt16) ( d + 0.5 );
166 break;
167 case SbxOBJECT:
169 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
170 if( pVal )
171 nRes = pVal->GetUShort();
172 else
174 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
176 break;
179 case SbxBYREF | SbxBYTE:
180 nRes = *p->pByte; break;
181 case SbxBYREF | SbxERROR:
182 case SbxBYREF | SbxUSHORT:
183 nRes = *p->pUShort; break;
185 // from here on will be tested
186 case SbxBYREF | SbxCHAR:
187 aTmp.nChar = *p->pChar; goto ref;
188 case SbxBYREF | SbxINTEGER:
189 case SbxBYREF | SbxBOOL:
190 aTmp.nInteger = *p->pInteger; goto ref;
191 case SbxBYREF | SbxLONG:
192 aTmp.nLong = *p->pLong; goto ref;
193 case SbxBYREF | SbxULONG:
194 aTmp.nULong = *p->pULong; goto ref;
195 case SbxBYREF | SbxSINGLE:
196 aTmp.nSingle = *p->pSingle; goto ref;
197 case SbxBYREF | SbxDATE:
198 case SbxBYREF | SbxDOUBLE:
199 aTmp.nDouble = *p->pDouble; goto ref;
200 case SbxBYREF | SbxCURRENCY:
201 case SbxBYREF | SbxSALINT64:
202 aTmp.nInt64 = *p->pnInt64; goto ref;
203 case SbxBYREF | SbxSALUINT64:
204 aTmp.uInt64 = *p->puInt64; goto ref;
205 ref:
206 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
207 p = &aTmp; goto start;
209 default:
210 SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
212 return nRes;
215 void ImpPutUShort( SbxValues* p, sal_uInt16 n )
217 SbxValues aTmp;
219 start:
220 switch( +p->eType )
222 case SbxERROR:
223 case SbxUSHORT:
224 p->nUShort = n; break;
225 case SbxLONG:
226 p->nLong = n; break;
227 case SbxULONG:
228 p->nULong = n; break;
229 case SbxSINGLE:
230 p->nSingle = n; break;
231 case SbxDATE:
232 case SbxDOUBLE:
233 p->nDouble = n; break;
234 case SbxCURRENCY:
235 p->nInt64 = n * CURRENCY_FACTOR; break;
236 case SbxSALINT64:
237 p->nInt64 = n; break;
238 case SbxSALUINT64:
239 p->uInt64 = n; break;
240 case SbxDECIMAL:
241 case SbxBYREF | SbxDECIMAL:
242 ImpCreateDecimal( p )->setUInt( n );
243 break;
245 // from here on tests
246 case SbxCHAR:
247 aTmp.pChar = &p->nChar; goto direct;
248 case SbxBYTE:
249 aTmp.pByte = &p->nByte; goto direct;
250 case SbxINTEGER:
251 case SbxBOOL:
252 aTmp.pInteger = &p->nInteger;
253 direct:
254 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
255 p = &aTmp; goto start;
257 case SbxBYREF | SbxSTRING:
258 case SbxSTRING:
259 case SbxLPSTR:
260 if( !p->pOUString )
261 p->pOUString = new OUString;
262 ImpCvtNum( (double) n, 0, *p->pOUString );
263 break;
264 case SbxOBJECT:
266 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
267 if( pVal )
268 pVal->PutUShort( n );
269 else
270 SbxBase::SetError( SbxERR_NO_OBJECT );
271 break;
274 case SbxBYREF | SbxCHAR:
275 *p->pChar = (sal_Unicode) n; break;
276 case SbxBYREF | SbxBYTE:
277 if( n > SbxMAXBYTE )
279 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
281 *p->pByte = (sal_uInt8) n; break;
282 case SbxBYREF | SbxINTEGER:
283 case SbxBYREF | SbxBOOL:
284 if( n > SbxMAXINT )
286 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXINT;
288 *p->pInteger = (sal_Int16) n; break;
289 case SbxBYREF | SbxERROR:
290 case SbxBYREF | SbxUSHORT:
291 *p->pUShort = n; break;
292 case SbxBYREF | SbxLONG:
293 *p->pLong = n; break;
294 case SbxBYREF | SbxULONG:
295 *p->pULong = n; break;
296 case SbxBYREF | SbxSINGLE:
297 *p->pSingle = n; break;
298 case SbxBYREF | SbxDATE:
299 case SbxBYREF | SbxDOUBLE:
300 *p->pDouble = n; break;
301 case SbxBYREF | SbxCURRENCY:
302 *p->pnInt64 = n * CURRENCY_FACTOR; break;
303 case SbxBYREF | SbxSALINT64:
304 *p->pnInt64 = n; break;
305 case SbxBYREF | SbxSALUINT64:
306 *p->puInt64 = n; break;
308 default:
309 SbxBase::SetError( SbxERR_CONVERSION );
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */