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: sbxuint.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 UINT16
ImpGetUShort( const SbxValues
* p
)
45 SbxBase::SetError( SbxERR_CONVERSION
);
52 nRes
= p
->nByte
; break;
57 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
67 if( p
->nLong
> SbxMAXUINT
)
69 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXUINT
;
71 else if( p
->nLong
< 0 )
73 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
76 nRes
= (UINT16
) p
->nLong
;
79 if( p
->nULong
> SbxMAXUINT
)
81 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXUINT
;
84 nRes
= (UINT16
) p
->nULong
;
87 if( p
->nInt64
> SbxMAXUINT
)
89 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXUINT
;
91 else if( p
->nInt64
< 0 )
93 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
96 nRes
= (UINT16
) p
->nInt64
;
99 if( p
->uInt64
> SbxMAXUINT
)
101 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXUINT
;
104 nRes
= (UINT16
) p
->uInt64
;
107 if( p
->nSingle
> SbxMAXUINT
)
109 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXUINT
;
111 else if( p
->nSingle
< 0 )
113 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
116 nRes
= (UINT16
) ( p
->nSingle
+ 0.5 );
124 case SbxBYREF
| SbxDECIMAL
:
127 if( p
->eType
== SbxCURRENCY
)
128 dVal
= ImpCurrencyToDouble( p
->nLong64
);
129 else if( p
->eType
== SbxLONG64
)
130 dVal
= ImpINT64ToDouble( p
->nLong64
);
131 else if( p
->eType
== SbxULONG64
)
132 dVal
= ImpUINT64ToDouble( p
->nULong64
);
133 else if( p
->eType
== SbxDECIMAL
)
137 p
->pDecimal
->getDouble( dVal
);
142 if( dVal
> SbxMAXUINT
)
144 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXUINT
;
148 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
151 nRes
= (UINT16
) ( dVal
+ 0.5 );
154 case SbxBYREF
| SbxSTRING
:
163 if( ImpScan( *p
->pString
, d
, t
, NULL
) != SbxERR_OK
)
165 else if( d
> SbxMAXUINT
)
167 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXUINT
;
171 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
174 nRes
= (UINT16
) ( d
+ 0.5 );
179 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
181 nRes
= pVal
->GetUShort();
184 SbxBase::SetError( SbxERR_NO_OBJECT
); nRes
= 0;
189 case SbxBYREF
| SbxBYTE
:
190 nRes
= *p
->pByte
; break;
191 case SbxBYREF
| SbxERROR
:
192 case SbxBYREF
| SbxUSHORT
:
193 nRes
= *p
->pUShort
; break;
195 // ab hier wird getestet
196 case SbxBYREF
| SbxCHAR
:
197 aTmp
.nChar
= *p
->pChar
; goto ref
;
198 case SbxBYREF
| SbxINTEGER
:
199 case SbxBYREF
| SbxBOOL
:
200 aTmp
.nInteger
= *p
->pInteger
; goto ref
;
201 case SbxBYREF
| SbxLONG
:
202 aTmp
.nLong
= *p
->pLong
; goto ref
;
203 case SbxBYREF
| SbxULONG
:
204 aTmp
.nULong
= *p
->pULong
; goto ref
;
205 case SbxBYREF
| SbxSINGLE
:
206 aTmp
.nSingle
= *p
->pSingle
; goto ref
;
207 case SbxBYREF
| SbxDATE
:
208 case SbxBYREF
| SbxDOUBLE
:
209 aTmp
.nDouble
= *p
->pDouble
; goto ref
;
210 case SbxBYREF
| SbxULONG64
:
211 aTmp
.nULong64
= *p
->pULong64
; goto ref
;
212 case SbxBYREF
| SbxLONG64
:
213 case SbxBYREF
| SbxCURRENCY
:
214 aTmp
.nLong64
= *p
->pLong64
; goto ref
;
215 case SbxBYREF
| SbxSALINT64
:
216 aTmp
.nInt64
= *p
->pnInt64
; goto ref
;
217 case SbxBYREF
| SbxSALUINT64
:
218 aTmp
.uInt64
= *p
->puInt64
; goto ref
;
220 aTmp
.eType
= SbxDataType( p
->eType
& 0x0FFF );
221 p
= &aTmp
; goto start
;
224 SbxBase::SetError( SbxERR_CONVERSION
); nRes
= 0;
229 void ImpPutUShort( SbxValues
* p
, UINT16 n
)
238 p
->nUShort
= n
; break;
242 p
->nULong
= n
; break;
244 p
->nSingle
= n
; break;
247 p
->nDouble
= n
; break;
249 p
->nInt64
= n
; break;
251 p
->uInt64
= n
; break;
253 p
->nULong64
= ImpDoubleToUINT64( (double)n
); break;
255 p
->nLong64
= ImpDoubleToINT64( (double)n
); break;
257 p
->nLong64
= ImpDoubleToCurrency( (double)n
); break;
259 case SbxBYREF
| SbxDECIMAL
:
260 ImpCreateDecimal( p
)->setUInt( n
);
265 aTmp
.pChar
= &p
->nChar
; goto direct
;
267 aTmp
.pByte
= &p
->nByte
; goto direct
;
270 aTmp
.pInteger
= &p
->nInteger
;
272 aTmp
.eType
= SbxDataType( p
->eType
| SbxBYREF
);
273 p
= &aTmp
; goto start
;
275 case SbxBYREF
| SbxSTRING
:
279 p
->pString
= new XubString
;
280 ImpCvtNum( (double) n
, 0, *p
->pString
);
284 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
286 pVal
->PutUShort( n
);
288 SbxBase::SetError( SbxERR_NO_OBJECT
);
292 case SbxBYREF
| SbxCHAR
:
293 *p
->pChar
= (xub_Unicode
) n
; break;
294 case SbxBYREF
| SbxBYTE
:
297 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXBYTE
;
299 *p
->pByte
= (BYTE
) n
; break;
300 case SbxBYREF
| SbxINTEGER
:
301 case SbxBYREF
| SbxBOOL
:
304 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXINT
;
306 *p
->pInteger
= (INT16
) n
; break;
307 case SbxBYREF
| SbxERROR
:
308 case SbxBYREF
| SbxUSHORT
:
309 *p
->pUShort
= n
; break;
310 case SbxBYREF
| SbxLONG
:
311 *p
->pLong
= n
; break;
312 case SbxBYREF
| SbxULONG
:
313 *p
->pULong
= n
; break;
314 case SbxBYREF
| SbxSINGLE
:
315 *p
->pSingle
= n
; break;
316 case SbxBYREF
| SbxDATE
:
317 case SbxBYREF
| SbxDOUBLE
:
318 *p
->pDouble
= n
; break;
319 case SbxBYREF
| SbxSALINT64
:
320 *p
->pnInt64
= n
; break;
321 case SbxBYREF
| SbxSALUINT64
:
322 *p
->puInt64
= n
; break;
323 case SbxBYREF
| SbxULONG64
:
324 *p
->pULong64
= ImpDoubleToUINT64( (double)n
); break;
325 case SbxBYREF
| SbxLONG64
:
326 *p
->pLong64
= ImpDoubleToINT64( (double)n
); break;
327 case SbxBYREF
| SbxCURRENCY
:
328 *p
->pLong64
= ImpDoubleToCurrency( (double)n
); break;
331 SbxBase::SetError( SbxERR_CONVERSION
);