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: sbxlng.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 INT32
ImpGetLong( const SbxValues
* p
)
45 SbxBase::SetError( SbxERR_CONVERSION
);
49 nRes
= p
->nChar
; break;
51 nRes
= p
->nByte
; break;
54 nRes
= p
->nInteger
; break;
57 nRes
= p
->nUShort
; break;
59 nRes
= p
->nLong
; break;
61 if( p
->nULong
> SbxMAXLNG
)
63 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXLNG
;
66 nRes
= (INT32
) p
->nULong
;
69 if( p
->nSingle
> SbxMAXLNG
)
71 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXLNG
;
73 else if( p
->nSingle
< SbxMINLNG
)
75 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINLNG
;
78 nRes
= (INT32
) ImpRound( p
->nSingle
);
88 case SbxBYREF
| SbxDECIMAL
:
91 if( p
->eType
== SbxCURRENCY
)
92 dVal
= ImpCurrencyToDouble( p
->nLong64
);
93 else if( p
->eType
== SbxLONG64
)
94 dVal
= ImpINT64ToDouble( p
->nLong64
);
95 else if( p
->eType
== SbxULONG64
)
96 dVal
= ImpUINT64ToDouble( p
->nULong64
);
97 else if( p
->eType
== SbxSALINT64
)
98 dVal
= static_cast< double >(p
->nInt64
);
99 else if( p
->eType
== SbxSALUINT64
)
100 dVal
= ImpSalUInt64ToDouble( p
->uInt64
);
101 else if( p
->eType
== SbxDECIMAL
)
105 p
->pDecimal
->getDouble( dVal
);
110 if( dVal
> SbxMAXLNG
)
112 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXLNG
;
114 else if( dVal
< SbxMINLNG
)
116 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINLNG
;
119 nRes
= (INT32
) ImpRound( dVal
);
122 case SbxBYREF
| SbxSTRING
:
131 if( ImpScan( *p
->pString
, d
, t
, NULL
) != SbxERR_OK
)
133 else if( d
> SbxMAXLNG
)
135 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXLNG
;
137 else if( d
< SbxMINLNG
)
139 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINLNG
;
142 nRes
= (INT32
) ImpRound( d
);
147 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
149 nRes
= pVal
->GetLong();
152 SbxBase::SetError( SbxERR_NO_OBJECT
); nRes
= 0;
157 case SbxBYREF
| SbxCHAR
:
158 nRes
= *p
->pChar
; break;
159 case SbxBYREF
| SbxBYTE
:
160 nRes
= *p
->pByte
; break;
161 case SbxBYREF
| SbxINTEGER
:
162 case SbxBYREF
| SbxBOOL
:
163 nRes
= *p
->pInteger
; break;
164 case SbxBYREF
| SbxLONG
:
165 nRes
= *p
->pLong
; break;
167 // ab hier muss getestet werden
168 case SbxBYREF
| SbxULONG
:
169 aTmp
.nULong
= *p
->pULong
; goto ref
;
170 case SbxBYREF
| SbxERROR
:
171 case SbxBYREF
| SbxUSHORT
:
172 aTmp
.nUShort
= *p
->pUShort
; goto ref
;
173 case SbxBYREF
| SbxSINGLE
:
174 aTmp
.nSingle
= *p
->pSingle
; goto ref
;
175 case SbxBYREF
| SbxDATE
:
176 case SbxBYREF
| SbxDOUBLE
:
177 aTmp
.nDouble
= *p
->pDouble
; goto ref
;
178 case SbxBYREF
| SbxSALINT64
:
179 aTmp
.nInt64
= *p
->pnInt64
; goto ref
;
180 case SbxBYREF
| SbxSALUINT64
:
181 aTmp
.uInt64
= *p
->puInt64
; goto ref
;
182 case SbxBYREF
| SbxULONG64
:
183 aTmp
.nULong64
= *p
->pULong64
; goto ref
;
184 case SbxBYREF
| SbxLONG64
:
185 case SbxBYREF
| SbxCURRENCY
:
186 aTmp
.nLong64
= *p
->pLong64
; goto ref
;
188 aTmp
.eType
= SbxDataType( p
->eType
& 0x0FFF );
189 p
= &aTmp
; goto start
;
192 SbxBase::SetError( SbxERR_CONVERSION
); nRes
= 0;
197 void ImpPutLong( SbxValues
* p
, INT32 n
)
204 // Ab hier muss getestet werden
206 aTmp
.pChar
= &p
->nChar
; goto direct
;
208 aTmp
.pByte
= &p
->nByte
; goto direct
;
211 aTmp
.pInteger
= &p
->nInteger
; goto direct
;
213 aTmp
.pULong64
= &p
->nULong64
; goto direct
;
216 aTmp
.pLong64
= &p
->nLong64
; goto direct
;
218 aTmp
.pULong
= &p
->nULong
; goto direct
;
220 aTmp
.puInt64
= &p
->uInt64
; goto direct
;
223 aTmp
.pUShort
= &p
->nUShort
;
225 aTmp
.eType
= SbxDataType( p
->eType
| SbxBYREF
);
226 p
= &aTmp
; goto start
;
228 // ab hier nicht mehr
232 p
->nSingle
= (float) n
; break;
235 p
->nDouble
= n
; break;
237 p
->nInt64
= n
; break;
239 case SbxBYREF
| SbxDECIMAL
:
240 ImpCreateDecimal( p
)->setLong( n
);
243 case SbxBYREF
| SbxSTRING
:
247 p
->pString
= new XubString
;
248 ImpCvtNum( (double) n
, 0, *p
->pString
);
252 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
256 SbxBase::SetError( SbxERR_NO_OBJECT
);
259 case SbxBYREF
| SbxCHAR
:
262 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXCHAR
;
264 else if( n
< SbxMINCHAR
)
266 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMINCHAR
;
268 *p
->pChar
= (xub_Unicode
) n
; break;
269 case SbxBYREF
| SbxBYTE
:
272 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXBYTE
;
276 SbxBase::SetError( SbxERR_OVERFLOW
); n
= 0;
278 *p
->pByte
= (BYTE
) n
; break;
279 case SbxBYREF
| SbxINTEGER
:
280 case SbxBYREF
| SbxBOOL
:
283 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXINT
;
285 else if( n
< SbxMININT
)
287 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMININT
;
289 *p
->pInteger
= (INT16
) n
; break;
290 case SbxBYREF
| SbxERROR
:
291 case SbxBYREF
| SbxUSHORT
:
294 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXUINT
;
298 SbxBase::SetError( SbxERR_OVERFLOW
); n
= 0;
300 *p
->pUShort
= (UINT16
) n
; break;
301 case SbxBYREF
| SbxLONG
:
302 *p
->pLong
= n
; break;
303 case SbxBYREF
| SbxULONG
:
306 SbxBase::SetError( SbxERR_OVERFLOW
); n
= 0;
308 *p
->pULong
= (UINT32
) n
; break;
309 case SbxBYREF
| SbxSALINT64
:
310 *p
->pnInt64
= n
; break;
311 case SbxBYREF
| SbxSALUINT64
:
314 SbxBase::SetError( SbxERR_OVERFLOW
); *p
->puInt64
= 0;
319 case SbxBYREF
| SbxSINGLE
:
320 *p
->pSingle
= (float) n
; break;
321 case SbxBYREF
| SbxDATE
:
322 case SbxBYREF
| SbxDOUBLE
:
323 *p
->pDouble
= (double) n
; break;
324 case SbxBYREF
| SbxCURRENCY
:
328 SbxBase::SetError( SbxERR_OVERFLOW
); d
= SbxMAXCURR
;
330 else if( n
< SbxMINCURR
)
332 SbxBase::SetError( SbxERR_OVERFLOW
); d
= SbxMINCURR
;
338 *p
->pLong64
= ImpDoubleToCurrency( d
); break;
341 SbxBase::SetError( SbxERR_CONVERSION
);