1*e1f63238SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*e1f63238SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*e1f63238SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*e1f63238SAndrew Rist * distributed with this work for additional information
6*e1f63238SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*e1f63238SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*e1f63238SAndrew Rist * "License"); you may not use this file except in compliance
9*e1f63238SAndrew Rist * with the License. You may obtain a copy of the License at
10*e1f63238SAndrew Rist *
11*e1f63238SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*e1f63238SAndrew Rist *
13*e1f63238SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*e1f63238SAndrew Rist * software distributed under the License is distributed on an
15*e1f63238SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*e1f63238SAndrew Rist * KIND, either express or implied. See the License for the
17*e1f63238SAndrew Rist * specific language governing permissions and limitations
18*e1f63238SAndrew Rist * under the License.
19*e1f63238SAndrew Rist *
20*e1f63238SAndrew Rist *************************************************************/
21*e1f63238SAndrew Rist
22*e1f63238SAndrew 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
ImpGetLong(const SbxValues * p)30cdf0e10cSrcweir sal_Int32 ImpGetLong( const SbxValues* p )
31cdf0e10cSrcweir {
32cdf0e10cSrcweir SbxValues aTmp;
33cdf0e10cSrcweir sal_Int32 nRes;
34cdf0e10cSrcweir start:
35cdf0e10cSrcweir switch( +p->eType )
36cdf0e10cSrcweir {
37cdf0e10cSrcweir case SbxNULL:
38cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION );
39cdf0e10cSrcweir case SbxEMPTY:
40cdf0e10cSrcweir nRes = 0; break;
41cdf0e10cSrcweir case SbxCHAR:
42cdf0e10cSrcweir nRes = p->nChar; break;
43cdf0e10cSrcweir case SbxBYTE:
44cdf0e10cSrcweir nRes = p->nByte; break;
45cdf0e10cSrcweir case SbxINTEGER:
46cdf0e10cSrcweir case SbxBOOL:
47cdf0e10cSrcweir nRes = p->nInteger; break;
48cdf0e10cSrcweir case SbxERROR:
49cdf0e10cSrcweir case SbxUSHORT:
50cdf0e10cSrcweir nRes = p->nUShort; break;
51cdf0e10cSrcweir case SbxLONG:
52cdf0e10cSrcweir nRes = p->nLong; break;
53cdf0e10cSrcweir case SbxULONG:
54cdf0e10cSrcweir if( p->nULong > SbxMAXLNG )
55cdf0e10cSrcweir {
56cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXLNG;
57cdf0e10cSrcweir }
58cdf0e10cSrcweir else
59cdf0e10cSrcweir nRes = (sal_Int32) p->nULong;
60cdf0e10cSrcweir break;
61cdf0e10cSrcweir case SbxSINGLE:
62cdf0e10cSrcweir if( p->nSingle > SbxMAXLNG )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXLNG;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir else if( p->nSingle < SbxMINLNG )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINLNG;
69cdf0e10cSrcweir }
70cdf0e10cSrcweir else
71cdf0e10cSrcweir nRes = (sal_Int32) ImpRound( p->nSingle );
72cdf0e10cSrcweir break;
73cdf0e10cSrcweir case SbxDATE:
74cdf0e10cSrcweir case SbxDOUBLE:
75cdf0e10cSrcweir case SbxLONG64:
76cdf0e10cSrcweir case SbxULONG64:
77cdf0e10cSrcweir case SbxSALINT64:
78cdf0e10cSrcweir case SbxSALUINT64:
79cdf0e10cSrcweir case SbxCURRENCY:
80cdf0e10cSrcweir case SbxDECIMAL:
81cdf0e10cSrcweir case SbxBYREF | SbxDECIMAL:
82cdf0e10cSrcweir {
83cdf0e10cSrcweir double dVal;
84cdf0e10cSrcweir if( p->eType == SbxCURRENCY )
85cdf0e10cSrcweir dVal = ImpCurrencyToDouble( p->nLong64 );
86cdf0e10cSrcweir else if( p->eType == SbxLONG64 )
87cdf0e10cSrcweir dVal = ImpINT64ToDouble( p->nLong64 );
88cdf0e10cSrcweir else if( p->eType == SbxULONG64 )
89cdf0e10cSrcweir dVal = ImpUINT64ToDouble( p->nULong64 );
90cdf0e10cSrcweir else if( p->eType == SbxSALINT64 )
91cdf0e10cSrcweir dVal = static_cast< double >(p->nInt64);
92cdf0e10cSrcweir else if( p->eType == SbxSALUINT64 )
93cdf0e10cSrcweir dVal = ImpSalUInt64ToDouble( p->uInt64 );
94cdf0e10cSrcweir else if( p->eType == SbxDECIMAL )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir dVal = 0.0;
97cdf0e10cSrcweir if( p->pDecimal )
98cdf0e10cSrcweir p->pDecimal->getDouble( dVal );
99cdf0e10cSrcweir }
100cdf0e10cSrcweir else
101cdf0e10cSrcweir dVal = p->nDouble;
102cdf0e10cSrcweir
103cdf0e10cSrcweir if( dVal > SbxMAXLNG )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXLNG;
106cdf0e10cSrcweir }
107cdf0e10cSrcweir else if( dVal < SbxMINLNG )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINLNG;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir else
112cdf0e10cSrcweir nRes = (sal_Int32) ImpRound( dVal );
113cdf0e10cSrcweir break;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir case SbxBYREF | SbxSTRING:
116cdf0e10cSrcweir case SbxSTRING:
117cdf0e10cSrcweir case SbxLPSTR:
118cdf0e10cSrcweir if( !p->pOUString )
119cdf0e10cSrcweir nRes = 0;
120cdf0e10cSrcweir else
121cdf0e10cSrcweir {
122cdf0e10cSrcweir double d;
123cdf0e10cSrcweir SbxDataType t;
124cdf0e10cSrcweir if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
125cdf0e10cSrcweir nRes = 0;
126cdf0e10cSrcweir else if( d > SbxMAXLNG )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXLNG;
129cdf0e10cSrcweir }
130cdf0e10cSrcweir else if( d < SbxMINLNG )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINLNG;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir else
135cdf0e10cSrcweir nRes = (sal_Int32) ImpRound( d );
136cdf0e10cSrcweir }
137cdf0e10cSrcweir break;
138cdf0e10cSrcweir case SbxOBJECT:
139cdf0e10cSrcweir {
140cdf0e10cSrcweir SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
141cdf0e10cSrcweir if( pVal )
142cdf0e10cSrcweir nRes = pVal->GetLong();
143cdf0e10cSrcweir else
144cdf0e10cSrcweir {
145cdf0e10cSrcweir SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir break;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
150cdf0e10cSrcweir case SbxBYREF | SbxCHAR:
151cdf0e10cSrcweir nRes = *p->pChar; break;
152cdf0e10cSrcweir case SbxBYREF | SbxBYTE:
153cdf0e10cSrcweir nRes = *p->pByte; break;
154cdf0e10cSrcweir case SbxBYREF | SbxINTEGER:
155cdf0e10cSrcweir case SbxBYREF | SbxBOOL:
156cdf0e10cSrcweir nRes = *p->pInteger; break;
157cdf0e10cSrcweir case SbxBYREF | SbxLONG:
158cdf0e10cSrcweir nRes = *p->pLong; break;
159cdf0e10cSrcweir
160cdf0e10cSrcweir // ab hier muss getestet werden
161cdf0e10cSrcweir case SbxBYREF | SbxULONG:
162cdf0e10cSrcweir aTmp.nULong = *p->pULong; goto ref;
163cdf0e10cSrcweir case SbxBYREF | SbxERROR:
164cdf0e10cSrcweir case SbxBYREF | SbxUSHORT:
165cdf0e10cSrcweir aTmp.nUShort = *p->pUShort; goto ref;
166cdf0e10cSrcweir case SbxBYREF | SbxSINGLE:
167cdf0e10cSrcweir aTmp.nSingle = *p->pSingle; goto ref;
168cdf0e10cSrcweir case SbxBYREF | SbxDATE:
169cdf0e10cSrcweir case SbxBYREF | SbxDOUBLE:
170cdf0e10cSrcweir aTmp.nDouble = *p->pDouble; goto ref;
171cdf0e10cSrcweir case SbxBYREF | SbxSALINT64:
172cdf0e10cSrcweir aTmp.nInt64 = *p->pnInt64; goto ref;
173cdf0e10cSrcweir case SbxBYREF | SbxSALUINT64:
174cdf0e10cSrcweir aTmp.uInt64 = *p->puInt64; goto ref;
175cdf0e10cSrcweir case SbxBYREF | SbxULONG64:
176cdf0e10cSrcweir aTmp.nULong64 = *p->pULong64; goto ref;
177cdf0e10cSrcweir case SbxBYREF | SbxLONG64:
178cdf0e10cSrcweir case SbxBYREF | SbxCURRENCY:
179cdf0e10cSrcweir aTmp.nLong64 = *p->pLong64; goto ref;
180cdf0e10cSrcweir ref:
181cdf0e10cSrcweir aTmp.eType = SbxDataType( p->eType & 0x0FFF );
182cdf0e10cSrcweir p = &aTmp; goto start;
183cdf0e10cSrcweir
184cdf0e10cSrcweir default:
185cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir return nRes;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir
ImpPutLong(SbxValues * p,sal_Int32 n)190cdf0e10cSrcweir void ImpPutLong( SbxValues* p, sal_Int32 n )
191cdf0e10cSrcweir {
192cdf0e10cSrcweir SbxValues aTmp;
193cdf0e10cSrcweir
194cdf0e10cSrcweir start:
195cdf0e10cSrcweir switch( +p->eType )
196cdf0e10cSrcweir {
197cdf0e10cSrcweir // Ab hier muss getestet werden
198cdf0e10cSrcweir case SbxCHAR:
199cdf0e10cSrcweir aTmp.pChar = &p->nChar; goto direct;
200cdf0e10cSrcweir case SbxBYTE:
201cdf0e10cSrcweir aTmp.pByte = &p->nByte; goto direct;
202cdf0e10cSrcweir case SbxINTEGER:
203cdf0e10cSrcweir case SbxBOOL:
204cdf0e10cSrcweir aTmp.pInteger = &p->nInteger; goto direct;
205cdf0e10cSrcweir case SbxULONG64:
206cdf0e10cSrcweir aTmp.pULong64 = &p->nULong64; goto direct;
207cdf0e10cSrcweir case SbxLONG64:
208cdf0e10cSrcweir case SbxCURRENCY:
209cdf0e10cSrcweir aTmp.pLong64 = &p->nLong64; goto direct;
210cdf0e10cSrcweir case SbxULONG:
211cdf0e10cSrcweir aTmp.pULong = &p->nULong; goto direct;
212cdf0e10cSrcweir case SbxSALUINT64:
213cdf0e10cSrcweir aTmp.puInt64 = &p->uInt64; goto direct;
214cdf0e10cSrcweir case SbxERROR:
215cdf0e10cSrcweir case SbxUSHORT:
216cdf0e10cSrcweir aTmp.pUShort = &p->nUShort;
217cdf0e10cSrcweir direct:
218cdf0e10cSrcweir aTmp.eType = SbxDataType( p->eType | SbxBYREF );
219cdf0e10cSrcweir p = &aTmp; goto start;
220cdf0e10cSrcweir
221cdf0e10cSrcweir // ab hier nicht mehr
222cdf0e10cSrcweir case SbxLONG:
223cdf0e10cSrcweir p->nLong = n; break;
224cdf0e10cSrcweir case SbxSINGLE:
225cdf0e10cSrcweir p->nSingle = (float) n; break;
226cdf0e10cSrcweir case SbxDATE:
227cdf0e10cSrcweir case SbxDOUBLE:
228cdf0e10cSrcweir p->nDouble = n; break;
229cdf0e10cSrcweir case SbxSALINT64:
230cdf0e10cSrcweir p->nInt64 = n; break;
231cdf0e10cSrcweir case SbxDECIMAL:
232cdf0e10cSrcweir case SbxBYREF | SbxDECIMAL:
233cdf0e10cSrcweir ImpCreateDecimal( p )->setLong( n );
234cdf0e10cSrcweir break;
235cdf0e10cSrcweir
236cdf0e10cSrcweir case SbxBYREF | SbxSTRING:
237cdf0e10cSrcweir case SbxSTRING:
238cdf0e10cSrcweir case SbxLPSTR:
239cdf0e10cSrcweir if( !p->pOUString )
240cdf0e10cSrcweir p->pOUString = new ::rtl::OUString;
241cdf0e10cSrcweir ImpCvtNum( (double) n, 0, *p->pOUString );
242cdf0e10cSrcweir break;
243cdf0e10cSrcweir case SbxOBJECT:
244cdf0e10cSrcweir {
245cdf0e10cSrcweir SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
246cdf0e10cSrcweir if( pVal )
247cdf0e10cSrcweir pVal->PutLong( n );
248cdf0e10cSrcweir else
249cdf0e10cSrcweir SbxBase::SetError( SbxERR_NO_OBJECT );
250cdf0e10cSrcweir break;
251cdf0e10cSrcweir }
252cdf0e10cSrcweir case SbxBYREF | SbxCHAR:
253cdf0e10cSrcweir if( n > SbxMAXCHAR )
254cdf0e10cSrcweir {
255cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCHAR;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir else if( n < SbxMINCHAR )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCHAR;
260cdf0e10cSrcweir }
261cdf0e10cSrcweir *p->pChar = (xub_Unicode) n; break;
262cdf0e10cSrcweir case SbxBYREF | SbxBYTE:
263cdf0e10cSrcweir if( n > SbxMAXBYTE )
264cdf0e10cSrcweir {
265cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
266cdf0e10cSrcweir }
267cdf0e10cSrcweir else if( n < 0 )
268cdf0e10cSrcweir {
269cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
270cdf0e10cSrcweir }
271cdf0e10cSrcweir *p->pByte = (sal_uInt8) n; break;
272cdf0e10cSrcweir case SbxBYREF | SbxINTEGER:
273cdf0e10cSrcweir case SbxBYREF | SbxBOOL:
274cdf0e10cSrcweir if( n > SbxMAXINT )
275cdf0e10cSrcweir {
276cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXINT;
277cdf0e10cSrcweir }
278cdf0e10cSrcweir else if( n < SbxMININT )
279cdf0e10cSrcweir {
280cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMININT;
281cdf0e10cSrcweir }
282cdf0e10cSrcweir *p->pInteger = (sal_Int16) n; break;
283cdf0e10cSrcweir case SbxBYREF | SbxERROR:
284cdf0e10cSrcweir case SbxBYREF | SbxUSHORT:
285cdf0e10cSrcweir if( n > SbxMAXUINT )
286cdf0e10cSrcweir {
287cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXUINT;
288cdf0e10cSrcweir }
289cdf0e10cSrcweir else if( n < 0 )
290cdf0e10cSrcweir {
291cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
292cdf0e10cSrcweir }
293cdf0e10cSrcweir *p->pUShort = (sal_uInt16) n; break;
294cdf0e10cSrcweir case SbxBYREF | SbxLONG:
295cdf0e10cSrcweir *p->pLong = n; break;
296cdf0e10cSrcweir case SbxBYREF | SbxULONG:
297cdf0e10cSrcweir if( n < 0 )
298cdf0e10cSrcweir {
299cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
300cdf0e10cSrcweir }
301cdf0e10cSrcweir *p->pULong = (sal_uInt32) n; break;
302cdf0e10cSrcweir case SbxBYREF | SbxSALINT64:
303cdf0e10cSrcweir *p->pnInt64 = n; break;
304cdf0e10cSrcweir case SbxBYREF | SbxSALUINT64:
305cdf0e10cSrcweir if( n < 0 )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); *p->puInt64 = 0;
308cdf0e10cSrcweir }
309cdf0e10cSrcweir else
310cdf0e10cSrcweir *p->puInt64 = n;
311cdf0e10cSrcweir break;
312cdf0e10cSrcweir case SbxBYREF | SbxSINGLE:
313cdf0e10cSrcweir *p->pSingle = (float) n; break;
314cdf0e10cSrcweir case SbxBYREF | SbxDATE:
315cdf0e10cSrcweir case SbxBYREF | SbxDOUBLE:
316cdf0e10cSrcweir *p->pDouble = (double) n; break;
317cdf0e10cSrcweir case SbxBYREF | SbxCURRENCY:
318cdf0e10cSrcweir double d;
319cdf0e10cSrcweir if( n > SbxMAXCURR )
320cdf0e10cSrcweir {
321cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); d = SbxMAXCURR;
322cdf0e10cSrcweir }
323cdf0e10cSrcweir else if( n < SbxMINCURR )
324cdf0e10cSrcweir {
325cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); d = SbxMINCURR;
326cdf0e10cSrcweir }
327cdf0e10cSrcweir else
328cdf0e10cSrcweir {
329cdf0e10cSrcweir d = n;
330cdf0e10cSrcweir }
331cdf0e10cSrcweir *p->pLong64 = ImpDoubleToCurrency( d ); break;
332cdf0e10cSrcweir
333cdf0e10cSrcweir default:
334cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION );
335cdf0e10cSrcweir }
336cdf0e10cSrcweir }
337cdf0e10cSrcweir
338