fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / basic / source / sbx / sbxbyte.cxx
blob9c95222940238faf1822accd1b55f0904392f817
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_uInt8 ImpGetByte( const SbxValues* p )
26 SbxValues aTmp;
27 sal_uInt8 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 if( p->nChar > SbxMAXBYTE )
38 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
40 else
41 nRes = (sal_uInt8) p->nChar;
42 break;
43 case SbxBYTE:
44 nRes = (sal_uInt8) p->nByte; break;
45 case SbxINTEGER:
46 case SbxBOOL:
47 if( p->nInteger > SbxMAXBYTE )
49 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXBYTE;
51 else if( p->nInteger < 0 )
53 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
55 else
56 nRes = (sal_uInt8) p->nInteger;
57 break;
58 case SbxERROR:
59 case SbxUSHORT:
60 if( p->nUShort > (sal_uInt16) SbxMAXBYTE )
62 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXBYTE;
64 else
65 nRes = (sal_uInt8) p->nUShort;
66 break;
67 case SbxLONG:
68 if( p->nLong > SbxMAXBYTE )
70 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXBYTE;
72 else if( p->nLong < 0 )
74 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
76 else
77 nRes = (sal_uInt8) p->nLong;
78 break;
79 case SbxULONG:
80 if( p->nULong > SbxMAXBYTE )
82 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXBYTE;
84 else
85 nRes = (sal_uInt8) p->nULong;
86 break;
87 case SbxCURRENCY:
88 case SbxSALINT64:
90 sal_Int64 val = p->nInt64;
91 if ( p->eType == SbxCURRENCY )
92 val = val / CURRENCY_FACTOR;
93 if( val > SbxMAXBYTE )
95 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXBYTE;
97 else if( p->nInt64 < 0 )
99 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
101 else
102 nRes = (sal_uInt8) val;
103 break;
105 case SbxSALUINT64:
106 if( p->uInt64 > SbxMAXBYTE )
108 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXBYTE;
110 else
111 nRes = (sal_uInt8) p->uInt64;
112 break;
113 case SbxSINGLE:
114 if( p->nSingle > SbxMAXBYTE )
116 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXBYTE;
118 else if( p->nSingle < 0 )
120 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
122 else
123 nRes = (sal_uInt8) ImpRound( p->nSingle );
124 break;
125 case SbxDATE:
126 case SbxDOUBLE:
127 case SbxDECIMAL:
128 case SbxBYREF | SbxDECIMAL:
130 double dVal;
131 if( p->eType == SbxDECIMAL )
133 dVal = 0.0;
134 if( p->pDecimal )
135 p->pDecimal->getDouble( dVal );
137 else
138 dVal = p->nDouble;
140 if( dVal > SbxMAXBYTE )
142 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXBYTE;
144 else if( dVal < 0 )
146 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
148 else
149 nRes = (sal_uInt8) ImpRound( dVal );
150 break;
152 case SbxBYREF | SbxSTRING:
153 case SbxSTRING:
154 case SbxLPSTR:
155 if( !p->pOUString )
156 nRes = 0;
157 else
159 double d;
160 SbxDataType t;
161 if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
162 nRes = 0;
163 else if( d > SbxMAXBYTE )
165 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXBYTE;
167 else if( d < 0 )
169 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
171 else
172 nRes = (sal_uInt8) ( d + 0.5 );
174 break;
175 case SbxOBJECT:
177 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
178 if( pVal )
179 nRes = pVal->GetByte();
180 else
182 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
184 break;
187 case SbxBYREF | SbxBYTE:
188 nRes = p->nByte; break;
190 // from here on will be tested
191 case SbxBYREF | SbxCHAR:
192 aTmp.nChar = *p->pChar; goto ref;
193 case SbxBYREF | SbxINTEGER:
194 case SbxBYREF | SbxBOOL:
195 aTmp.nInteger = *p->pInteger; goto ref;
196 case SbxBYREF | SbxLONG:
197 aTmp.nLong = *p->pLong; goto ref;
198 case SbxBYREF | SbxULONG:
199 aTmp.nULong = *p->pULong; goto ref;
200 case SbxBYREF | SbxERROR:
201 case SbxBYREF | SbxUSHORT:
202 aTmp.nUShort = *p->pUShort; goto ref;
203 case SbxBYREF | SbxSINGLE:
204 aTmp.nSingle = *p->pSingle; goto ref;
205 case SbxBYREF | SbxDATE:
206 case SbxBYREF | SbxDOUBLE:
207 aTmp.nDouble = *p->pDouble; goto ref;
208 case SbxBYREF | SbxCURRENCY:
209 case SbxBYREF | SbxSALINT64:
210 aTmp.nInt64 = *p->pnInt64; goto ref;
211 case SbxBYREF | SbxSALUINT64:
212 aTmp.uInt64 = *p->puInt64; goto ref;
213 ref:
214 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
215 p = &aTmp; goto start;
217 default:
218 SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
220 return nRes;
223 void ImpPutByte( SbxValues* p, sal_uInt8 n )
225 switch( +p->eType )
227 case SbxBYTE:
228 p->nByte = n; break;
229 case SbxINTEGER:
230 case SbxBOOL:
231 p->nInteger = n; break;
232 case SbxERROR:
233 case SbxUSHORT:
234 p->nUShort = n; break;
235 case SbxLONG:
236 p->nLong = n; break;
237 case SbxULONG:
238 p->nULong = n; break;
239 case SbxSINGLE:
240 p->nSingle = n; break;
241 case SbxDATE:
242 case SbxDOUBLE:
243 p->nDouble = n; break;
244 case SbxCURRENCY:
245 p->nInt64 = n * CURRENCY_FACTOR; break;
246 case SbxSALINT64:
247 p->nInt64 = n; break;
248 case SbxSALUINT64:
249 p->uInt64 = n; break;
250 case SbxDECIMAL:
251 case SbxBYREF | SbxDECIMAL:
252 ImpCreateDecimal( p )->setByte( n );
253 break;
255 case SbxCHAR:
256 p->nChar = (sal_Unicode) n; break;
258 case SbxBYREF | SbxSTRING:
259 case SbxSTRING:
260 case SbxLPSTR:
261 if( !p->pOUString )
262 p->pOUString = new OUString;
263 ImpCvtNum( (double) n, 0, *p->pOUString );
264 break;
265 case SbxOBJECT:
267 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
268 if( pVal )
269 pVal->PutByte( n );
270 else
271 SbxBase::SetError( SbxERR_NO_OBJECT );
272 break;
274 case SbxBYREF | SbxCHAR:
275 *p->pChar = (sal_Unicode) n; break;
276 case SbxBYREF | SbxBYTE:
277 *p->pByte = n; break;
278 case SbxBYREF | SbxINTEGER:
279 case SbxBYREF | SbxBOOL:
280 *p->pInteger = n; break;
281 case SbxBYREF | SbxERROR:
282 case SbxBYREF | SbxUSHORT:
283 *p->pUShort = n; break;
284 case SbxBYREF | SbxLONG:
285 *p->pLong = n; break;
286 case SbxBYREF | SbxULONG:
287 *p->pULong = n; break;
288 case SbxBYREF | SbxSINGLE:
289 *p->pSingle = n; break;
290 case SbxBYREF | SbxDATE:
291 case SbxBYREF | SbxDOUBLE:
292 *p->pDouble = n; break;
293 case SbxBYREF | SbxCURRENCY:
294 p->nInt64 = n * CURRENCY_FACTOR; break;
295 case SbxBYREF | SbxSALINT64:
296 *p->pnInt64 = n; break;
297 case SbxBYREF | SbxSALUINT64:
298 *p->puInt64 = n; break;
300 default:
301 SbxBase::SetError( SbxERR_CONVERSION );
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */