1e1f63238SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3e1f63238SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4e1f63238SAndrew Rist * or more contributor license agreements. See the NOTICE file
5e1f63238SAndrew Rist * distributed with this work for additional information
6e1f63238SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7e1f63238SAndrew Rist * to you under the Apache License, Version 2.0 (the
8e1f63238SAndrew Rist * "License"); you may not use this file except in compliance
9e1f63238SAndrew Rist * with the License. You may obtain a copy of the License at
10e1f63238SAndrew Rist *
11e1f63238SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12e1f63238SAndrew Rist *
13e1f63238SAndrew Rist * Unless required by applicable law or agreed to in writing,
14e1f63238SAndrew Rist * software distributed under the License is distributed on an
15e1f63238SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16e1f63238SAndrew Rist * KIND, either express or implied. See the License for the
17e1f63238SAndrew Rist * specific language governing permissions and limitations
18e1f63238SAndrew Rist * under the License.
19e1f63238SAndrew Rist *
20e1f63238SAndrew Rist *************************************************************/
21e1f63238SAndrew Rist
22e1f63238SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_basic.hxx"
26cdf0e10cSrcweir #include <tools/errcode.hxx>
27cdf0e10cSrcweir #include <basic/sbx.hxx>
28cdf0e10cSrcweir #include "sbxconv.hxx"
29cdf0e10cSrcweir
ImpRound(double d)30cdf0e10cSrcweir double ImpRound( double d )
31cdf0e10cSrcweir {
32cdf0e10cSrcweir return d + ( d < 0 ? -0.5 : 0.5 );
33cdf0e10cSrcweir }
34cdf0e10cSrcweir
ImpGetInteger(const SbxValues * p)35cdf0e10cSrcweir sal_Int16 ImpGetInteger( const SbxValues* p )
36cdf0e10cSrcweir {
37cdf0e10cSrcweir SbxValues aTmp;
38cdf0e10cSrcweir sal_Int16 nRes;
39cdf0e10cSrcweir start:
40cdf0e10cSrcweir switch( +p->eType )
41cdf0e10cSrcweir {
42cdf0e10cSrcweir case SbxNULL:
43cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION );
44cdf0e10cSrcweir case SbxEMPTY:
45cdf0e10cSrcweir nRes = 0; break;
46cdf0e10cSrcweir case SbxCHAR:
47cdf0e10cSrcweir nRes = p->nChar; break;
48cdf0e10cSrcweir case SbxBYTE:
49cdf0e10cSrcweir nRes = p->nByte; break;
50cdf0e10cSrcweir case SbxINTEGER:
51cdf0e10cSrcweir case SbxBOOL:
52cdf0e10cSrcweir nRes = p->nInteger; break;
53cdf0e10cSrcweir case SbxERROR:
54cdf0e10cSrcweir case SbxUSHORT:
55cdf0e10cSrcweir if( p->nUShort > (sal_uInt16) SbxMAXINT )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
58cdf0e10cSrcweir }
59cdf0e10cSrcweir else
60cdf0e10cSrcweir nRes = (sal_Int16) p->nUShort;
61cdf0e10cSrcweir break;
62cdf0e10cSrcweir case SbxLONG:
63cdf0e10cSrcweir if( p->nLong > SbxMAXINT )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
66cdf0e10cSrcweir }
67cdf0e10cSrcweir else if( p->nLong < SbxMININT )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir else
72cdf0e10cSrcweir nRes = (sal_Int16) p->nLong;
73cdf0e10cSrcweir break;
74cdf0e10cSrcweir case SbxULONG:
75cdf0e10cSrcweir if( p->nULong > SbxMAXINT )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
78cdf0e10cSrcweir }
79cdf0e10cSrcweir else
80cdf0e10cSrcweir nRes = (sal_Int16) p->nULong;
81cdf0e10cSrcweir break;
82cdf0e10cSrcweir case SbxSINGLE:
83cdf0e10cSrcweir if( p->nSingle > SbxMAXINT )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir else if( p->nSingle < SbxMININT )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir else
92cdf0e10cSrcweir nRes = (sal_Int16) ImpRound( p->nSingle );
93cdf0e10cSrcweir break;
94cdf0e10cSrcweir case SbxSALINT64:
95cdf0e10cSrcweir if( p->nInt64 > SbxMAXINT )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir else if( p->nInt64 < SbxMININT )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir else
104cdf0e10cSrcweir nRes = (sal_Int16) p->nInt64;
105cdf0e10cSrcweir break;
106cdf0e10cSrcweir case SbxSALUINT64:
107cdf0e10cSrcweir if( p->uInt64 > SbxMAXINT )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir else
112cdf0e10cSrcweir nRes = (sal_Int16) p->uInt64;
113cdf0e10cSrcweir break;
114cdf0e10cSrcweir case SbxDATE:
115cdf0e10cSrcweir case SbxDOUBLE:
116cdf0e10cSrcweir case SbxLONG64:
117cdf0e10cSrcweir case SbxULONG64:
118cdf0e10cSrcweir case SbxCURRENCY:
119cdf0e10cSrcweir case SbxDECIMAL:
120cdf0e10cSrcweir case SbxBYREF | SbxDECIMAL:
121cdf0e10cSrcweir {
122cdf0e10cSrcweir double dVal;
123cdf0e10cSrcweir if( p->eType == SbxCURRENCY )
124cdf0e10cSrcweir dVal = ImpCurrencyToDouble( p->nLong64 );
125cdf0e10cSrcweir else if( p->eType == SbxLONG64 )
126cdf0e10cSrcweir dVal = ImpINT64ToDouble( p->nLong64 );
127cdf0e10cSrcweir else if( p->eType == SbxULONG64 )
128cdf0e10cSrcweir dVal = ImpUINT64ToDouble( p->nULong64 );
129cdf0e10cSrcweir else if( p->eType == SbxDECIMAL )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir dVal = 0.0;
132cdf0e10cSrcweir if( p->pDecimal )
133cdf0e10cSrcweir p->pDecimal->getDouble( dVal );
134cdf0e10cSrcweir }
135cdf0e10cSrcweir else
136cdf0e10cSrcweir dVal = p->nDouble;
137cdf0e10cSrcweir
138cdf0e10cSrcweir if( dVal > SbxMAXINT )
139cdf0e10cSrcweir {
140cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir else if( dVal < SbxMININT )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir else
147cdf0e10cSrcweir nRes = (sal_Int16) ImpRound( dVal );
148cdf0e10cSrcweir break;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir case SbxLPSTR:
151cdf0e10cSrcweir case SbxSTRING:
152cdf0e10cSrcweir case SbxBYREF | SbxSTRING:
153cdf0e10cSrcweir if( !p->pOUString )
154cdf0e10cSrcweir nRes = 0;
155cdf0e10cSrcweir else
156cdf0e10cSrcweir {
157cdf0e10cSrcweir double d;
158cdf0e10cSrcweir SbxDataType t;
159cdf0e10cSrcweir if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
160cdf0e10cSrcweir nRes = 0;
161cdf0e10cSrcweir else if( d > SbxMAXINT )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXINT;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir else if( d < SbxMININT )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMININT;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir else
170cdf0e10cSrcweir nRes = (sal_Int16) ImpRound( d );
171cdf0e10cSrcweir }
172cdf0e10cSrcweir break;
173cdf0e10cSrcweir case SbxOBJECT:
174cdf0e10cSrcweir {
175cdf0e10cSrcweir SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
176cdf0e10cSrcweir if( pVal )
177cdf0e10cSrcweir nRes = pVal->GetInteger();
178cdf0e10cSrcweir else
179cdf0e10cSrcweir {
180cdf0e10cSrcweir SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir break;
183cdf0e10cSrcweir }
184cdf0e10cSrcweir
185cdf0e10cSrcweir case SbxBYREF | SbxCHAR:
186cdf0e10cSrcweir nRes = *p->pChar; break;
187cdf0e10cSrcweir case SbxBYREF | SbxBYTE:
188cdf0e10cSrcweir nRes = *p->pByte; break;
189cdf0e10cSrcweir case SbxBYREF | SbxINTEGER:
190cdf0e10cSrcweir case SbxBYREF | SbxBOOL:
191cdf0e10cSrcweir nRes = *p->pInteger; break;
192cdf0e10cSrcweir
193cdf0e10cSrcweir // ab hier muss getestet werden
194cdf0e10cSrcweir case SbxBYREF | SbxLONG:
195cdf0e10cSrcweir aTmp.nLong = *p->pLong; goto ref;
196cdf0e10cSrcweir case SbxBYREF | SbxULONG:
197cdf0e10cSrcweir aTmp.nULong = *p->pULong; goto ref;
198cdf0e10cSrcweir case SbxBYREF | SbxERROR:
199cdf0e10cSrcweir case SbxBYREF | SbxUSHORT:
200cdf0e10cSrcweir aTmp.nUShort = *p->pUShort; goto ref;
201cdf0e10cSrcweir case SbxBYREF | SbxSINGLE:
202cdf0e10cSrcweir aTmp.nSingle = *p->pSingle; goto ref;
203cdf0e10cSrcweir case SbxBYREF | SbxDATE:
204cdf0e10cSrcweir case SbxBYREF | SbxDOUBLE:
205cdf0e10cSrcweir aTmp.nDouble = *p->pDouble; goto ref;
206cdf0e10cSrcweir case SbxBYREF | SbxULONG64:
207cdf0e10cSrcweir aTmp.nULong64 = *p->pULong64; goto ref;
208cdf0e10cSrcweir case SbxBYREF | SbxLONG64:
209cdf0e10cSrcweir case SbxBYREF | SbxCURRENCY:
210cdf0e10cSrcweir aTmp.nLong64 = *p->pLong64; goto ref;
211cdf0e10cSrcweir case SbxBYREF | SbxSALINT64:
212cdf0e10cSrcweir aTmp.nInt64 = *p->pnInt64; goto ref;
213cdf0e10cSrcweir case SbxBYREF | SbxSALUINT64:
214cdf0e10cSrcweir aTmp.uInt64 = *p->puInt64; goto ref;
215cdf0e10cSrcweir ref:
216cdf0e10cSrcweir aTmp.eType = SbxDataType( p->eType & 0x0FFF );
217cdf0e10cSrcweir p = &aTmp; goto start;
218cdf0e10cSrcweir
219cdf0e10cSrcweir default:
220cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir return nRes;
223cdf0e10cSrcweir }
224cdf0e10cSrcweir
ImpPutInteger(SbxValues * p,sal_Int16 n)225cdf0e10cSrcweir void ImpPutInteger( SbxValues* p, sal_Int16 n )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir SbxValues aTmp;
228cdf0e10cSrcweir start:
229cdf0e10cSrcweir switch( +p->eType )
230cdf0e10cSrcweir {
231cdf0e10cSrcweir // hier muss getestet werden
232cdf0e10cSrcweir case SbxCHAR:
233cdf0e10cSrcweir aTmp.pChar = &p->nChar; goto direct;
234cdf0e10cSrcweir case SbxBYTE:
235cdf0e10cSrcweir aTmp.pByte = &p->nByte; goto direct;
236cdf0e10cSrcweir case SbxULONG:
237cdf0e10cSrcweir aTmp.pULong = &p->nULong; goto direct;
238cdf0e10cSrcweir case SbxERROR:
239cdf0e10cSrcweir case SbxUSHORT:
240cdf0e10cSrcweir aTmp.pUShort = &p->nUShort; goto direct;
241cdf0e10cSrcweir case SbxSALUINT64:
242cdf0e10cSrcweir aTmp.puInt64 = &p->uInt64; goto direct;
243cdf0e10cSrcweir direct:
244cdf0e10cSrcweir aTmp.eType = SbxDataType( p->eType | SbxBYREF );
245cdf0e10cSrcweir p = &aTmp; goto start;
246cdf0e10cSrcweir
247cdf0e10cSrcweir // ab hier nicht mehr
248cdf0e10cSrcweir case SbxINTEGER:
249cdf0e10cSrcweir case SbxBOOL:
250cdf0e10cSrcweir p->nInteger = n; break;
251cdf0e10cSrcweir case SbxLONG:
252cdf0e10cSrcweir p->nLong = n; break;
253cdf0e10cSrcweir case SbxSINGLE:
254cdf0e10cSrcweir p->nSingle = n; break;
255cdf0e10cSrcweir case SbxDATE:
256cdf0e10cSrcweir case SbxDOUBLE:
257cdf0e10cSrcweir p->nDouble = n; break;
258cdf0e10cSrcweir case SbxSALINT64:
259cdf0e10cSrcweir p->nInt64 = n; break;
260cdf0e10cSrcweir case SbxULONG64:
261cdf0e10cSrcweir p->nULong64 = ImpDoubleToUINT64( (double)n ); break;
262cdf0e10cSrcweir case SbxLONG64:
263cdf0e10cSrcweir p->nLong64 = ImpDoubleToINT64( (double)n ); break;
264cdf0e10cSrcweir case SbxCURRENCY:
265cdf0e10cSrcweir p->nLong64 = ImpDoubleToCurrency( (double)n ); break;
266cdf0e10cSrcweir case SbxDECIMAL:
267cdf0e10cSrcweir case SbxBYREF | SbxDECIMAL:
268cdf0e10cSrcweir ImpCreateDecimal( p )->setInt( n );
269cdf0e10cSrcweir break;
270cdf0e10cSrcweir
271cdf0e10cSrcweir case SbxLPSTR:
272cdf0e10cSrcweir case SbxSTRING:
273cdf0e10cSrcweir case SbxBYREF | SbxSTRING:
274cdf0e10cSrcweir if( !p->pOUString )
275cdf0e10cSrcweir p->pOUString = new ::rtl::OUString;
276cdf0e10cSrcweir ImpCvtNum( (double) n, 0, *p->pOUString );
277cdf0e10cSrcweir break;
278cdf0e10cSrcweir case SbxOBJECT:
279cdf0e10cSrcweir {
280cdf0e10cSrcweir SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
281cdf0e10cSrcweir if( pVal )
282cdf0e10cSrcweir pVal->PutInteger( n );
283cdf0e10cSrcweir else
284cdf0e10cSrcweir SbxBase::SetError( SbxERR_NO_OBJECT );
285cdf0e10cSrcweir break;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir case SbxBYREF | SbxCHAR:
288cdf0e10cSrcweir if( n < SbxMINCHAR )
289cdf0e10cSrcweir {
290cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCHAR;
291cdf0e10cSrcweir }
292cdf0e10cSrcweir *p->pChar = (char) n; break;
293cdf0e10cSrcweir case SbxBYREF | SbxBYTE:
294cdf0e10cSrcweir if( n > SbxMAXBYTE )
295cdf0e10cSrcweir {
296cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
297cdf0e10cSrcweir }
298cdf0e10cSrcweir else if( n < 0 )
299cdf0e10cSrcweir {
300cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
301cdf0e10cSrcweir }
302cdf0e10cSrcweir *p->pByte = (sal_uInt8) n; break;
303cdf0e10cSrcweir case SbxBYREF | SbxINTEGER:
304cdf0e10cSrcweir case SbxBYREF | SbxBOOL:
305cdf0e10cSrcweir *p->pInteger = n; break;
306cdf0e10cSrcweir case SbxBYREF | SbxERROR:
307cdf0e10cSrcweir case SbxBYREF | SbxUSHORT:
308cdf0e10cSrcweir if( n < 0 )
309cdf0e10cSrcweir {
310cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
311cdf0e10cSrcweir }
312cdf0e10cSrcweir *p->pUShort = (sal_uInt16) n; break;
313cdf0e10cSrcweir case SbxBYREF | SbxLONG:
314cdf0e10cSrcweir *p->pLong = (sal_Int32) n; break;
315cdf0e10cSrcweir case SbxBYREF | SbxULONG:
316cdf0e10cSrcweir if( n < 0 )
317cdf0e10cSrcweir {
318cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
319cdf0e10cSrcweir }
320cdf0e10cSrcweir *p->pULong = (sal_uInt32) n; break;
321cdf0e10cSrcweir case SbxBYREF | SbxSALINT64:
322cdf0e10cSrcweir *p->pnInt64 = n; break;
323cdf0e10cSrcweir case SbxBYREF | SbxSALUINT64:
324cdf0e10cSrcweir if( n < 0 )
325cdf0e10cSrcweir {
326cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); *p->puInt64 = 0;
327cdf0e10cSrcweir }
328cdf0e10cSrcweir else
329cdf0e10cSrcweir *p->puInt64 = n;
330cdf0e10cSrcweir break;
331cdf0e10cSrcweir case SbxBYREF | SbxSINGLE:
332cdf0e10cSrcweir *p->pSingle = (float) n; break;
333cdf0e10cSrcweir case SbxBYREF | SbxDATE:
334cdf0e10cSrcweir case SbxBYREF | SbxDOUBLE:
335cdf0e10cSrcweir *p->pDouble = (double) n; break;
336cdf0e10cSrcweir case SbxBYREF | SbxULONG64:
337cdf0e10cSrcweir *p->pULong64 = ImpDoubleToUINT64( (double)n ); break;
338cdf0e10cSrcweir case SbxBYREF | SbxLONG64:
339cdf0e10cSrcweir *p->pLong64 = ImpDoubleToINT64( (double)n ); break;
340cdf0e10cSrcweir case SbxBYREF | SbxCURRENCY:
341cdf0e10cSrcweir *p->pLong64 = ImpDoubleToCurrency( (double)n ); break;
342cdf0e10cSrcweir
343cdf0e10cSrcweir default:
344cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION );
345cdf0e10cSrcweir }
346cdf0e10cSrcweir }
347cdf0e10cSrcweir
348cdf0e10cSrcweir
349cdf0e10cSrcweir // sal_Int64 / hyper
350cdf0e10cSrcweir
ImpDoubleToSalInt64(double d)351cdf0e10cSrcweir sal_Int64 ImpDoubleToSalInt64( double d )
352cdf0e10cSrcweir {
353cdf0e10cSrcweir sal_Int64 nRes;
354cdf0e10cSrcweir if( d > SbxMAXSALINT64 )
355cdf0e10cSrcweir {
356cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALINT64;
357cdf0e10cSrcweir }
358cdf0e10cSrcweir else if( d < SbxMINSALINT64 )
359cdf0e10cSrcweir {
360cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINSALINT64;
361cdf0e10cSrcweir }
362cdf0e10cSrcweir else
363cdf0e10cSrcweir nRes = (sal_Int64) ImpRound( d );
364cdf0e10cSrcweir return nRes;
365cdf0e10cSrcweir }
366cdf0e10cSrcweir
ImpDoubleToSalUInt64(double d)367cdf0e10cSrcweir sal_uInt64 ImpDoubleToSalUInt64( double d )
368cdf0e10cSrcweir {
369cdf0e10cSrcweir sal_uInt64 nRes;
370cdf0e10cSrcweir if( d > SbxMAXSALUINT64 )
371cdf0e10cSrcweir {
372cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALUINT64;
373cdf0e10cSrcweir }
374cdf0e10cSrcweir else if( d < 0.0 )
375cdf0e10cSrcweir {
376cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
377cdf0e10cSrcweir }
378cdf0e10cSrcweir else
379cdf0e10cSrcweir nRes = (sal_uInt64) ImpRound( d );
380cdf0e10cSrcweir return nRes;
381cdf0e10cSrcweir }
382cdf0e10cSrcweir
ImpSalUInt64ToDouble(sal_uInt64 n)383cdf0e10cSrcweir double ImpSalUInt64ToDouble( sal_uInt64 n )
384cdf0e10cSrcweir {
385cdf0e10cSrcweir double d = 0.0;
386cdf0e10cSrcweir if( n > SbxMAXSALINT64 )
387cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION );
388cdf0e10cSrcweir else
389cdf0e10cSrcweir d = (double)(sal_Int64) n;
390cdf0e10cSrcweir return d;
391cdf0e10cSrcweir }
392cdf0e10cSrcweir
393cdf0e10cSrcweir
ImpGetInt64(const SbxValues * p)394cdf0e10cSrcweir sal_Int64 ImpGetInt64( const SbxValues* p )
395cdf0e10cSrcweir {
396cdf0e10cSrcweir SbxValues aTmp;
397cdf0e10cSrcweir sal_Int64 nRes;
398cdf0e10cSrcweir start:
399cdf0e10cSrcweir switch( +p->eType )
400cdf0e10cSrcweir {
401cdf0e10cSrcweir case SbxNULL:
402cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION );
403cdf0e10cSrcweir case SbxEMPTY:
404cdf0e10cSrcweir nRes = 0; break;
405cdf0e10cSrcweir case SbxCHAR:
406cdf0e10cSrcweir nRes = p->nChar; break;
407cdf0e10cSrcweir case SbxBYTE:
408cdf0e10cSrcweir nRes = p->nByte; break;
409cdf0e10cSrcweir case SbxINTEGER:
410cdf0e10cSrcweir case SbxBOOL:
411cdf0e10cSrcweir nRes = p->nInteger; break;
412cdf0e10cSrcweir case SbxERROR:
413cdf0e10cSrcweir case SbxUSHORT:
414cdf0e10cSrcweir nRes = p->nUShort; break;
415cdf0e10cSrcweir case SbxLONG:
416cdf0e10cSrcweir nRes = p->nLong; break;
417cdf0e10cSrcweir case SbxULONG:
418cdf0e10cSrcweir nRes = (sal_Int64) p->nULong; break;
419cdf0e10cSrcweir case SbxSINGLE:
420cdf0e10cSrcweir nRes = ImpDoubleToSalInt64( (double)p->nSingle );
421cdf0e10cSrcweir break;
422cdf0e10cSrcweir case SbxDATE:
423cdf0e10cSrcweir case SbxDOUBLE:
424cdf0e10cSrcweir case SbxLONG64:
425cdf0e10cSrcweir case SbxULONG64:
426cdf0e10cSrcweir case SbxCURRENCY:
427cdf0e10cSrcweir {
428cdf0e10cSrcweir double dVal;
429cdf0e10cSrcweir if( p->eType == SbxCURRENCY )
430cdf0e10cSrcweir dVal = ImpCurrencyToDouble( p->nLong64 );
431cdf0e10cSrcweir else if( p->eType == SbxLONG64 )
432cdf0e10cSrcweir dVal = ImpINT64ToDouble( p->nLong64 );
433cdf0e10cSrcweir else if( p->eType == SbxULONG64 )
434cdf0e10cSrcweir dVal = ImpUINT64ToDouble( p->nULong64 );
435cdf0e10cSrcweir else
436cdf0e10cSrcweir dVal = p->nDouble;
437cdf0e10cSrcweir
438cdf0e10cSrcweir nRes = ImpDoubleToSalInt64( dVal );
439cdf0e10cSrcweir break;
440cdf0e10cSrcweir }
441cdf0e10cSrcweir case SbxSALINT64:
442cdf0e10cSrcweir nRes = p->nInt64; break;
443cdf0e10cSrcweir case SbxSALUINT64:
444cdf0e10cSrcweir if( p->uInt64 > SbxMAXSALINT64 )
445cdf0e10cSrcweir {
446cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALINT64;
447cdf0e10cSrcweir }
448cdf0e10cSrcweir else
449cdf0e10cSrcweir nRes = (sal_Int64) p->uInt64;
450cdf0e10cSrcweir break;
451cdf0e10cSrcweir
452cdf0e10cSrcweir case SbxBYREF | SbxSTRING:
453cdf0e10cSrcweir case SbxSTRING:
454cdf0e10cSrcweir case SbxLPSTR:
455cdf0e10cSrcweir if( !p->pOUString )
456cdf0e10cSrcweir nRes = 0;
457cdf0e10cSrcweir else
458cdf0e10cSrcweir {
459cdf0e10cSrcweir ::rtl::OString aOStr = ::rtl::OUStringToOString
460cdf0e10cSrcweir ( *p->pOUString, RTL_TEXTENCODING_ASCII_US );
461cdf0e10cSrcweir nRes = aOStr.toInt64();
462cdf0e10cSrcweir if( nRes == 0 )
463cdf0e10cSrcweir {
464cdf0e10cSrcweir // Check if really 0 or invalid conversion
465cdf0e10cSrcweir double d;
466cdf0e10cSrcweir SbxDataType t;
467cdf0e10cSrcweir if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
468cdf0e10cSrcweir nRes = 0;
469cdf0e10cSrcweir else
470cdf0e10cSrcweir nRes = ImpDoubleToSalInt64( d );
471cdf0e10cSrcweir }
472cdf0e10cSrcweir }
473cdf0e10cSrcweir break;
474cdf0e10cSrcweir case SbxOBJECT:
475cdf0e10cSrcweir {
476cdf0e10cSrcweir SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
477cdf0e10cSrcweir if( pVal )
478cdf0e10cSrcweir nRes = pVal->GetInt64();
479cdf0e10cSrcweir else
480cdf0e10cSrcweir {
481cdf0e10cSrcweir SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
482cdf0e10cSrcweir }
483cdf0e10cSrcweir break;
484cdf0e10cSrcweir }
485cdf0e10cSrcweir
486cdf0e10cSrcweir case SbxBYREF | SbxCHAR:
487cdf0e10cSrcweir nRes = *p->pChar; break;
488cdf0e10cSrcweir case SbxBYREF | SbxBYTE:
489cdf0e10cSrcweir nRes = *p->pByte; break;
490cdf0e10cSrcweir case SbxBYREF | SbxINTEGER:
491cdf0e10cSrcweir case SbxBYREF | SbxBOOL:
492cdf0e10cSrcweir nRes = *p->pInteger; break;
493cdf0e10cSrcweir case SbxBYREF | SbxLONG:
494cdf0e10cSrcweir nRes = *p->pLong; break;
495cdf0e10cSrcweir case SbxBYREF | SbxULONG:
496cdf0e10cSrcweir nRes = *p->pULong; break;
497cdf0e10cSrcweir case SbxBYREF | SbxSALINT64:
498cdf0e10cSrcweir nRes = *p->pnInt64; break;
499cdf0e10cSrcweir
500cdf0e10cSrcweir // from here the values has to be checked
501cdf0e10cSrcweir case SbxBYREF | SbxERROR:
502cdf0e10cSrcweir case SbxBYREF | SbxUSHORT:
503cdf0e10cSrcweir aTmp.nUShort = *p->pUShort; goto ref;
504cdf0e10cSrcweir case SbxBYREF | SbxSINGLE:
505cdf0e10cSrcweir aTmp.nSingle = *p->pSingle; goto ref;
506cdf0e10cSrcweir case SbxBYREF | SbxDATE:
507cdf0e10cSrcweir case SbxBYREF | SbxDOUBLE:
508cdf0e10cSrcweir aTmp.nDouble = *p->pDouble; goto ref;
509cdf0e10cSrcweir case SbxBYREF | SbxULONG64:
510cdf0e10cSrcweir aTmp.nULong64 = *p->pULong64; goto ref;
511cdf0e10cSrcweir case SbxBYREF | SbxLONG64:
512cdf0e10cSrcweir case SbxBYREF | SbxCURRENCY:
513cdf0e10cSrcweir aTmp.nLong64 = *p->pLong64; goto ref;
514cdf0e10cSrcweir case SbxBYREF | SbxSALUINT64:
515cdf0e10cSrcweir aTmp.uInt64 = *p->puInt64; goto ref;
516cdf0e10cSrcweir ref:
517cdf0e10cSrcweir aTmp.eType = SbxDataType( p->eType & 0x0FFF );
518cdf0e10cSrcweir p = &aTmp; goto start;
519cdf0e10cSrcweir
520cdf0e10cSrcweir default:
521cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
522cdf0e10cSrcweir }
523cdf0e10cSrcweir return nRes;
524cdf0e10cSrcweir }
525cdf0e10cSrcweir
ImpPutInt64(SbxValues * p,sal_Int64 n)526cdf0e10cSrcweir void ImpPutInt64( SbxValues* p, sal_Int64 n )
527cdf0e10cSrcweir {
528cdf0e10cSrcweir SbxValues aTmp;
529cdf0e10cSrcweir
530cdf0e10cSrcweir start:
531cdf0e10cSrcweir switch( +p->eType )
532cdf0e10cSrcweir {
533*07a3d7f1SPedro Giffuni // Check necessary
534cdf0e10cSrcweir case SbxCHAR:
535cdf0e10cSrcweir aTmp.pChar = &p->nChar; goto direct;
536cdf0e10cSrcweir case SbxBYTE:
537cdf0e10cSrcweir aTmp.pByte = &p->nByte; goto direct;
538cdf0e10cSrcweir case SbxINTEGER:
539cdf0e10cSrcweir case SbxBOOL:
540cdf0e10cSrcweir aTmp.pInteger = &p->nInteger; goto direct;
541cdf0e10cSrcweir case SbxULONG64:
542cdf0e10cSrcweir aTmp.pULong64 = &p->nULong64; goto direct;
543cdf0e10cSrcweir case SbxLONG64:
544cdf0e10cSrcweir case SbxCURRENCY:
545cdf0e10cSrcweir aTmp.pLong64 = &p->nLong64; goto direct;
546cdf0e10cSrcweir case SbxULONG:
547cdf0e10cSrcweir aTmp.pULong = &p->nULong; goto direct;
548cdf0e10cSrcweir case SbxERROR:
549cdf0e10cSrcweir case SbxUSHORT:
550cdf0e10cSrcweir aTmp.pUShort = &p->nUShort; goto direct;
551cdf0e10cSrcweir case SbxLONG:
552cdf0e10cSrcweir aTmp.pnInt64 = &p->nInt64; goto direct;
553cdf0e10cSrcweir case SbxSALUINT64:
554cdf0e10cSrcweir aTmp.puInt64 = &p->uInt64; goto direct;
555cdf0e10cSrcweir
556cdf0e10cSrcweir direct:
557cdf0e10cSrcweir aTmp.eType = SbxDataType( p->eType | SbxBYREF );
558cdf0e10cSrcweir p = &aTmp; goto start;
559cdf0e10cSrcweir
560*07a3d7f1SPedro Giffuni // Check not necessary
561cdf0e10cSrcweir case SbxSALINT64:
562cdf0e10cSrcweir p->nInt64 = n; break;
563cdf0e10cSrcweir case SbxSINGLE:
564cdf0e10cSrcweir p->nSingle = (float) n; break;
565cdf0e10cSrcweir case SbxDATE:
566cdf0e10cSrcweir case SbxDOUBLE:
567cdf0e10cSrcweir p->nDouble = (double) n; break;
568cdf0e10cSrcweir
569cdf0e10cSrcweir case SbxBYREF | SbxSTRING:
570cdf0e10cSrcweir case SbxSTRING:
571cdf0e10cSrcweir case SbxLPSTR:
572cdf0e10cSrcweir {
573cdf0e10cSrcweir if( !p->pOUString )
574cdf0e10cSrcweir p->pOUString = new ::rtl::OUString;
575cdf0e10cSrcweir
576cdf0e10cSrcweir ::rtl::OString aOStr = ::rtl::OString::valueOf( n );
577cdf0e10cSrcweir (*p->pOUString) = ::rtl::OStringToOUString
578cdf0e10cSrcweir ( aOStr, RTL_TEXTENCODING_ASCII_US );
579cdf0e10cSrcweir break;
580cdf0e10cSrcweir }
581cdf0e10cSrcweir case SbxOBJECT:
582cdf0e10cSrcweir {
583cdf0e10cSrcweir SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
584cdf0e10cSrcweir if( pVal )
585cdf0e10cSrcweir pVal->PutInt64( n );
586cdf0e10cSrcweir else
587cdf0e10cSrcweir SbxBase::SetError( SbxERR_NO_OBJECT );
588cdf0e10cSrcweir break;
589cdf0e10cSrcweir }
590cdf0e10cSrcweir case SbxBYREF | SbxCHAR:
591cdf0e10cSrcweir if( n > SbxMAXCHAR )
592cdf0e10cSrcweir {
593cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCHAR;
594cdf0e10cSrcweir }
595cdf0e10cSrcweir else if( n < SbxMINCHAR )
596cdf0e10cSrcweir {
597cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCHAR;
598cdf0e10cSrcweir }
599cdf0e10cSrcweir *p->pChar = (xub_Unicode) n; break;
600cdf0e10cSrcweir case SbxBYREF | SbxBYTE:
601cdf0e10cSrcweir if( n > SbxMAXBYTE )
602cdf0e10cSrcweir {
603cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
604cdf0e10cSrcweir }
605cdf0e10cSrcweir else if( n < 0 )
606cdf0e10cSrcweir {
607cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
608cdf0e10cSrcweir }
609cdf0e10cSrcweir *p->pByte = (sal_uInt8) n; break;
610cdf0e10cSrcweir case SbxBYREF | SbxINTEGER:
611cdf0e10cSrcweir case SbxBYREF | SbxBOOL:
612cdf0e10cSrcweir if( n > SbxMAXINT )
613cdf0e10cSrcweir {
614cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXINT;
615cdf0e10cSrcweir }
616cdf0e10cSrcweir else if( n < SbxMININT )
617cdf0e10cSrcweir {
618cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMININT;
619cdf0e10cSrcweir }
620cdf0e10cSrcweir *p->pInteger = (sal_Int16) n; break;
621cdf0e10cSrcweir case SbxBYREF | SbxERROR:
622cdf0e10cSrcweir case SbxBYREF | SbxUSHORT:
623cdf0e10cSrcweir if( n > SbxMAXUINT )
624cdf0e10cSrcweir {
625cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXUINT;
626cdf0e10cSrcweir }
627cdf0e10cSrcweir else if( n < 0 )
628cdf0e10cSrcweir {
629cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
630cdf0e10cSrcweir }
631cdf0e10cSrcweir *p->pUShort = (sal_uInt16) n; break;
632cdf0e10cSrcweir case SbxBYREF | SbxLONG:
633cdf0e10cSrcweir if( n > SbxMAXLNG )
634cdf0e10cSrcweir {
635cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXLNG;
636cdf0e10cSrcweir }
637cdf0e10cSrcweir else if( n < SbxMINLNG )
638cdf0e10cSrcweir {
639cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINLNG;
640cdf0e10cSrcweir }
641cdf0e10cSrcweir *p->pLong = (sal_Int32) n; break;
642cdf0e10cSrcweir case SbxBYREF | SbxULONG:
643cdf0e10cSrcweir if( n > SbxMAXULNG )
644cdf0e10cSrcweir {
645cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXULNG;
646cdf0e10cSrcweir }
647cdf0e10cSrcweir else if( n < 0 )
648cdf0e10cSrcweir {
649cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
650cdf0e10cSrcweir }
651cdf0e10cSrcweir *p->pULong = (sal_uInt32) n; break;
652cdf0e10cSrcweir case SbxBYREF | SbxSINGLE:
653cdf0e10cSrcweir *p->pSingle = (float) n; break;
654cdf0e10cSrcweir case SbxBYREF | SbxDATE:
655cdf0e10cSrcweir case SbxBYREF | SbxDOUBLE:
656cdf0e10cSrcweir *p->pDouble = (double) n; break;
657cdf0e10cSrcweir case SbxBYREF | SbxCURRENCY:
658cdf0e10cSrcweir if( n > SbxMAXCURR )
659cdf0e10cSrcweir {
660cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = (sal_Int64) SbxMAXCURR;
661cdf0e10cSrcweir }
662cdf0e10cSrcweir else if( n < SbxMINCURR )
663cdf0e10cSrcweir {
664cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = (sal_Int64) SbxMINCURR;
665cdf0e10cSrcweir }
666cdf0e10cSrcweir *p->pLong64 = ImpDoubleToCurrency( (double)n ); break;
667cdf0e10cSrcweir
668cdf0e10cSrcweir case SbxBYREF | SbxSALINT64:
669cdf0e10cSrcweir *p->pnInt64 = n; break;
670cdf0e10cSrcweir case SbxBYREF | SbxSALUINT64:
671cdf0e10cSrcweir if( n < 0 )
672cdf0e10cSrcweir {
673cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
674cdf0e10cSrcweir }
675cdf0e10cSrcweir *p->puInt64 = (sal_Int64) n; break;
676cdf0e10cSrcweir
677cdf0e10cSrcweir default:
678cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION );
679cdf0e10cSrcweir }
680cdf0e10cSrcweir }
681cdf0e10cSrcweir
ImpGetUInt64(const SbxValues * p)682cdf0e10cSrcweir sal_uInt64 ImpGetUInt64( const SbxValues* p )
683cdf0e10cSrcweir {
684cdf0e10cSrcweir SbxValues aTmp;
685cdf0e10cSrcweir sal_uInt64 nRes;
686cdf0e10cSrcweir start:
687cdf0e10cSrcweir switch( +p->eType )
688cdf0e10cSrcweir {
689cdf0e10cSrcweir case SbxNULL:
690cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION );
691cdf0e10cSrcweir case SbxEMPTY:
692cdf0e10cSrcweir nRes = 0; break;
693cdf0e10cSrcweir case SbxCHAR:
694cdf0e10cSrcweir nRes = p->nChar; break;
695cdf0e10cSrcweir case SbxBYTE:
696cdf0e10cSrcweir nRes = p->nByte; break;
697cdf0e10cSrcweir case SbxINTEGER:
698cdf0e10cSrcweir case SbxBOOL:
699cdf0e10cSrcweir nRes = p->nInteger; break;
700cdf0e10cSrcweir case SbxERROR:
701cdf0e10cSrcweir case SbxUSHORT:
702cdf0e10cSrcweir nRes = p->nUShort; break;
703cdf0e10cSrcweir case SbxLONG:
704cdf0e10cSrcweir nRes = p->nLong; break;
705cdf0e10cSrcweir case SbxULONG:
706cdf0e10cSrcweir nRes = (sal_uInt64) p->nULong; break;
707cdf0e10cSrcweir case SbxSINGLE:
708cdf0e10cSrcweir nRes = ImpDoubleToSalUInt64( (double)p->nSingle );
709cdf0e10cSrcweir break;
710cdf0e10cSrcweir case SbxDATE:
711cdf0e10cSrcweir case SbxDOUBLE:
712cdf0e10cSrcweir case SbxLONG64:
713cdf0e10cSrcweir case SbxULONG64:
714cdf0e10cSrcweir case SbxCURRENCY:
715cdf0e10cSrcweir {
716cdf0e10cSrcweir double dVal;
717cdf0e10cSrcweir if( p->eType == SbxCURRENCY )
718cdf0e10cSrcweir dVal = ImpCurrencyToDouble( p->nLong64 );
719cdf0e10cSrcweir else if( p->eType == SbxLONG64 )
720cdf0e10cSrcweir dVal = ImpINT64ToDouble( p->nLong64 );
721cdf0e10cSrcweir else if( p->eType == SbxULONG64 )
722cdf0e10cSrcweir dVal = ImpUINT64ToDouble( p->nULong64 );
723cdf0e10cSrcweir else
724cdf0e10cSrcweir dVal = p->nDouble;
725cdf0e10cSrcweir
726cdf0e10cSrcweir nRes = ImpDoubleToSalUInt64( dVal );
727cdf0e10cSrcweir break;
728cdf0e10cSrcweir }
729cdf0e10cSrcweir case SbxSALINT64:
730cdf0e10cSrcweir if( p->nInt64 < 0 )
731cdf0e10cSrcweir {
732cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
733cdf0e10cSrcweir }
734cdf0e10cSrcweir else
735cdf0e10cSrcweir nRes = (sal_uInt64) p->nInt64;
736cdf0e10cSrcweir case SbxSALUINT64:
737cdf0e10cSrcweir nRes = p->uInt64; break;
738cdf0e10cSrcweir
739cdf0e10cSrcweir case SbxBYREF | SbxSTRING:
740cdf0e10cSrcweir case SbxSTRING:
741cdf0e10cSrcweir case SbxLPSTR:
742cdf0e10cSrcweir if( !p->pOUString )
743cdf0e10cSrcweir nRes = 0;
744cdf0e10cSrcweir else
745cdf0e10cSrcweir {
746cdf0e10cSrcweir ::rtl::OString aOStr = ::rtl::OUStringToOString
747cdf0e10cSrcweir ( *p->pOUString, RTL_TEXTENCODING_ASCII_US );
748cdf0e10cSrcweir sal_Int64 n64 = aOStr.toInt64();
749cdf0e10cSrcweir if( n64 == 0 )
750cdf0e10cSrcweir {
751cdf0e10cSrcweir // Check if really 0 or invalid conversion
752cdf0e10cSrcweir double d;
753cdf0e10cSrcweir SbxDataType t;
754cdf0e10cSrcweir if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
755cdf0e10cSrcweir nRes = 0;
756cdf0e10cSrcweir else if( d > SbxMAXSALUINT64 )
757cdf0e10cSrcweir {
758cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXSALUINT64;
759cdf0e10cSrcweir }
760cdf0e10cSrcweir else if( d < 0.0 )
761cdf0e10cSrcweir {
762cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
763cdf0e10cSrcweir }
764cdf0e10cSrcweir else
765cdf0e10cSrcweir nRes = (sal_uInt64) ImpRound( d );
766cdf0e10cSrcweir }
767cdf0e10cSrcweir else if( n64 < 0 )
768cdf0e10cSrcweir {
769cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
770cdf0e10cSrcweir }
771cdf0e10cSrcweir else
772cdf0e10cSrcweir {
773cdf0e10cSrcweir nRes = n64;
774cdf0e10cSrcweir }
775cdf0e10cSrcweir }
776cdf0e10cSrcweir break;
777cdf0e10cSrcweir case SbxOBJECT:
778cdf0e10cSrcweir {
779cdf0e10cSrcweir SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
780cdf0e10cSrcweir if( pVal )
781cdf0e10cSrcweir nRes = pVal->GetUInt64();
782cdf0e10cSrcweir else
783cdf0e10cSrcweir {
784cdf0e10cSrcweir SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
785cdf0e10cSrcweir }
786cdf0e10cSrcweir break;
787cdf0e10cSrcweir }
788cdf0e10cSrcweir
789cdf0e10cSrcweir case SbxBYREF | SbxCHAR:
790cdf0e10cSrcweir nRes = *p->pChar; break;
791cdf0e10cSrcweir case SbxBYREF | SbxBYTE:
792cdf0e10cSrcweir nRes = *p->pByte; break;
793cdf0e10cSrcweir case SbxBYREF | SbxINTEGER:
794cdf0e10cSrcweir case SbxBYREF | SbxBOOL:
795cdf0e10cSrcweir nRes = *p->pInteger; break;
796cdf0e10cSrcweir case SbxBYREF | SbxLONG:
797cdf0e10cSrcweir nRes = *p->pLong; break;
798cdf0e10cSrcweir case SbxBYREF | SbxULONG:
799cdf0e10cSrcweir nRes = *p->pULong; break;
800cdf0e10cSrcweir case SbxBYREF | SbxSALUINT64:
801cdf0e10cSrcweir nRes = *p->puInt64; break;
802cdf0e10cSrcweir
803cdf0e10cSrcweir // from here the values has to be checked
804cdf0e10cSrcweir case SbxBYREF | SbxERROR:
805cdf0e10cSrcweir case SbxBYREF | SbxUSHORT:
806cdf0e10cSrcweir aTmp.nUShort = *p->pUShort; goto ref;
807cdf0e10cSrcweir case SbxBYREF | SbxSINGLE:
808cdf0e10cSrcweir aTmp.nSingle = *p->pSingle; goto ref;
809cdf0e10cSrcweir case SbxBYREF | SbxDATE:
810cdf0e10cSrcweir case SbxBYREF | SbxDOUBLE:
811cdf0e10cSrcweir aTmp.nDouble = *p->pDouble; goto ref;
812cdf0e10cSrcweir case SbxBYREF | SbxULONG64:
813cdf0e10cSrcweir aTmp.nULong64 = *p->pULong64; goto ref;
814cdf0e10cSrcweir case SbxBYREF | SbxLONG64:
815cdf0e10cSrcweir case SbxBYREF | SbxCURRENCY:
816cdf0e10cSrcweir aTmp.nLong64 = *p->pLong64; goto ref;
817cdf0e10cSrcweir case SbxBYREF | SbxSALINT64:
818cdf0e10cSrcweir aTmp.nInt64 = *p->pnInt64; goto ref;
819cdf0e10cSrcweir ref:
820cdf0e10cSrcweir aTmp.eType = SbxDataType( p->eType & 0x0FFF );
821cdf0e10cSrcweir p = &aTmp; goto start;
822cdf0e10cSrcweir
823cdf0e10cSrcweir default:
824cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
825cdf0e10cSrcweir }
826cdf0e10cSrcweir return nRes;
827cdf0e10cSrcweir }
828cdf0e10cSrcweir
ImpPutUInt64(SbxValues * p,sal_uInt64 n)829cdf0e10cSrcweir void ImpPutUInt64( SbxValues* p, sal_uInt64 n )
830cdf0e10cSrcweir {
831cdf0e10cSrcweir SbxValues aTmp;
832cdf0e10cSrcweir
833cdf0e10cSrcweir start:
834cdf0e10cSrcweir switch( +p->eType )
835cdf0e10cSrcweir {
836*07a3d7f1SPedro Giffuni // Check necessary
837cdf0e10cSrcweir case SbxCHAR:
838cdf0e10cSrcweir aTmp.pChar = &p->nChar; goto direct;
839cdf0e10cSrcweir case SbxBYTE:
840cdf0e10cSrcweir aTmp.pByte = &p->nByte; goto direct;
841cdf0e10cSrcweir case SbxINTEGER:
842cdf0e10cSrcweir case SbxBOOL:
843cdf0e10cSrcweir aTmp.pInteger = &p->nInteger; goto direct;
844cdf0e10cSrcweir case SbxULONG64:
845cdf0e10cSrcweir aTmp.pULong64 = &p->nULong64; goto direct;
846cdf0e10cSrcweir case SbxLONG64:
847cdf0e10cSrcweir case SbxCURRENCY:
848cdf0e10cSrcweir aTmp.pLong64 = &p->nLong64; goto direct;
849cdf0e10cSrcweir case SbxULONG:
850cdf0e10cSrcweir aTmp.pULong = &p->nULong; goto direct;
851cdf0e10cSrcweir case SbxERROR:
852cdf0e10cSrcweir case SbxUSHORT:
853cdf0e10cSrcweir aTmp.pUShort = &p->nUShort; goto direct;
854cdf0e10cSrcweir case SbxLONG:
855cdf0e10cSrcweir aTmp.pnInt64 = &p->nInt64; goto direct;
856cdf0e10cSrcweir case SbxSALINT64:
857cdf0e10cSrcweir aTmp.pnInt64 = &p->nInt64; goto direct;
858cdf0e10cSrcweir case SbxSINGLE:
859cdf0e10cSrcweir aTmp.pSingle = &p->nSingle; goto direct;
860cdf0e10cSrcweir case SbxDATE:
861cdf0e10cSrcweir case SbxDOUBLE:
862cdf0e10cSrcweir aTmp.pDouble = &p->nDouble; goto direct;
863cdf0e10cSrcweir
864cdf0e10cSrcweir direct:
865cdf0e10cSrcweir aTmp.eType = SbxDataType( p->eType | SbxBYREF );
866cdf0e10cSrcweir p = &aTmp; goto start;
867cdf0e10cSrcweir
868*07a3d7f1SPedro Giffuni // Check not necessary
869cdf0e10cSrcweir case SbxSALUINT64:
870cdf0e10cSrcweir p->uInt64 = n; break;
871cdf0e10cSrcweir
872cdf0e10cSrcweir case SbxBYREF | SbxSTRING:
873cdf0e10cSrcweir case SbxSTRING:
874cdf0e10cSrcweir case SbxLPSTR:
875cdf0e10cSrcweir if( !p->pOUString )
876cdf0e10cSrcweir p->pOUString = new ::rtl::OUString;
877cdf0e10cSrcweir if( n > SbxMAXSALINT64 )
878cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION );
879cdf0e10cSrcweir else
880cdf0e10cSrcweir {
881cdf0e10cSrcweir ::rtl::OString aOStr = ::rtl::OString::valueOf( (sal_Int64)n );
882cdf0e10cSrcweir (*p->pOUString) = ::rtl::OStringToOUString
883cdf0e10cSrcweir ( aOStr, RTL_TEXTENCODING_ASCII_US );
884cdf0e10cSrcweir }
885cdf0e10cSrcweir break;
886cdf0e10cSrcweir case SbxOBJECT:
887cdf0e10cSrcweir {
888cdf0e10cSrcweir SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
889cdf0e10cSrcweir if( pVal )
890cdf0e10cSrcweir pVal->PutUInt64( n );
891cdf0e10cSrcweir else
892cdf0e10cSrcweir SbxBase::SetError( SbxERR_NO_OBJECT );
893cdf0e10cSrcweir break;
894cdf0e10cSrcweir }
895cdf0e10cSrcweir case SbxBYREF | SbxCHAR:
896cdf0e10cSrcweir if( n > SbxMAXCHAR )
897cdf0e10cSrcweir {
898cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCHAR;
899cdf0e10cSrcweir }
900cdf0e10cSrcweir *p->pChar = (xub_Unicode) n; break;
901cdf0e10cSrcweir case SbxBYREF | SbxBYTE:
902cdf0e10cSrcweir if( n > SbxMAXBYTE )
903cdf0e10cSrcweir {
904cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
905cdf0e10cSrcweir }
906cdf0e10cSrcweir *p->pByte = (sal_uInt8) n; break;
907cdf0e10cSrcweir case SbxBYREF | SbxINTEGER:
908cdf0e10cSrcweir case SbxBYREF | SbxBOOL:
909cdf0e10cSrcweir if( n > SbxMAXINT )
910cdf0e10cSrcweir {
911cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXINT;
912cdf0e10cSrcweir }
913cdf0e10cSrcweir *p->pInteger = (sal_Int16) n; break;
914cdf0e10cSrcweir case SbxBYREF | SbxERROR:
915cdf0e10cSrcweir case SbxBYREF | SbxUSHORT:
916cdf0e10cSrcweir if( n > SbxMAXUINT )
917cdf0e10cSrcweir {
918cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXUINT;
919cdf0e10cSrcweir }
920cdf0e10cSrcweir *p->pUShort = (sal_uInt16) n; break;
921cdf0e10cSrcweir case SbxBYREF | SbxLONG:
922cdf0e10cSrcweir if( n > SbxMAXLNG )
923cdf0e10cSrcweir {
924cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXLNG;
925cdf0e10cSrcweir }
926cdf0e10cSrcweir *p->pLong = (sal_Int32) n; break;
927cdf0e10cSrcweir case SbxBYREF | SbxULONG:
928cdf0e10cSrcweir if( n > SbxMAXULNG )
929cdf0e10cSrcweir {
930cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXULNG;
931cdf0e10cSrcweir }
932cdf0e10cSrcweir *p->pULong = (sal_uInt32) n; break;
933cdf0e10cSrcweir case SbxBYREF | SbxSINGLE:
934cdf0e10cSrcweir *p->pDouble = (float)ImpSalUInt64ToDouble( n ); break;
935cdf0e10cSrcweir case SbxBYREF | SbxDATE:
936cdf0e10cSrcweir case SbxBYREF | SbxDOUBLE:
937cdf0e10cSrcweir *p->pDouble = ImpSalUInt64ToDouble( n ); break;
938cdf0e10cSrcweir case SbxBYREF | SbxCURRENCY:
939cdf0e10cSrcweir if( n > SbxMAXSALINT64 || (sal_Int64)n > SbxMAXCURR )
940cdf0e10cSrcweir {
941cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = (sal_Int64) SbxMAXCURR;
942cdf0e10cSrcweir }
943cdf0e10cSrcweir *p->pLong64 = ImpDoubleToCurrency( (double)(sal_Int64) n ); break;
944cdf0e10cSrcweir
945cdf0e10cSrcweir case SbxBYREF | SbxSALUINT64:
946cdf0e10cSrcweir *p->puInt64 = n; break;
947cdf0e10cSrcweir case SbxBYREF | SbxSALINT64:
948cdf0e10cSrcweir if( n > SbxMAXSALINT64 )
949cdf0e10cSrcweir {
950cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
951cdf0e10cSrcweir }
952cdf0e10cSrcweir *p->pnInt64 = (sal_Int64) n; break;
953cdf0e10cSrcweir
954cdf0e10cSrcweir default:
955cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION );
956cdf0e10cSrcweir }
957cdf0e10cSrcweir }
958cdf0e10cSrcweir
959cdf0e10cSrcweir
960