Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / basic / source / sbx / sbxint.cxx
blob61b601e3aec88a9ef1e668b9ab38d429c8c5e0a3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/errcode.hxx>
21 #include <basic/sbx.hxx>
22 #include "sbxconv.hxx"
24 double ImpRound( double d )
26 return d + ( d < 0 ? -0.5 : 0.5 );
29 sal_Int16 ImpGetInteger( const SbxValues* p )
31 SbxValues aTmp;
32 sal_Int16 nRes;
33 start:
34 switch( +p->eType )
36 case SbxNULL:
37 SbxBase::SetError( SbxERR_CONVERSION );
38 case SbxEMPTY:
39 nRes = 0; break;
40 case SbxCHAR:
41 nRes = p->nChar; break;
42 case SbxBYTE:
43 nRes = p->nByte; break;
44 case SbxINTEGER:
45 case SbxBOOL:
46 nRes = p->nInteger; break;
47 case SbxERROR:
48 case SbxUSHORT:
49 if( p->nUShort > (sal_uInt16) SbxMAXINT )
51 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
53 else
54 nRes = (sal_Int16) p->nUShort;
55 break;
56 case SbxLONG:
57 if( p->nLong > SbxMAXINT )
59 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
61 else if( p->nLong < SbxMININT )
63 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
65 else
66 nRes = (sal_Int16) p->nLong;
67 break;
68 case SbxULONG:
69 if( p->nULong > SbxMAXINT )
71 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
73 else
74 nRes = (sal_Int16) p->nULong;
75 break;
76 case SbxSINGLE:
77 if( p->nSingle > SbxMAXINT )
79 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
81 else if( p->nSingle < SbxMININT )
83 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
85 else
86 nRes = (sal_Int16) ImpRound( p->nSingle );
87 break;
88 case SbxCURRENCY:
90 sal_Int64 tstVal = (sal_Int64) p->nInt64 / (sal_Int64) CURRENCY_FACTOR;
92 if( tstVal > SbxMAXINT )
94 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
96 else if( tstVal < SbxMININT )
98 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
100 else
101 nRes = (sal_Int16) (tstVal);
102 break;
104 case SbxSALINT64:
105 if( p->nInt64 > SbxMAXINT )
107 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
109 else if( p->nInt64 < SbxMININT )
111 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
113 else
114 nRes = (sal_Int16) p->nInt64;
115 break;
116 case SbxSALUINT64:
117 if( p->uInt64 > SbxMAXINT )
119 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
121 else
122 nRes = (sal_Int16) p->uInt64;
123 break;
124 case SbxDATE:
125 case SbxDOUBLE:
126 case SbxDECIMAL:
127 case SbxBYREF | SbxDECIMAL:
129 double dVal = 0.0;
130 if( p->eType == SbxDECIMAL )
132 if( p->pDecimal )
133 p->pDecimal->getDouble( dVal );
135 else
136 dVal = p->nDouble;
138 if( dVal > SbxMAXINT )
140 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
142 else if( dVal < SbxMININT )
144 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
146 else
147 nRes = (sal_Int16) ImpRound( dVal );
148 break;
150 case SbxLPSTR:
151 case SbxSTRING:
152 case SbxBYREF | SbxSTRING:
153 if( !p->pOUString )
154 nRes = 0;
155 else
157 double d;
158 SbxDataType t;
159 if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
160 nRes = 0;
161 else if( d > SbxMAXINT )
163 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
165 else if( d < SbxMININT )
167 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
169 else
170 nRes = (sal_Int16) ImpRound( d );
172 break;
173 case SbxOBJECT:
175 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
176 if( pVal )
177 nRes = pVal->GetInteger();
178 else
180 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
182 break;
185 case SbxBYREF | SbxCHAR:
186 nRes = *p->pChar; break;
187 case SbxBYREF | SbxBYTE:
188 nRes = *p->pByte; break;
189 case SbxBYREF | SbxINTEGER:
190 case SbxBYREF | SbxBOOL:
191 nRes = *p->pInteger; break;
193 // from here had to be tested
194 case SbxBYREF | SbxLONG:
195 aTmp.nLong = *p->pLong; goto ref;
196 case SbxBYREF | SbxULONG:
197 aTmp.nULong = *p->pULong; goto ref;
198 case SbxBYREF | SbxERROR:
199 case SbxBYREF | SbxUSHORT:
200 aTmp.nUShort = *p->pUShort; goto ref;
201 case SbxBYREF | SbxSINGLE:
202 aTmp.nSingle = *p->pSingle; goto ref;
203 case SbxBYREF | SbxDATE:
204 case SbxBYREF | SbxDOUBLE:
205 aTmp.nDouble = *p->pDouble; goto ref;
206 case SbxBYREF | SbxCURRENCY:
207 case SbxBYREF | SbxSALINT64:
208 aTmp.nInt64 = *p->pnInt64; goto ref;
209 case SbxBYREF | SbxSALUINT64:
210 aTmp.uInt64 = *p->puInt64; goto ref;
211 ref:
212 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
213 p = &aTmp; goto start;
215 default:
216 SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
218 return nRes;
221 void ImpPutInteger( SbxValues* p, sal_Int16 n )
223 SbxValues aTmp;
224 start:
225 switch( +p->eType )
227 // here had to be tested
228 case SbxCHAR:
229 aTmp.pChar = &p->nChar; goto direct;
230 case SbxBYTE:
231 aTmp.pByte = &p->nByte; goto direct;
232 case SbxULONG:
233 aTmp.pULong = &p->nULong; goto direct;
234 case SbxERROR:
235 case SbxUSHORT:
236 aTmp.pUShort = &p->nUShort; goto direct;
237 case SbxSALUINT64:
238 aTmp.puInt64 = &p->uInt64; goto direct;
239 direct:
240 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
241 p = &aTmp; goto start;
243 // from here no tests needed
244 case SbxINTEGER:
245 case SbxBOOL:
246 p->nInteger = n; break;
247 case SbxLONG:
248 p->nLong = n; break;
249 case SbxSINGLE:
250 p->nSingle = n; break;
251 case SbxDATE:
252 case SbxDOUBLE:
253 p->nDouble = n; break;
254 case SbxCURRENCY:
255 p->nInt64 = n * CURRENCY_FACTOR; break;
256 case SbxSALINT64:
257 p->nInt64 = n; break;
258 case SbxDECIMAL:
259 case SbxBYREF | SbxDECIMAL:
260 ImpCreateDecimal( p )->setInt( n );
261 break;
263 case SbxLPSTR:
264 case SbxSTRING:
265 case SbxBYREF | SbxSTRING:
266 if( !p->pOUString )
267 p->pOUString = new ::rtl::OUString;
268 ImpCvtNum( (double) n, 0, *p->pOUString );
269 break;
270 case SbxOBJECT:
272 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
273 if( pVal )
274 pVal->PutInteger( n );
275 else
276 SbxBase::SetError( SbxERR_NO_OBJECT );
277 break;
279 case SbxBYREF | SbxCHAR:
280 if( n < SbxMINCHAR )
282 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCHAR;
284 *p->pChar = (char) n; break;
285 case SbxBYREF | SbxBYTE:
286 if( n > SbxMAXBYTE )
288 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
290 else if( n < 0 )
292 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
294 *p->pByte = (sal_uInt8) n; break;
295 case SbxBYREF | SbxINTEGER:
296 case SbxBYREF | SbxBOOL:
297 *p->pInteger = n; break;
298 case SbxBYREF | SbxERROR:
299 case SbxBYREF | SbxUSHORT:
300 if( n < 0 )
302 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
304 *p->pUShort = (sal_uInt16) n; break;
305 case SbxBYREF | SbxLONG:
306 *p->pLong = (sal_Int32) n; break;
307 case SbxBYREF | SbxULONG:
308 if( n < 0 )
310 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
312 *p->pULong = (sal_uInt32) n; break;
313 case SbxBYREF | SbxCURRENCY:
314 *p->pnInt64 = n * CURRENCY_FACTOR; break;
315 case SbxBYREF | SbxSALINT64:
316 *p->pnInt64 = n; break;
317 case SbxBYREF | SbxSALUINT64:
318 if( n < 0 )
320 SbxBase::SetError( SbxERR_OVERFLOW );
321 *p->puInt64 = 0;
323 else
324 *p->puInt64 = n;
325 break;
326 case SbxBYREF | SbxSINGLE:
327 *p->pSingle = (float) n; break;
328 case SbxBYREF | SbxDATE:
329 case SbxBYREF | SbxDOUBLE:
330 *p->pDouble = (double) n; break;
332 default:
333 SbxBase::SetError( SbxERR_CONVERSION );
338 // sal_Int64 / hyper
340 sal_Int64 ImpDoubleToSalInt64( double d )
342 sal_Int64 nRes;
343 if( d > SbxMAXSALINT64 )
345 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALINT64;
347 else if( d < SbxMINSALINT64 )
349 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINSALINT64;
351 else
352 nRes = (sal_Int64) ImpRound( d );
353 return nRes;
356 sal_uInt64 ImpDoubleToSalUInt64( double d )
358 sal_uInt64 nRes;
359 if( d > SbxMAXSALUINT64 )
361 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALUINT64;
363 else if( d < 0.0 )
365 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
367 else
368 nRes = (sal_uInt64) ImpRound( d );
369 return nRes;
373 double ImpSalUInt64ToDouble( sal_uInt64 n )
375 double d = 0.0;
376 if( n > SbxMAXSALINT64 )
377 SbxBase::SetError( SbxERR_CONVERSION );
378 else
379 d = (double)(sal_Int64) n;
380 return d;
384 sal_Int64 ImpGetInt64( const SbxValues* p )
386 SbxValues aTmp;
387 sal_Int64 nRes;
388 start:
389 switch( +p->eType )
391 case SbxNULL:
392 SbxBase::SetError( SbxERR_CONVERSION );
393 case SbxEMPTY:
394 nRes = 0; break;
395 case SbxCHAR:
396 nRes = p->nChar; break;
397 case SbxBYTE:
398 nRes = p->nByte; break;
399 case SbxINTEGER:
400 case SbxBOOL:
401 nRes = p->nInteger; break;
402 case SbxERROR:
403 case SbxUSHORT:
404 nRes = (sal_Int64) p->nUShort; break;
405 case SbxLONG:
406 nRes = (sal_Int64) p->nLong; break;
407 case SbxULONG:
408 nRes = (sal_Int64) p->nULong; break;
409 case SbxSINGLE:
410 nRes = (sal_Int64) p->nSingle;
411 break;
412 case SbxDATE:
413 case SbxDOUBLE:
414 nRes = (sal_Int64) p->nDouble;
415 break;
416 case SbxCURRENCY:
417 nRes = p->nInt64 / CURRENCY_FACTOR; break;
418 case SbxSALINT64:
419 nRes = p->nInt64; break;
420 case SbxSALUINT64:
421 if( p->uInt64 > SbxMAXSALINT64 )
423 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALINT64;
425 else
426 nRes = (sal_Int64) p->uInt64;
427 break;
429 case SbxBYREF | SbxSTRING:
430 case SbxSTRING:
431 case SbxLPSTR:
432 if( !p->pOUString )
433 nRes = 0;
434 else
436 ::rtl::OString aOStr = ::rtl::OUStringToOString
437 ( *p->pOUString, RTL_TEXTENCODING_ASCII_US );
438 nRes = aOStr.toInt64();
439 if( nRes == 0 )
441 // Check if really 0 or invalid conversion
442 double d;
443 SbxDataType t;
444 if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
445 nRes = 0;
446 else
447 nRes = (sal_Int64) d;
450 break;
451 case SbxOBJECT:
453 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
454 if( pVal )
455 nRes = pVal->GetInt64();
456 else
458 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
460 break;
463 case SbxBYREF | SbxCHAR:
464 nRes = *p->pChar; break;
465 case SbxBYREF | SbxBYTE:
466 nRes = *p->pByte; break;
467 case SbxBYREF | SbxINTEGER:
468 case SbxBYREF | SbxBOOL:
469 nRes = *p->pInteger; break;
470 case SbxBYREF | SbxLONG:
471 nRes = *p->pLong; break;
472 case SbxBYREF | SbxULONG:
473 nRes = *p->pULong; break;
474 case SbxBYREF | SbxCURRENCY:
475 nRes = p->nInt64 / CURRENCY_FACTOR; break;
476 case SbxBYREF | SbxSALINT64:
477 nRes = *p->pnInt64; break;
479 // from here the values has to be checked
480 case SbxBYREF | SbxSALUINT64:
481 aTmp.uInt64 = *p->puInt64; goto ref;
483 case SbxBYREF | SbxERROR:
484 case SbxBYREF | SbxUSHORT:
485 aTmp.nUShort = *p->pUShort; goto ref;
486 case SbxBYREF | SbxSINGLE:
487 aTmp.nSingle = *p->pSingle; goto ref;
488 case SbxBYREF | SbxDATE:
489 case SbxBYREF | SbxDOUBLE:
490 aTmp.nDouble = *p->pDouble; goto ref;
491 ref:
492 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
493 p = &aTmp; goto start;
495 default:
496 SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
498 return nRes;
501 void ImpPutInt64( SbxValues* p, sal_Int64 n )
503 SbxValues aTmp;
505 start:
506 switch( +p->eType )
508 // Check neccessary
509 case SbxCHAR:
510 aTmp.pChar = &p->nChar; goto direct;
511 case SbxBYTE:
512 aTmp.pByte = &p->nByte; goto direct;
513 case SbxINTEGER:
514 case SbxBOOL:
515 aTmp.pInteger = &p->nInteger; goto direct;
516 case SbxULONG:
517 aTmp.pULong = &p->nULong; goto direct;
518 case SbxERROR:
519 case SbxUSHORT:
520 aTmp.pUShort = &p->nUShort; goto direct;
521 case SbxLONG:
522 aTmp.pnInt64 = &p->nInt64; goto direct;
523 case SbxCURRENCY:
524 case SbxSALINT64:
525 aTmp.pnInt64 = &p->nInt64; goto direct;
526 case SbxSALUINT64:
527 aTmp.puInt64 = &p->uInt64; goto direct;
529 direct:
530 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
531 p = &aTmp; goto start;
533 case SbxSINGLE:
534 p->nSingle = (float) n; break;
535 case SbxDATE:
536 case SbxDOUBLE:
537 p->nDouble = (double) n; break;
539 case SbxBYREF | SbxSTRING:
540 case SbxSTRING:
541 case SbxLPSTR:
543 if( !p->pOUString )
544 p->pOUString = new ::rtl::OUString;
546 ::rtl::OString aOStr = ::rtl::OString::valueOf( n );
547 (*p->pOUString) = ::rtl::OStringToOUString
548 ( aOStr, RTL_TEXTENCODING_ASCII_US );
549 break;
551 case SbxOBJECT:
553 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
554 if( pVal )
555 pVal->PutInt64( n );
556 else
557 SbxBase::SetError( SbxERR_NO_OBJECT );
558 break;
560 case SbxBYREF | SbxCHAR:
561 if( n > SbxMAXCHAR )
563 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCHAR;
565 else if( n < SbxMINCHAR )
567 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCHAR;
569 *p->pChar = (sal_Unicode) n; break;
570 case SbxBYREF | SbxBYTE:
571 if( n > SbxMAXBYTE )
573 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
575 else if( n < 0 )
577 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
579 *p->pByte = (sal_uInt8) n; break;
580 case SbxBYREF | SbxINTEGER:
581 case SbxBYREF | SbxBOOL:
582 if( n > SbxMAXINT )
584 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXINT;
586 else if( n < SbxMININT )
588 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMININT;
590 *p->pInteger = (sal_Int16) n; break;
591 case SbxBYREF | SbxERROR:
592 case SbxBYREF | SbxUSHORT:
593 if( n > SbxMAXUINT )
595 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXUINT;
597 else if( n < 0 )
599 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
601 *p->pUShort = (sal_uInt16) n; break;
602 case SbxBYREF | SbxLONG:
603 if( n > SbxMAXLNG )
605 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXLNG;
607 else if( n < SbxMINLNG )
609 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINLNG;
611 *p->pLong = (sal_Int32) n; break;
612 case SbxBYREF | SbxULONG:
613 if( n > SbxMAXULNG )
615 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXULNG;
617 else if( n < 0 )
619 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
621 *p->pULong = (sal_uInt32) n; break;
622 case SbxBYREF | SbxSINGLE:
623 *p->pSingle = (float) n; break;
624 case SbxBYREF | SbxDATE:
625 case SbxBYREF | SbxDOUBLE:
626 *p->pDouble = (double) n; break;
627 case SbxBYREF | SbxCURRENCY:
628 *p->pnInt64 = n * CURRENCY_FACTOR; break;
629 case SbxBYREF | SbxSALINT64:
630 *p->pnInt64 = n; break;
631 case SbxBYREF | SbxSALUINT64:
632 if( n < 0 )
634 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
636 *p->puInt64 = (sal_Int64) n; break;
638 default:
639 SbxBase::SetError( SbxERR_CONVERSION );
643 sal_uInt64 ImpGetUInt64( const SbxValues* p )
645 SbxValues aTmp;
646 sal_uInt64 nRes;
647 start:
648 switch( +p->eType )
650 case SbxNULL:
651 SbxBase::SetError( SbxERR_CONVERSION );
652 case SbxEMPTY:
653 nRes = 0; break;
654 case SbxCHAR:
655 nRes = p->nChar; break;
656 case SbxBYTE:
657 nRes = p->nByte; break;
658 case SbxINTEGER:
659 case SbxBOOL:
660 nRes = p->nInteger; break;
661 case SbxERROR:
662 case SbxUSHORT:
663 nRes = p->nUShort; break;
664 case SbxLONG:
665 nRes = p->nLong; break;
666 case SbxULONG:
667 nRes = (sal_uInt64) p->nULong; break;
668 case SbxSINGLE:
669 nRes = (sal_uInt64) p->nSingle; break;
670 case SbxDATE:
671 case SbxDOUBLE:
673 //TODO overflow check
674 nRes = (sal_uInt64) p->nDouble;
675 break;
677 case SbxCURRENCY:
678 nRes = p->nInt64 * CURRENCY_FACTOR; break;
679 case SbxSALINT64:
680 if( p->nInt64 < 0 )
682 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
684 else
685 nRes = (sal_uInt64) p->nInt64;
686 break;
687 case SbxSALUINT64:
688 nRes = p->uInt64; break;
690 case SbxBYREF | SbxSTRING:
691 case SbxSTRING:
692 case SbxLPSTR:
693 if( !p->pOUString )
694 nRes = 0;
695 else
697 ::rtl::OString aOStr = ::rtl::OUStringToOString
698 ( *p->pOUString, RTL_TEXTENCODING_ASCII_US );
699 sal_Int64 n64 = aOStr.toInt64();
700 if( n64 == 0 )
702 // Check if really 0 or invalid conversion
703 double d;
704 SbxDataType t;
705 if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
706 nRes = 0;
707 else if( d > SbxMAXSALUINT64 )
709 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALUINT64;
711 else if( d < 0.0 )
713 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
715 else
716 nRes = (sal_uInt64) ImpRound( d );
718 else if( n64 < 0 )
720 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
722 else
724 nRes = n64;
727 break;
728 case SbxOBJECT:
730 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
731 if( pVal )
732 nRes = pVal->GetUInt64();
733 else
735 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
737 break;
740 case SbxBYREF | SbxCHAR:
741 nRes = *p->pChar; break;
742 case SbxBYREF | SbxBYTE:
743 nRes = *p->pByte; break;
744 case SbxBYREF | SbxINTEGER:
745 case SbxBYREF | SbxBOOL:
746 nRes = *p->pInteger; break;
747 case SbxBYREF | SbxLONG:
748 nRes = *p->pLong; break;
749 case SbxBYREF | SbxULONG:
750 nRes = *p->pULong; break;
751 case SbxBYREF | SbxSALUINT64:
752 nRes = *p->puInt64; break;
754 // from here on the value has to be checked
755 case SbxBYREF | SbxERROR:
756 case SbxBYREF | SbxUSHORT:
757 aTmp.nUShort = *p->pUShort; goto ref;
758 case SbxBYREF | SbxSINGLE:
759 aTmp.nSingle = *p->pSingle; goto ref;
760 case SbxBYREF | SbxDATE:
761 case SbxBYREF | SbxDOUBLE:
762 aTmp.nDouble = *p->pDouble; goto ref;
763 case SbxBYREF | SbxCURRENCY:
764 case SbxBYREF | SbxSALINT64:
765 aTmp.nInt64 = *p->pnInt64; goto ref;
766 ref:
767 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
768 p = &aTmp; goto start;
770 default:
771 SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
773 return nRes;
776 void ImpPutUInt64( SbxValues* p, sal_uInt64 n )
778 SbxValues aTmp;
780 start:
781 switch( +p->eType )
783 // Check neccessary
784 case SbxCHAR:
785 aTmp.pChar = &p->nChar; goto direct;
786 case SbxBYTE:
787 aTmp.pByte = &p->nByte; goto direct;
788 case SbxINTEGER:
789 case SbxBOOL:
790 aTmp.pInteger = &p->nInteger; goto direct;
791 case SbxULONG:
792 aTmp.pULong = &p->nULong; goto direct;
793 case SbxERROR:
794 case SbxUSHORT:
795 aTmp.pUShort = &p->nUShort; goto direct;
796 case SbxLONG:
797 aTmp.pnInt64 = &p->nInt64; goto direct;
798 case SbxCURRENCY:
799 case SbxSALINT64:
800 aTmp.pnInt64 = &p->nInt64; goto direct;
801 case SbxSINGLE:
802 aTmp.pSingle = &p->nSingle; goto direct;
803 case SbxDATE:
804 case SbxDOUBLE:
805 aTmp.pDouble = &p->nDouble; goto direct;
807 direct:
808 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
809 p = &aTmp; goto start;
811 // Check not neccessary
812 case SbxSALUINT64:
813 p->uInt64 = n; break;
815 case SbxBYREF | SbxSTRING:
816 case SbxSTRING:
817 case SbxLPSTR:
818 if( !p->pOUString )
819 p->pOUString = new ::rtl::OUString;
820 if( n > SbxMAXSALINT64 )
821 SbxBase::SetError( SbxERR_CONVERSION );
822 else
824 ::rtl::OString aOStr = ::rtl::OString::valueOf( (sal_Int64)n );
825 (*p->pOUString) = ::rtl::OStringToOUString
826 ( aOStr, RTL_TEXTENCODING_ASCII_US );
828 break;
829 case SbxOBJECT:
831 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
832 if( pVal )
833 pVal->PutUInt64( n );
834 else
835 SbxBase::SetError( SbxERR_NO_OBJECT );
836 break;
838 case SbxBYREF | SbxCHAR:
839 if( n > SbxMAXCHAR )
841 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCHAR;
843 *p->pChar = (sal_Unicode) n; break;
844 case SbxBYREF | SbxBYTE:
845 if( n > SbxMAXBYTE )
847 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
849 *p->pByte = (sal_uInt8) n; break;
850 case SbxBYREF | SbxINTEGER:
851 case SbxBYREF | SbxBOOL:
852 if( n > SbxMAXINT )
854 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXINT;
856 *p->pInteger = (sal_Int16) n; break;
857 case SbxBYREF | SbxERROR:
858 case SbxBYREF | SbxUSHORT:
859 if( n > SbxMAXUINT )
861 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXUINT;
863 *p->pUShort = (sal_uInt16) n; break;
864 case SbxBYREF | SbxLONG:
865 if( n > SbxMAXLNG )
867 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXLNG;
869 *p->pLong = (sal_Int32) n; break;
870 case SbxBYREF | SbxULONG:
871 if( n > SbxMAXULNG )
873 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXULNG;
875 *p->pULong = (sal_uInt32) n; break;
876 case SbxBYREF | SbxSINGLE:
877 *p->pDouble = (float)ImpSalUInt64ToDouble( n ); break;
878 case SbxBYREF | SbxDATE:
879 case SbxBYREF | SbxDOUBLE:
881 *p->pDouble = ImpSalUInt64ToDouble( n ); break;
882 case SbxBYREF | SbxCURRENCY:
883 if ( n > ( SbxMAXSALINT64 / CURRENCY_FACTOR ) )
884 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXSALINT64;
885 *p->pnInt64 = ( sal_Int64) ( n * CURRENCY_FACTOR ); break;
886 case SbxBYREF | SbxSALUINT64:
887 *p->puInt64 = n; break;
888 case SbxBYREF | SbxSALINT64:
889 if( n > SbxMAXSALINT64 )
891 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
893 *p->pnInt64 = (sal_Int64) n; break;
895 default:
896 SbxBase::SetError( SbxERR_CONVERSION );
901 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */