Update ooo320-m1
[ooovba.git] / basic / source / sbx / sbxint.cxx
blob28bcebf5daeeff00e20468f7b6e68f3e59fd8e59
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sbxint.cxx,v $
10 * $Revision: 1.8 $
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 double ImpRound( double d )
39 return d + ( d < 0 ? -0.5 : 0.5 );
42 INT16 ImpGetInteger( const SbxValues* p )
44 SbxValues aTmp;
45 INT16 nRes;
46 start:
47 switch( +p->eType )
49 case SbxNULL:
50 SbxBase::SetError( SbxERR_CONVERSION );
51 case SbxEMPTY:
52 nRes = 0; break;
53 case SbxCHAR:
54 nRes = p->nChar; break;
55 case SbxBYTE:
56 nRes = p->nByte; break;
57 case SbxINTEGER:
58 case SbxBOOL:
59 nRes = p->nInteger; break;
60 case SbxERROR:
61 case SbxUSHORT:
62 if( p->nUShort > (USHORT) SbxMAXINT )
64 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
66 else
67 nRes = (INT16) p->nUShort;
68 break;
69 case SbxLONG:
70 if( p->nLong > SbxMAXINT )
72 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
74 else if( p->nLong < SbxMININT )
76 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
78 else
79 nRes = (INT16) p->nLong;
80 break;
81 case SbxULONG:
82 if( p->nULong > SbxMAXINT )
84 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
86 else
87 nRes = (INT16) p->nULong;
88 break;
89 case SbxSINGLE:
90 if( p->nSingle > SbxMAXINT )
92 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
94 else if( p->nSingle < SbxMININT )
96 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
98 else
99 nRes = (INT16) ImpRound( p->nSingle );
100 break;
101 case SbxSALINT64:
102 if( p->nInt64 > SbxMAXINT )
104 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
106 else if( p->nInt64 < SbxMININT )
108 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
110 else
111 nRes = (INT16) p->nInt64;
112 break;
113 case SbxSALUINT64:
114 if( p->uInt64 > SbxMAXINT )
116 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
118 else
119 nRes = (INT16) p->uInt64;
120 break;
121 case SbxDATE:
122 case SbxDOUBLE:
123 case SbxLONG64:
124 case SbxULONG64:
125 case SbxCURRENCY:
126 case SbxDECIMAL:
127 case SbxBYREF | SbxDECIMAL:
129 double dVal;
130 if( p->eType == SbxCURRENCY )
131 dVal = ImpCurrencyToDouble( p->nLong64 );
132 else if( p->eType == SbxLONG64 )
133 dVal = ImpINT64ToDouble( p->nLong64 );
134 else if( p->eType == SbxULONG64 )
135 dVal = ImpUINT64ToDouble( p->nULong64 );
136 else if( p->eType == SbxDECIMAL )
138 dVal = 0.0;
139 if( p->pDecimal )
140 p->pDecimal->getDouble( dVal );
142 else
143 dVal = p->nDouble;
145 if( dVal > SbxMAXINT )
147 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
149 else if( dVal < SbxMININT )
151 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
153 else
154 nRes = (INT16) ImpRound( dVal );
155 break;
157 case SbxLPSTR:
158 case SbxSTRING:
159 case SbxBYREF | SbxSTRING:
160 if( !p->pString )
161 nRes = 0;
162 else
164 double d;
165 SbxDataType t;
166 if( ImpScan( *p->pString, d, t, NULL ) != SbxERR_OK )
167 nRes = 0;
168 else if( d > SbxMAXINT )
170 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
172 else if( d < SbxMININT )
174 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
176 else
177 nRes = (INT16) ImpRound( d );
179 break;
180 case SbxOBJECT:
182 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
183 if( pVal )
184 nRes = pVal->GetInteger();
185 else
187 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
189 break;
192 case SbxBYREF | SbxCHAR:
193 nRes = *p->pChar; break;
194 case SbxBYREF | SbxBYTE:
195 nRes = *p->pByte; break;
196 case SbxBYREF | SbxINTEGER:
197 case SbxBYREF | SbxBOOL:
198 nRes = *p->pInteger; break;
200 // ab hier muss getestet werden
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 | SbxERROR:
206 case SbxBYREF | SbxUSHORT:
207 aTmp.nUShort = *p->pUShort; goto ref;
208 case SbxBYREF | SbxSINGLE:
209 aTmp.nSingle = *p->pSingle; goto ref;
210 case SbxBYREF | SbxDATE:
211 case SbxBYREF | SbxDOUBLE:
212 aTmp.nDouble = *p->pDouble; goto ref;
213 case SbxBYREF | SbxULONG64:
214 aTmp.nULong64 = *p->pULong64; goto ref;
215 case SbxBYREF | SbxLONG64:
216 case SbxBYREF | SbxCURRENCY:
217 aTmp.nLong64 = *p->pLong64; goto ref;
218 case SbxBYREF | SbxSALINT64:
219 aTmp.nInt64 = *p->pnInt64; goto ref;
220 case SbxBYREF | SbxSALUINT64:
221 aTmp.uInt64 = *p->puInt64; goto ref;
222 ref:
223 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
224 p = &aTmp; goto start;
226 default:
227 SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
229 return nRes;
232 void ImpPutInteger( SbxValues* p, INT16 n )
234 SbxValues aTmp;
235 start:
236 switch( +p->eType )
238 // hier muss getestet werden
239 case SbxCHAR:
240 aTmp.pChar = &p->nChar; goto direct;
241 case SbxBYTE:
242 aTmp.pByte = &p->nByte; goto direct;
243 case SbxULONG:
244 aTmp.pULong = &p->nULong; goto direct;
245 case SbxERROR:
246 case SbxUSHORT:
247 aTmp.pUShort = &p->nUShort; goto direct;
248 case SbxSALUINT64:
249 aTmp.puInt64 = &p->uInt64; goto direct;
250 direct:
251 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
252 p = &aTmp; goto start;
254 // ab hier nicht mehr
255 case SbxINTEGER:
256 case SbxBOOL:
257 p->nInteger = n; break;
258 case SbxLONG:
259 p->nLong = n; break;
260 case SbxSINGLE:
261 p->nSingle = n; break;
262 case SbxDATE:
263 case SbxDOUBLE:
264 p->nDouble = n; break;
265 case SbxSALINT64:
266 p->nInt64 = n; break;
267 case SbxULONG64:
268 p->nULong64 = ImpDoubleToUINT64( (double)n ); break;
269 case SbxLONG64:
270 p->nLong64 = ImpDoubleToINT64( (double)n ); break;
271 case SbxCURRENCY:
272 p->nLong64 = ImpDoubleToCurrency( (double)n ); break;
273 case SbxDECIMAL:
274 case SbxBYREF | SbxDECIMAL:
275 ImpCreateDecimal( p )->setInt( n );
276 break;
278 case SbxLPSTR:
279 case SbxSTRING:
280 case SbxBYREF | SbxSTRING:
281 if( !p->pString )
282 p->pString = new XubString;
283 ImpCvtNum( (double) n, 0, *p->pString );
284 break;
285 case SbxOBJECT:
287 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
288 if( pVal )
289 pVal->PutInteger( n );
290 else
291 SbxBase::SetError( SbxERR_NO_OBJECT );
292 break;
294 case SbxBYREF | SbxCHAR:
295 if( n < SbxMINCHAR )
297 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCHAR;
299 *p->pChar = (char) n; break;
300 case SbxBYREF | SbxBYTE:
301 if( n > SbxMAXBYTE )
303 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
305 else if( n < 0 )
307 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
309 *p->pByte = (BYTE) n; break;
310 case SbxBYREF | SbxINTEGER:
311 case SbxBYREF | SbxBOOL:
312 *p->pInteger = n; break;
313 case SbxBYREF | SbxERROR:
314 case SbxBYREF | SbxUSHORT:
315 if( n < 0 )
317 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
319 *p->pUShort = (UINT16) n; break;
320 case SbxBYREF | SbxLONG:
321 *p->pLong = (INT32) n; break;
322 case SbxBYREF | SbxULONG:
323 if( n < 0 )
325 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
327 *p->pULong = (UINT32) n; break;
328 case SbxBYREF | SbxSALINT64:
329 *p->pnInt64 = n; break;
330 case SbxBYREF | SbxSALUINT64:
331 if( n < 0 )
333 SbxBase::SetError( SbxERR_OVERFLOW ); *p->puInt64 = 0;
335 else
336 *p->puInt64 = n;
337 break;
338 case SbxBYREF | SbxSINGLE:
339 *p->pSingle = (float) n; break;
340 case SbxBYREF | SbxDATE:
341 case SbxBYREF | SbxDOUBLE:
342 *p->pDouble = (double) n; break;
343 case SbxBYREF | SbxULONG64:
344 *p->pULong64 = ImpDoubleToUINT64( (double)n ); break;
345 case SbxBYREF | SbxLONG64:
346 *p->pLong64 = ImpDoubleToINT64( (double)n ); break;
347 case SbxBYREF | SbxCURRENCY:
348 *p->pLong64 = ImpDoubleToCurrency( (double)n ); break;
350 default:
351 SbxBase::SetError( SbxERR_CONVERSION );
356 // sal_Int64 / hyper
358 sal_Int64 ImpDoubleToSalInt64( double d )
360 sal_Int64 nRes;
361 if( d > SbxMAXSALINT64 )
363 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALINT64;
365 else if( d < SbxMINSALINT64 )
367 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINSALINT64;
369 else
370 nRes = (sal_Int64) ImpRound( d );
371 return nRes;
374 sal_uInt64 ImpDoubleToSalUInt64( double d )
376 sal_uInt64 nRes;
377 if( d > SbxMAXSALUINT64 )
379 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALUINT64;
381 else if( d < 0.0 )
383 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
385 else
386 nRes = (sal_uInt64) ImpRound( d );
387 return nRes;
390 double ImpSalUInt64ToDouble( sal_uInt64 n )
392 double d = 0.0;
393 if( n > SbxMAXSALINT64 )
394 SbxBase::SetError( SbxERR_CONVERSION );
395 else
396 d = (double)(sal_Int64) n;
397 return d;
401 sal_Int64 ImpGetInt64( const SbxValues* p )
403 SbxValues aTmp;
404 sal_Int64 nRes;
405 start:
406 switch( +p->eType )
408 case SbxNULL:
409 SbxBase::SetError( SbxERR_CONVERSION );
410 case SbxEMPTY:
411 nRes = 0; break;
412 case SbxCHAR:
413 nRes = p->nChar; break;
414 case SbxBYTE:
415 nRes = p->nByte; break;
416 case SbxINTEGER:
417 case SbxBOOL:
418 nRes = p->nInteger; break;
419 case SbxERROR:
420 case SbxUSHORT:
421 nRes = p->nUShort; break;
422 case SbxLONG:
423 nRes = p->nLong; break;
424 case SbxULONG:
425 nRes = (sal_Int64) p->nULong; break;
426 case SbxSINGLE:
427 nRes = ImpDoubleToSalInt64( (double)p->nSingle );
428 break;
429 case SbxDATE:
430 case SbxDOUBLE:
431 case SbxLONG64:
432 case SbxULONG64:
433 case SbxCURRENCY:
435 double dVal;
436 if( p->eType == SbxCURRENCY )
437 dVal = ImpCurrencyToDouble( p->nLong64 );
438 else if( p->eType == SbxLONG64 )
439 dVal = ImpINT64ToDouble( p->nLong64 );
440 else if( p->eType == SbxULONG64 )
441 dVal = ImpUINT64ToDouble( p->nULong64 );
442 else
443 dVal = p->nDouble;
445 nRes = ImpDoubleToSalInt64( dVal );
446 break;
448 case SbxSALINT64:
449 nRes = p->nInt64; break;
450 case SbxSALUINT64:
451 if( p->uInt64 > SbxMAXSALINT64 )
453 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALINT64;
455 else
456 nRes = (sal_Int64) p->uInt64;
457 break;
459 case SbxBYREF | SbxSTRING:
460 case SbxSTRING:
461 case SbxLPSTR:
462 if( !p->pString )
463 nRes = 0;
464 else
466 ::rtl::OUString aOUStr( *p->pString );
467 ::rtl::OString aOStr = ::rtl::OUStringToOString
468 ( aOUStr, RTL_TEXTENCODING_ASCII_US );
469 nRes = aOStr.toInt64();
470 if( nRes == 0 )
472 // Check if really 0 or invalid conversion
473 double d;
474 SbxDataType t;
475 if( ImpScan( *p->pString, d, t, NULL ) != SbxERR_OK )
476 nRes = 0;
477 else
478 nRes = ImpDoubleToSalInt64( d );
481 break;
482 case SbxOBJECT:
484 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
485 if( pVal )
486 nRes = pVal->GetInt64();
487 else
489 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
491 break;
494 case SbxBYREF | SbxCHAR:
495 nRes = *p->pChar; break;
496 case SbxBYREF | SbxBYTE:
497 nRes = *p->pByte; break;
498 case SbxBYREF | SbxINTEGER:
499 case SbxBYREF | SbxBOOL:
500 nRes = *p->pInteger; break;
501 case SbxBYREF | SbxLONG:
502 nRes = *p->pLong; break;
503 case SbxBYREF | SbxULONG:
504 nRes = *p->pULong; break;
505 case SbxBYREF | SbxSALINT64:
506 nRes = *p->pnInt64; break;
508 // from here the values has to be checked
509 case SbxBYREF | SbxERROR:
510 case SbxBYREF | SbxUSHORT:
511 aTmp.nUShort = *p->pUShort; goto ref;
512 case SbxBYREF | SbxSINGLE:
513 aTmp.nSingle = *p->pSingle; goto ref;
514 case SbxBYREF | SbxDATE:
515 case SbxBYREF | SbxDOUBLE:
516 aTmp.nDouble = *p->pDouble; goto ref;
517 case SbxBYREF | SbxULONG64:
518 aTmp.nULong64 = *p->pULong64; goto ref;
519 case SbxBYREF | SbxLONG64:
520 case SbxBYREF | SbxCURRENCY:
521 aTmp.nLong64 = *p->pLong64; goto ref;
522 case SbxBYREF | SbxSALUINT64:
523 aTmp.uInt64 = *p->puInt64; goto ref;
524 ref:
525 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
526 p = &aTmp; goto start;
528 default:
529 SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
531 return nRes;
534 void ImpPutInt64( SbxValues* p, sal_Int64 n )
536 SbxValues aTmp;
538 start:
539 switch( +p->eType )
541 // Check neccessary
542 case SbxCHAR:
543 aTmp.pChar = &p->nChar; goto direct;
544 case SbxBYTE:
545 aTmp.pByte = &p->nByte; goto direct;
546 case SbxINTEGER:
547 case SbxBOOL:
548 aTmp.pInteger = &p->nInteger; goto direct;
549 case SbxULONG64:
550 aTmp.pULong64 = &p->nULong64; goto direct;
551 case SbxLONG64:
552 case SbxCURRENCY:
553 aTmp.pLong64 = &p->nLong64; goto direct;
554 case SbxULONG:
555 aTmp.pULong = &p->nULong; goto direct;
556 case SbxERROR:
557 case SbxUSHORT:
558 aTmp.pUShort = &p->nUShort; goto direct;
559 case SbxLONG:
560 aTmp.pnInt64 = &p->nInt64; goto direct;
561 case SbxSALUINT64:
562 aTmp.puInt64 = &p->uInt64; goto direct;
564 direct:
565 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
566 p = &aTmp; goto start;
568 // Check not neccessary
569 case SbxSALINT64:
570 p->nInt64 = n; break;
571 case SbxSINGLE:
572 p->nSingle = (float) n; break;
573 case SbxDATE:
574 case SbxDOUBLE:
575 p->nDouble = (double) n; break;
577 case SbxBYREF | SbxSTRING:
578 case SbxSTRING:
579 case SbxLPSTR:
581 if( !p->pString )
582 p->pString = new XubString;
584 ::rtl::OString aOStr = ::rtl::OString::valueOf( n );
585 ::rtl::OUString aOUStr = ::rtl::OStringToOUString
586 ( aOStr, RTL_TEXTENCODING_ASCII_US );
587 (*p->pString) = aOUStr;
588 break;
590 case SbxOBJECT:
592 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
593 if( pVal )
594 pVal->PutInt64( n );
595 else
596 SbxBase::SetError( SbxERR_NO_OBJECT );
597 break;
599 case SbxBYREF | SbxCHAR:
600 if( n > SbxMAXCHAR )
602 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCHAR;
604 else if( n < SbxMINCHAR )
606 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCHAR;
608 *p->pChar = (xub_Unicode) n; break;
609 case SbxBYREF | SbxBYTE:
610 if( n > SbxMAXBYTE )
612 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
614 else if( n < 0 )
616 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
618 *p->pByte = (BYTE) n; break;
619 case SbxBYREF | SbxINTEGER:
620 case SbxBYREF | SbxBOOL:
621 if( n > SbxMAXINT )
623 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXINT;
625 else if( n < SbxMININT )
627 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMININT;
629 *p->pInteger = (INT16) n; break;
630 case SbxBYREF | SbxERROR:
631 case SbxBYREF | SbxUSHORT:
632 if( n > SbxMAXUINT )
634 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXUINT;
636 else if( n < 0 )
638 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
640 *p->pUShort = (UINT16) n; break;
641 case SbxBYREF | SbxLONG:
642 if( n > SbxMAXLNG )
644 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXLNG;
646 else if( n < SbxMINLNG )
648 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINLNG;
650 *p->pLong = (INT32) n; break;
651 case SbxBYREF | SbxULONG:
652 if( n > SbxMAXULNG )
654 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXULNG;
656 else if( n < 0 )
658 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
660 *p->pULong = (UINT32) n; break;
661 case SbxBYREF | SbxSINGLE:
662 *p->pSingle = (float) n; break;
663 case SbxBYREF | SbxDATE:
664 case SbxBYREF | SbxDOUBLE:
665 *p->pDouble = (double) n; break;
666 case SbxBYREF | SbxCURRENCY:
667 if( n > SbxMAXCURR )
669 SbxBase::SetError( SbxERR_OVERFLOW ); n = (sal_Int64) SbxMAXCURR;
671 else if( n < SbxMINCURR )
673 SbxBase::SetError( SbxERR_OVERFLOW ); n = (sal_Int64) SbxMINCURR;
675 *p->pLong64 = ImpDoubleToCurrency( (double)n ); break;
677 case SbxBYREF | SbxSALINT64:
678 *p->pnInt64 = n; break;
679 case SbxBYREF | SbxSALUINT64:
680 if( n < 0 )
682 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
684 *p->puInt64 = (sal_Int64) n; break;
686 default:
687 SbxBase::SetError( SbxERR_CONVERSION );
691 sal_uInt64 ImpGetUInt64( const SbxValues* p )
693 SbxValues aTmp;
694 sal_uInt64 nRes;
695 start:
696 switch( +p->eType )
698 case SbxNULL:
699 SbxBase::SetError( SbxERR_CONVERSION );
700 case SbxEMPTY:
701 nRes = 0; break;
702 case SbxCHAR:
703 nRes = p->nChar; break;
704 case SbxBYTE:
705 nRes = p->nByte; break;
706 case SbxINTEGER:
707 case SbxBOOL:
708 nRes = p->nInteger; break;
709 case SbxERROR:
710 case SbxUSHORT:
711 nRes = p->nUShort; break;
712 case SbxLONG:
713 nRes = p->nLong; break;
714 case SbxULONG:
715 nRes = (sal_uInt64) p->nULong; break;
716 case SbxSINGLE:
717 nRes = ImpDoubleToSalUInt64( (double)p->nSingle );
718 break;
719 case SbxDATE:
720 case SbxDOUBLE:
721 case SbxLONG64:
722 case SbxULONG64:
723 case SbxCURRENCY:
725 double dVal;
726 if( p->eType == SbxCURRENCY )
727 dVal = ImpCurrencyToDouble( p->nLong64 );
728 else if( p->eType == SbxLONG64 )
729 dVal = ImpINT64ToDouble( p->nLong64 );
730 else if( p->eType == SbxULONG64 )
731 dVal = ImpUINT64ToDouble( p->nULong64 );
732 else
733 dVal = p->nDouble;
735 nRes = ImpDoubleToSalUInt64( dVal );
736 break;
738 case SbxSALINT64:
739 if( p->nInt64 < 0 )
741 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
743 else
744 nRes = (sal_uInt64) p->nInt64;
745 case SbxSALUINT64:
746 nRes = p->uInt64; break;
748 case SbxBYREF | SbxSTRING:
749 case SbxSTRING:
750 case SbxLPSTR:
751 if( !p->pString )
752 nRes = 0;
753 else
755 ::rtl::OUString aOUStr( *p->pString );
756 ::rtl::OString aOStr = ::rtl::OUStringToOString
757 ( aOUStr, RTL_TEXTENCODING_ASCII_US );
758 sal_Int64 n64 = aOStr.toInt64();
759 if( n64 == 0 )
761 // Check if really 0 or invalid conversion
762 double d;
763 SbxDataType t;
764 if( ImpScan( *p->pString, d, t, NULL ) != SbxERR_OK )
765 nRes = 0;
766 else if( d > SbxMAXSALUINT64 )
768 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALUINT64;
770 else if( d < 0.0 )
772 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
774 else
775 nRes = (sal_uInt64) ImpRound( d );
777 else if( n64 < 0 )
779 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
781 else
783 nRes = n64;
786 break;
787 case SbxOBJECT:
789 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
790 if( pVal )
791 nRes = pVal->GetUInt64();
792 else
794 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
796 break;
799 case SbxBYREF | SbxCHAR:
800 nRes = *p->pChar; break;
801 case SbxBYREF | SbxBYTE:
802 nRes = *p->pByte; break;
803 case SbxBYREF | SbxINTEGER:
804 case SbxBYREF | SbxBOOL:
805 nRes = *p->pInteger; break;
806 case SbxBYREF | SbxLONG:
807 nRes = *p->pLong; break;
808 case SbxBYREF | SbxULONG:
809 nRes = *p->pULong; break;
810 case SbxBYREF | SbxSALUINT64:
811 nRes = *p->puInt64; break;
813 // from here the values has to be checked
814 case SbxBYREF | SbxERROR:
815 case SbxBYREF | SbxUSHORT:
816 aTmp.nUShort = *p->pUShort; goto ref;
817 case SbxBYREF | SbxSINGLE:
818 aTmp.nSingle = *p->pSingle; goto ref;
819 case SbxBYREF | SbxDATE:
820 case SbxBYREF | SbxDOUBLE:
821 aTmp.nDouble = *p->pDouble; goto ref;
822 case SbxBYREF | SbxULONG64:
823 aTmp.nULong64 = *p->pULong64; goto ref;
824 case SbxBYREF | SbxLONG64:
825 case SbxBYREF | SbxCURRENCY:
826 aTmp.nLong64 = *p->pLong64; goto ref;
827 case SbxBYREF | SbxSALINT64:
828 aTmp.nInt64 = *p->pnInt64; goto ref;
829 ref:
830 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
831 p = &aTmp; goto start;
833 default:
834 SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
836 return nRes;
839 void ImpPutUInt64( SbxValues* p, sal_uInt64 n )
841 SbxValues aTmp;
843 start:
844 switch( +p->eType )
846 // Check neccessary
847 case SbxCHAR:
848 aTmp.pChar = &p->nChar; goto direct;
849 case SbxBYTE:
850 aTmp.pByte = &p->nByte; goto direct;
851 case SbxINTEGER:
852 case SbxBOOL:
853 aTmp.pInteger = &p->nInteger; goto direct;
854 case SbxULONG64:
855 aTmp.pULong64 = &p->nULong64; goto direct;
856 case SbxLONG64:
857 case SbxCURRENCY:
858 aTmp.pLong64 = &p->nLong64; goto direct;
859 case SbxULONG:
860 aTmp.pULong = &p->nULong; goto direct;
861 case SbxERROR:
862 case SbxUSHORT:
863 aTmp.pUShort = &p->nUShort; goto direct;
864 case SbxLONG:
865 aTmp.pnInt64 = &p->nInt64; goto direct;
866 case SbxSALINT64:
867 aTmp.pnInt64 = &p->nInt64; goto direct;
868 case SbxSINGLE:
869 aTmp.pSingle = &p->nSingle; goto direct;
870 case SbxDATE:
871 case SbxDOUBLE:
872 aTmp.pDouble = &p->nDouble; goto direct;
874 direct:
875 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
876 p = &aTmp; goto start;
878 // Check not neccessary
879 case SbxSALUINT64:
880 p->uInt64 = n; break;
882 case SbxBYREF | SbxSTRING:
883 case SbxSTRING:
884 case SbxLPSTR:
885 if( !p->pString )
886 p->pString = new XubString;
887 if( n > SbxMAXSALINT64 )
888 SbxBase::SetError( SbxERR_CONVERSION );
889 else
891 ::rtl::OString aOStr = ::rtl::OString::valueOf( (sal_Int64)n );
892 ::rtl::OUString aOUStr = ::rtl::OStringToOUString
893 ( aOStr, RTL_TEXTENCODING_ASCII_US );
894 (*p->pString) = aOUStr;
896 break;
897 case SbxOBJECT:
899 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
900 if( pVal )
901 pVal->PutUInt64( n );
902 else
903 SbxBase::SetError( SbxERR_NO_OBJECT );
904 break;
906 case SbxBYREF | SbxCHAR:
907 if( n > SbxMAXCHAR )
909 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCHAR;
911 *p->pChar = (xub_Unicode) n; break;
912 case SbxBYREF | SbxBYTE:
913 if( n > SbxMAXBYTE )
915 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
917 *p->pByte = (BYTE) n; break;
918 case SbxBYREF | SbxINTEGER:
919 case SbxBYREF | SbxBOOL:
920 if( n > SbxMAXINT )
922 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXINT;
924 *p->pInteger = (INT16) n; break;
925 case SbxBYREF | SbxERROR:
926 case SbxBYREF | SbxUSHORT:
927 if( n > SbxMAXUINT )
929 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXUINT;
931 *p->pUShort = (UINT16) n; break;
932 case SbxBYREF | SbxLONG:
933 if( n > SbxMAXLNG )
935 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXLNG;
937 *p->pLong = (INT32) n; break;
938 case SbxBYREF | SbxULONG:
939 if( n > SbxMAXULNG )
941 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXULNG;
943 *p->pULong = (UINT32) n; break;
944 case SbxBYREF | SbxSINGLE:
945 *p->pDouble = (float)ImpSalUInt64ToDouble( n ); break;
946 case SbxBYREF | SbxDATE:
947 case SbxBYREF | SbxDOUBLE:
948 *p->pDouble = ImpSalUInt64ToDouble( n ); break;
949 case SbxBYREF | SbxCURRENCY:
950 if( n > SbxMAXSALINT64 || (sal_Int64)n > SbxMAXCURR )
952 SbxBase::SetError( SbxERR_OVERFLOW ); n = (sal_Int64) SbxMAXCURR;
954 *p->pLong64 = ImpDoubleToCurrency( (double)(sal_Int64) n ); break;
956 case SbxBYREF | SbxSALUINT64:
957 *p->puInt64 = n; break;
958 case SbxBYREF | SbxSALINT64:
959 if( n > SbxMAXSALINT64 )
961 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
963 *p->pnInt64 = (sal_Int64) n; break;
965 default:
966 SbxBase::SetError( SbxERR_CONVERSION );