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: sbxulng.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 UINT32
ImpGetULong( const SbxValues
* p
)
45 SbxBase::SetError( SbxERR_CONVERSION
);
52 nRes
= p
->nByte
; break;
57 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
69 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
75 nRes
= p
->nULong
; break;
77 if( p
->nSingle
> SbxMAXULNG
)
79 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXULNG
;
81 else if( p
->nSingle
< 0 )
83 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
86 nRes
= (UINT32
) ( p
->nSingle
+ 0.5 );
96 case SbxBYREF
| SbxDECIMAL
:
99 if( p
->eType
== SbxCURRENCY
)
100 dVal
= ImpCurrencyToDouble( p
->nLong64
);
101 else if( p
->eType
== SbxLONG64
)
102 dVal
= ImpINT64ToDouble( p
->nLong64
);
103 else if( p
->eType
== SbxULONG64
)
104 dVal
= ImpUINT64ToDouble( p
->nULong64
);
105 else if( p
->eType
== SbxSALINT64
)
106 dVal
= static_cast< double >(p
->nInt64
);
107 else if( p
->eType
== SbxSALUINT64
)
108 dVal
= ImpSalUInt64ToDouble( p
->uInt64
);
109 else if( p
->eType
== SbxDECIMAL
)
113 p
->pDecimal
->getDouble( dVal
);
118 if( dVal
> SbxMAXULNG
)
120 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXULNG
;
124 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
127 nRes
= (UINT32
) ( dVal
+ 0.5 );
130 case SbxBYREF
| SbxSTRING
:
139 if( ImpScan( *p
->pString
, d
, t
, NULL
) != SbxERR_OK
)
141 else if( d
> SbxMAXULNG
)
143 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXULNG
;
147 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
150 nRes
= (UINT32
) ( d
+ 0.5 );
155 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
157 nRes
= pVal
->GetULong();
160 SbxBase::SetError( SbxERR_NO_OBJECT
); nRes
= 0;
165 case SbxBYREF
| SbxBYTE
:
166 nRes
= *p
->pByte
; break;
167 case SbxBYREF
| SbxERROR
:
168 case SbxBYREF
| SbxUSHORT
:
169 nRes
= *p
->pUShort
; break;
170 case SbxBYREF
| SbxULONG
:
171 nRes
= *p
->pULong
; break;
174 case SbxBYREF
| SbxCHAR
:
175 aTmp
.nChar
= *p
->pChar
; goto ref
;
176 case SbxBYREF
| SbxINTEGER
:
177 case SbxBYREF
| SbxBOOL
:
178 aTmp
.nInteger
= *p
->pInteger
; goto ref
;
179 case SbxBYREF
| SbxLONG
:
180 aTmp
.nLong
= *p
->pLong
; goto ref
;
181 case SbxBYREF
| SbxSINGLE
:
182 aTmp
.nSingle
= *p
->pSingle
; goto ref
;
183 case SbxBYREF
| SbxDATE
:
184 case SbxBYREF
| SbxDOUBLE
:
185 aTmp
.nDouble
= *p
->pDouble
; goto ref
;
186 case SbxBYREF
| SbxSALINT64
:
187 aTmp
.nInt64
= *p
->pnInt64
; goto ref
;
188 case SbxBYREF
| SbxSALUINT64
:
189 aTmp
.uInt64
= *p
->puInt64
; goto ref
;
190 case SbxBYREF
| SbxULONG64
:
191 aTmp
.nULong64
= *p
->pULong64
; goto ref
;
192 case SbxBYREF
| SbxLONG64
:
193 case SbxBYREF
| SbxCURRENCY
:
194 aTmp
.nLong64
= *p
->pLong64
; goto ref
;
196 aTmp
.eType
= SbxDataType( p
->eType
& 0x0FFF );
197 p
= &aTmp
; goto start
;
200 SbxBase::SetError( SbxERR_CONVERSION
); nRes
= 0;
205 void ImpPutULong( SbxValues
* p
, UINT32 n
)
212 p
->nULong
= n
; break;
214 p
->nSingle
= (float) n
; break;
217 p
->nDouble
= n
; break;
219 p
->nInt64
= n
; break;
221 p
->uInt64
= n
; break;
223 case SbxBYREF
| SbxDECIMAL
:
224 ImpCreateDecimal( p
)->setULong( n
);
229 aTmp
.pChar
= &p
->nChar
; goto direct
;
231 aTmp
.pByte
= &p
->nByte
; goto direct
;
234 aTmp
.pInteger
= &p
->nInteger
; goto direct
;
236 aTmp
.pLong
= &p
->nLong
; goto direct
;
239 aTmp
.pUShort
= &p
->nUShort
; goto direct
;
241 aTmp
.pULong64
= &p
->nULong64
; goto direct
;
244 aTmp
.pLong64
= &p
->nLong64
; goto direct
;
246 aTmp
.eType
= SbxDataType( p
->eType
| SbxBYREF
);
247 p
= &aTmp
; goto start
;
249 case SbxBYREF
| SbxSTRING
:
253 p
->pString
= new XubString
;
254 ImpCvtNum( (double) n
, 0, *p
->pString
);
258 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
262 SbxBase::SetError( SbxERR_NO_OBJECT
);
265 case SbxBYREF
| SbxCHAR
:
268 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXCHAR
;
270 *p
->pChar
= (xub_Unicode
) n
; break;
271 case SbxBYREF
| SbxBYTE
:
274 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXBYTE
;
276 *p
->pByte
= (BYTE
) n
; break;
277 case SbxBYREF
| SbxINTEGER
:
278 case SbxBYREF
| SbxBOOL
:
281 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXINT
;
283 *p
->pInteger
= (INT16
) n
; break;
284 case SbxBYREF
| SbxERROR
:
285 case SbxBYREF
| SbxUSHORT
:
288 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXUINT
;
290 *p
->pUShort
= (UINT16
) n
; break;
291 case SbxBYREF
| SbxLONG
:
294 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXLNG
;
296 *p
->pLong
= (INT32
) n
; break;
297 case SbxBYREF
| SbxULONG
:
298 *p
->pULong
= n
; break;
299 case SbxBYREF
| SbxSINGLE
:
300 *p
->pSingle
= (float) n
; break;
301 case SbxBYREF
| SbxDATE
:
302 case SbxBYREF
| SbxDOUBLE
:
303 *p
->pDouble
= n
; break;
304 case SbxBYREF
| SbxSALINT64
:
305 *p
->pnInt64
= n
; break;
306 case SbxBYREF
| SbxSALUINT64
:
307 *p
->puInt64
= n
; break;
308 case SbxBYREF
| SbxCURRENCY
:
312 SbxBase::SetError( SbxERR_OVERFLOW
); d
= SbxMAXCURR
;
318 *p
->pLong64
= ImpDoubleToCurrency( n
); break;
321 SbxBase::SetError( SbxERR_CONVERSION
);