1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sbxbyte.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basic.hxx"
33 #include <tools/errcode.hxx>
34 #include <basic/sbx.hxx>
35 #include "sbxconv.hxx"
37 BYTE
ImpGetByte( const SbxValues
* p
)
45 SbxBase::SetError( SbxERR_CONVERSION
);
49 if( p
->nChar
> SbxMAXBYTE
)
51 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
54 nRes
= (BYTE
) p
->nChar
;
57 nRes
= (BYTE
) p
->nByte
; break;
60 if( p
->nInteger
> SbxMAXBYTE
)
62 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXBYTE
;
64 else if( p
->nInteger
< 0 )
66 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
69 nRes
= (BYTE
) p
->nInteger
;
73 if( p
->nUShort
> (USHORT
) SbxMAXBYTE
)
75 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXBYTE
;
78 nRes
= (BYTE
) p
->nUShort
;
81 if( p
->nLong
> SbxMAXBYTE
)
83 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXBYTE
;
85 else if( p
->nLong
< 0 )
87 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
90 nRes
= (BYTE
) p
->nLong
;
93 if( p
->nULong
> SbxMAXBYTE
)
95 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXBYTE
;
98 nRes
= (BYTE
) p
->nULong
;
101 if( p
->nInt64
> SbxMAXBYTE
)
103 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXBYTE
;
105 else if( p
->nInt64
< 0 )
107 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
110 nRes
= (BYTE
) p
->nInt64
;
113 if( p
->uInt64
> SbxMAXBYTE
)
115 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXBYTE
;
118 nRes
= (BYTE
) p
->uInt64
;
121 if( p
->nSingle
> SbxMAXBYTE
)
123 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXBYTE
;
125 else if( p
->nSingle
< 0 )
127 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
130 nRes
= (BYTE
) ImpRound( p
->nSingle
);
138 case SbxBYREF
| SbxDECIMAL
:
141 if( p
->eType
== SbxCURRENCY
)
142 dVal
= ImpCurrencyToDouble( p
->nLong64
);
143 else if( p
->eType
== SbxLONG64
)
144 dVal
= ImpINT64ToDouble( p
->nLong64
);
145 else if( p
->eType
== SbxULONG64
)
146 dVal
= ImpUINT64ToDouble( p
->nULong64
);
147 else if( p
->eType
== SbxDECIMAL
)
151 p
->pDecimal
->getDouble( dVal
);
156 if( dVal
> SbxMAXBYTE
)
158 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXBYTE
;
162 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
165 nRes
= (BYTE
) ImpRound( dVal
);
168 case SbxBYREF
| SbxSTRING
:
177 if( ImpScan( *p
->pString
, d
, t
, NULL
) != SbxERR_OK
)
179 else if( d
> SbxMAXBYTE
)
181 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXBYTE
;
185 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
188 nRes
= (BYTE
) ( d
+ 0.5 );
193 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
195 nRes
= pVal
->GetByte();
198 SbxBase::SetError( SbxERR_NO_OBJECT
); nRes
= 0;
203 case SbxBYREF
| SbxBYTE
:
204 nRes
= p
->nByte
; break;
206 // ab hier wird getestet
207 case SbxBYREF
| SbxCHAR
:
208 aTmp
.nChar
= *p
->pChar
; goto ref
;
209 case SbxBYREF
| SbxINTEGER
:
210 case SbxBYREF
| SbxBOOL
:
211 aTmp
.nInteger
= *p
->pInteger
; goto ref
;
212 case SbxBYREF
| SbxLONG
:
213 aTmp
.nLong
= *p
->pLong
; goto ref
;
214 case SbxBYREF
| SbxULONG
:
215 aTmp
.nULong
= *p
->pULong
; goto ref
;
216 case SbxBYREF
| SbxERROR
:
217 case SbxBYREF
| SbxUSHORT
:
218 aTmp
.nUShort
= *p
->pUShort
; goto ref
;
219 case SbxBYREF
| SbxSINGLE
:
220 aTmp
.nSingle
= *p
->pSingle
; goto ref
;
221 case SbxBYREF
| SbxDATE
:
222 case SbxBYREF
| SbxDOUBLE
:
223 aTmp
.nDouble
= *p
->pDouble
; goto ref
;
224 case SbxBYREF
| SbxULONG64
:
225 aTmp
.nULong64
= *p
->pULong64
; goto ref
;
226 case SbxBYREF
| SbxLONG64
:
227 case SbxBYREF
| SbxCURRENCY
:
228 aTmp
.nLong64
= *p
->pLong64
; goto ref
;
229 case SbxBYREF
| SbxSALINT64
:
230 aTmp
.nInt64
= *p
->pnInt64
; goto ref
;
231 case SbxBYREF
| SbxSALUINT64
:
232 aTmp
.uInt64
= *p
->puInt64
; goto ref
;
234 aTmp
.eType
= SbxDataType( p
->eType
& 0x0FFF );
235 p
= &aTmp
; goto start
;
238 SbxBase::SetError( SbxERR_CONVERSION
); nRes
= 0;
243 void ImpPutByte( SbxValues
* p
, BYTE n
)
251 p
->nInteger
= n
; break;
254 p
->nUShort
= n
; break;
258 p
->nULong
= n
; break;
260 p
->nSingle
= n
; break;
263 p
->nDouble
= n
; break;
265 p
->nInt64
= n
; break;
267 p
->uInt64
= n
; break;
269 p
->nULong64
= ImpDoubleToUINT64( (double)n
); break;
271 p
->nLong64
= ImpDoubleToINT64( (double)n
); break;
273 p
->nLong64
= ImpDoubleToCurrency( (double)n
); break;
275 case SbxBYREF
| SbxDECIMAL
:
276 ImpCreateDecimal( p
)->setByte( n
);
280 p
->nChar
= (xub_Unicode
) n
; break;
282 case SbxBYREF
| SbxSTRING
:
286 p
->pString
= new XubString
;
287 ImpCvtNum( (double) n
, 0, *p
->pString
);
291 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
295 SbxBase::SetError( SbxERR_NO_OBJECT
);
298 case SbxBYREF
| SbxCHAR
:
299 *p
->pChar
= (xub_Unicode
) n
; break;
300 case SbxBYREF
| SbxBYTE
:
301 *p
->pByte
= n
; break;
302 case SbxBYREF
| SbxINTEGER
:
303 case SbxBYREF
| SbxBOOL
:
304 *p
->pInteger
= n
; break;
305 case SbxBYREF
| SbxERROR
:
306 case SbxBYREF
| SbxUSHORT
:
307 *p
->pUShort
= n
; break;
308 case SbxBYREF
| SbxLONG
:
309 *p
->pLong
= n
; break;
310 case SbxBYREF
| SbxULONG
:
311 *p
->pULong
= n
; break;
312 case SbxBYREF
| SbxSINGLE
:
313 *p
->pSingle
= n
; break;
314 case SbxBYREF
| SbxDATE
:
315 case SbxBYREF
| SbxDOUBLE
:
316 *p
->pDouble
= n
; break;
317 case SbxBYREF
| SbxULONG64
:
318 *p
->pULong64
= ImpDoubleToUINT64( (double)n
); break;
319 case SbxBYREF
| SbxLONG64
:
320 *p
->pLong64
= ImpDoubleToINT64( (double)n
); break;
321 case SbxBYREF
| SbxSALINT64
:
322 *p
->pnInt64
= n
; break;
323 case SbxBYREF
| SbxSALUINT64
:
324 *p
->puInt64
= n
; break;
325 case SbxBYREF
| SbxCURRENCY
:
326 *p
->pLong64
= ImpDoubleToCurrency( (double)n
); break;
329 SbxBase::SetError( SbxERR_CONVERSION
);