1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
)
32 SbxBase::SetError( SbxERR_CONVERSION
);
36 if( p
->nChar
> SbxMAXBYTE
)
38 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
41 nRes
= (sal_uInt8
) p
->nChar
;
44 nRes
= (sal_uInt8
) p
->nByte
; break;
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;
56 nRes
= (sal_uInt8
) p
->nInteger
;
60 if( p
->nUShort
> (sal_uInt16
) SbxMAXBYTE
)
62 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXBYTE
;
65 nRes
= (sal_uInt8
) p
->nUShort
;
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;
77 nRes
= (sal_uInt8
) p
->nLong
;
80 if( p
->nULong
> SbxMAXBYTE
)
82 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXBYTE
;
85 nRes
= (sal_uInt8
) p
->nULong
;
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;
102 nRes
= (sal_uInt8
) val
;
106 if( p
->uInt64
> SbxMAXBYTE
)
108 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXBYTE
;
111 nRes
= (sal_uInt8
) p
->uInt64
;
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;
123 nRes
= (sal_uInt8
) ImpRound( p
->nSingle
);
128 case SbxBYREF
| SbxDECIMAL
:
131 if( p
->eType
== SbxDECIMAL
)
135 p
->pDecimal
->getDouble( dVal
);
140 if( dVal
> SbxMAXBYTE
)
142 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXBYTE
;
146 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
149 nRes
= (sal_uInt8
) ImpRound( dVal
);
152 case SbxBYREF
| SbxSTRING
:
161 if( ImpScan( *p
->pOUString
, d
, t
, NULL
) != SbxERR_OK
)
163 else if( d
> SbxMAXBYTE
)
165 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXBYTE
;
169 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
172 nRes
= (sal_uInt8
) ( d
+ 0.5 );
177 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
179 nRes
= pVal
->GetByte();
182 SbxBase::SetError( SbxERR_NO_OBJECT
); nRes
= 0;
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
;
214 aTmp
.eType
= SbxDataType( p
->eType
& 0x0FFF );
215 p
= &aTmp
; goto start
;
218 SbxBase::SetError( SbxERR_CONVERSION
); nRes
= 0;
223 void ImpPutByte( SbxValues
* p
, sal_uInt8 n
)
231 p
->nInteger
= n
; break;
234 p
->nUShort
= n
; break;
238 p
->nULong
= n
; break;
240 p
->nSingle
= n
; break;
243 p
->nDouble
= n
; break;
245 p
->nInt64
= n
* CURRENCY_FACTOR
; break;
247 p
->nInt64
= n
; break;
249 p
->uInt64
= n
; break;
251 case SbxBYREF
| SbxDECIMAL
:
252 ImpCreateDecimal( p
)->setByte( n
);
256 p
->nChar
= (sal_Unicode
) n
; break;
258 case SbxBYREF
| SbxSTRING
:
262 p
->pOUString
= new OUString
;
263 ImpCvtNum( (double) n
, 0, *p
->pOUString
);
267 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
271 SbxBase::SetError( SbxERR_NO_OBJECT
);
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;
301 SbxBase::SetError( SbxERR_CONVERSION
);
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */