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
10cdf0e10cSrcweir *
11*e1f63238SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
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.
19cdf0e10cSrcweir *
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
30cdf0e10cSrcweir // AB 29.10.99 Unicode
31cdf0e10cSrcweir #ifndef _USE_NO_NAMESPACE
32cdf0e10cSrcweir using namespace rtl;
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir
ImpGetChar(const SbxValues * p)35cdf0e10cSrcweir xub_Unicode ImpGetChar( const SbxValues* p )
36cdf0e10cSrcweir {
37cdf0e10cSrcweir SbxValues aTmp;
38cdf0e10cSrcweir xub_Unicode nRes = 0;
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 = (xub_Unicode) p->nByte;
50cdf0e10cSrcweir break;
51cdf0e10cSrcweir case SbxINTEGER:
52cdf0e10cSrcweir case SbxBOOL:
53cdf0e10cSrcweir if( p->nInteger < SbxMINCHAR )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
56cdf0e10cSrcweir }
57cdf0e10cSrcweir else
58cdf0e10cSrcweir nRes = (xub_Unicode) p->nInteger;
59cdf0e10cSrcweir break;
60cdf0e10cSrcweir case SbxERROR:
61cdf0e10cSrcweir case SbxUSHORT:
62cdf0e10cSrcweir nRes = (xub_Unicode) p->nUShort;
63cdf0e10cSrcweir break;
64cdf0e10cSrcweir case SbxLONG:
65cdf0e10cSrcweir if( p->nLong > SbxMAXCHAR )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir else if( p->nLong < SbxMINCHAR )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir else
74cdf0e10cSrcweir nRes = (xub_Unicode) p->nLong;
75cdf0e10cSrcweir break;
76cdf0e10cSrcweir case SbxULONG:
77cdf0e10cSrcweir if( p->nULong > SbxMAXCHAR )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir else
82cdf0e10cSrcweir nRes = (xub_Unicode) p->nULong;
83cdf0e10cSrcweir break;
84cdf0e10cSrcweir case SbxSALINT64:
85cdf0e10cSrcweir if( p->nInt64 > SbxMAXCHAR )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir else if( p->nInt64 < SbxMINCHAR )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir else
94cdf0e10cSrcweir nRes = (xub_Unicode) p->nInt64;
95cdf0e10cSrcweir break;
96cdf0e10cSrcweir case SbxSALUINT64:
97cdf0e10cSrcweir if( p->uInt64 > SbxMAXCHAR )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir else
102cdf0e10cSrcweir nRes = (xub_Unicode) p->uInt64;
103cdf0e10cSrcweir break;
104cdf0e10cSrcweir case SbxSINGLE:
105cdf0e10cSrcweir if( p->nSingle > SbxMAXCHAR )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir else if( p->nSingle < SbxMINCHAR )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir else
114cdf0e10cSrcweir nRes = (xub_Unicode) ImpRound( p->nSingle );
115cdf0e10cSrcweir break;
116cdf0e10cSrcweir case SbxDATE:
117cdf0e10cSrcweir case SbxDOUBLE:
118cdf0e10cSrcweir case SbxLONG64:
119cdf0e10cSrcweir case SbxULONG64:
120cdf0e10cSrcweir case SbxCURRENCY:
121cdf0e10cSrcweir case SbxDECIMAL:
122cdf0e10cSrcweir case SbxBYREF | SbxDECIMAL:
123cdf0e10cSrcweir {
124cdf0e10cSrcweir double dVal;
125cdf0e10cSrcweir if( p->eType == SbxCURRENCY )
126cdf0e10cSrcweir dVal = ImpCurrencyToDouble( p->nLong64 );
127cdf0e10cSrcweir else if( p->eType == SbxLONG64 )
128cdf0e10cSrcweir dVal = ImpINT64ToDouble( p->nLong64 );
129cdf0e10cSrcweir else if( p->eType == SbxULONG64 )
130cdf0e10cSrcweir dVal = ImpUINT64ToDouble( p->nULong64 );
131cdf0e10cSrcweir else if( p->eType == SbxDECIMAL )
132cdf0e10cSrcweir {
133cdf0e10cSrcweir dVal = 0.0;
134cdf0e10cSrcweir if( p->pDecimal )
135cdf0e10cSrcweir p->pDecimal->getDouble( dVal );
136cdf0e10cSrcweir }
137cdf0e10cSrcweir else
138cdf0e10cSrcweir dVal = p->nDouble;
139cdf0e10cSrcweir
140cdf0e10cSrcweir if( dVal > SbxMAXCHAR )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir else if( dVal < SbxMINCHAR )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir else
149cdf0e10cSrcweir nRes = (sal_uInt8) ImpRound( dVal );
150cdf0e10cSrcweir break;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir case SbxBYREF | SbxSTRING:
153cdf0e10cSrcweir case SbxSTRING:
154cdf0e10cSrcweir case SbxLPSTR:
155cdf0e10cSrcweir if ( p->pOUString )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir double d;
158cdf0e10cSrcweir SbxDataType t;
159cdf0e10cSrcweir if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
160cdf0e10cSrcweir nRes = 0;
161cdf0e10cSrcweir else if( d > SbxMAXCHAR )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir else if( d < SbxMINCHAR )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir else
170cdf0e10cSrcweir nRes = (xub_Unicode) ImpRound( d );
171cdf0e10cSrcweir }
172cdf0e10cSrcweir break;
173cdf0e10cSrcweir case SbxOBJECT:
174cdf0e10cSrcweir {
175cdf0e10cSrcweir SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
176cdf0e10cSrcweir if( pVal )
177cdf0e10cSrcweir nRes = pVal->GetChar();
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 // ab hier wird getestet
188cdf0e10cSrcweir case SbxBYREF | SbxBYTE:
189cdf0e10cSrcweir aTmp.nByte = *p->pByte; goto ref;
190cdf0e10cSrcweir case SbxBYREF | SbxINTEGER:
191cdf0e10cSrcweir case SbxBYREF | SbxBOOL:
192cdf0e10cSrcweir aTmp.nInteger = *p->pInteger; goto ref;
193cdf0e10cSrcweir case SbxBYREF | SbxLONG:
194cdf0e10cSrcweir aTmp.nLong = *p->pLong; goto ref;
195cdf0e10cSrcweir case SbxBYREF | SbxULONG:
196cdf0e10cSrcweir aTmp.nULong = *p->pULong; goto ref;
197cdf0e10cSrcweir case SbxBYREF | SbxERROR:
198cdf0e10cSrcweir case SbxBYREF | SbxUSHORT:
199cdf0e10cSrcweir aTmp.nUShort = *p->pUShort; goto ref;
200cdf0e10cSrcweir case SbxBYREF | SbxSINGLE:
201cdf0e10cSrcweir aTmp.nSingle = *p->pSingle; goto ref;
202cdf0e10cSrcweir case SbxBYREF | SbxDATE:
203cdf0e10cSrcweir case SbxBYREF | SbxDOUBLE:
204cdf0e10cSrcweir aTmp.nDouble = *p->pDouble; goto ref;
205cdf0e10cSrcweir case SbxBYREF | SbxULONG64:
206cdf0e10cSrcweir aTmp.nULong64 = *p->pULong64; goto ref;
207cdf0e10cSrcweir case SbxBYREF | SbxLONG64:
208cdf0e10cSrcweir case SbxBYREF | SbxCURRENCY:
209cdf0e10cSrcweir aTmp.nLong64 = *p->pLong64; goto ref;
210cdf0e10cSrcweir case SbxBYREF | SbxSALINT64:
211cdf0e10cSrcweir aTmp.nInt64 = *p->pnInt64; goto ref;
212cdf0e10cSrcweir case SbxBYREF | SbxSALUINT64:
213cdf0e10cSrcweir aTmp.uInt64 = *p->puInt64; goto ref;
214cdf0e10cSrcweir ref:
215cdf0e10cSrcweir aTmp.eType = SbxDataType( p->eType & 0x0FFF );
216cdf0e10cSrcweir p = &aTmp; goto start;
217cdf0e10cSrcweir
218cdf0e10cSrcweir default:
219cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
220cdf0e10cSrcweir }
221cdf0e10cSrcweir return nRes;
222cdf0e10cSrcweir }
223cdf0e10cSrcweir
ImpPutChar(SbxValues * p,xub_Unicode n)224cdf0e10cSrcweir void ImpPutChar( SbxValues* p, xub_Unicode n )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir SbxValues aTmp;
227cdf0e10cSrcweir start:
228cdf0e10cSrcweir switch( +p->eType )
229cdf0e10cSrcweir {
230cdf0e10cSrcweir case SbxCHAR:
231cdf0e10cSrcweir p->nChar = n; break;
232cdf0e10cSrcweir case SbxINTEGER:
233cdf0e10cSrcweir case SbxBOOL:
234cdf0e10cSrcweir p->nInteger = n; break;
235cdf0e10cSrcweir case SbxLONG:
236cdf0e10cSrcweir p->nLong = n; break;
237cdf0e10cSrcweir case SbxSINGLE:
238cdf0e10cSrcweir p->nSingle = n; break;
239cdf0e10cSrcweir case SbxDATE:
240cdf0e10cSrcweir case SbxDOUBLE:
241cdf0e10cSrcweir p->nDouble = n; break;
242cdf0e10cSrcweir case SbxSALINT64:
243cdf0e10cSrcweir p->nInt64 = n; break;
244cdf0e10cSrcweir case SbxSALUINT64:
245cdf0e10cSrcweir p->uInt64 = n; break;
246cdf0e10cSrcweir case SbxULONG64:
247cdf0e10cSrcweir p->nULong64 = ImpDoubleToUINT64( (double)n ); break;
248cdf0e10cSrcweir case SbxLONG64:
249cdf0e10cSrcweir p->nLong64 = ImpDoubleToINT64( (double)n ); break;
250cdf0e10cSrcweir case SbxCURRENCY:
251cdf0e10cSrcweir p->nLong64 = ImpDoubleToCurrency( (double)n ); break;
252cdf0e10cSrcweir case SbxBYREF | SbxDECIMAL:
253cdf0e10cSrcweir ImpCreateDecimal( p )->setChar( n );
254cdf0e10cSrcweir break;
255cdf0e10cSrcweir
256cdf0e10cSrcweir // ab hier wird getestet
257cdf0e10cSrcweir case SbxBYTE:
258cdf0e10cSrcweir aTmp.pByte = &p->nByte; goto direct;
259cdf0e10cSrcweir case SbxULONG:
260cdf0e10cSrcweir aTmp.pULong = &p->nULong; goto direct;
261cdf0e10cSrcweir case SbxERROR:
262cdf0e10cSrcweir case SbxUSHORT:
263cdf0e10cSrcweir aTmp.pUShort = &p->nUShort; goto direct;
264cdf0e10cSrcweir direct:
265cdf0e10cSrcweir aTmp.eType = SbxDataType( p->eType | SbxBYREF );
266cdf0e10cSrcweir p = &aTmp; goto start;
267cdf0e10cSrcweir
268cdf0e10cSrcweir case SbxBYREF | SbxSTRING:
269cdf0e10cSrcweir case SbxSTRING:
270cdf0e10cSrcweir case SbxLPSTR:
271cdf0e10cSrcweir if ( !p->pOUString )
272cdf0e10cSrcweir p->pOUString = new ::rtl::OUString( n );
273cdf0e10cSrcweir else
274cdf0e10cSrcweir *p->pOUString = ::rtl::OUString( n );
275cdf0e10cSrcweir break;
276cdf0e10cSrcweir case SbxOBJECT:
277cdf0e10cSrcweir {
278cdf0e10cSrcweir SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
279cdf0e10cSrcweir if( pVal )
280cdf0e10cSrcweir pVal->PutChar( n );
281cdf0e10cSrcweir else
282cdf0e10cSrcweir SbxBase::SetError( SbxERR_NO_OBJECT );
283cdf0e10cSrcweir break;
284cdf0e10cSrcweir }
285cdf0e10cSrcweir case SbxBYREF | SbxCHAR:
286cdf0e10cSrcweir *p->pChar = n; break;
287cdf0e10cSrcweir case SbxBYREF | SbxBYTE:
288cdf0e10cSrcweir *p->pByte = (sal_uInt8) n; break;
289cdf0e10cSrcweir case SbxBYREF | SbxINTEGER:
290cdf0e10cSrcweir case SbxBYREF | SbxBOOL:
291cdf0e10cSrcweir *p->pInteger = n; break;
292cdf0e10cSrcweir case SbxBYREF | SbxERROR:
293cdf0e10cSrcweir case SbxBYREF | SbxUSHORT:
294cdf0e10cSrcweir *p->pUShort = (sal_uInt16) n; break;
295cdf0e10cSrcweir case SbxBYREF | SbxLONG:
296cdf0e10cSrcweir *p->pLong = (sal_Int32) n; break;
297cdf0e10cSrcweir case SbxBYREF | SbxULONG:
298cdf0e10cSrcweir *p->pULong = (sal_uInt32) n; break;
299cdf0e10cSrcweir case SbxBYREF | SbxSINGLE:
300cdf0e10cSrcweir *p->pSingle = (float) n; break;
301cdf0e10cSrcweir case SbxBYREF | SbxDATE:
302cdf0e10cSrcweir case SbxBYREF | SbxDOUBLE:
303cdf0e10cSrcweir *p->pDouble = (double) n; break;
304cdf0e10cSrcweir case SbxBYREF | SbxSALINT64:
305cdf0e10cSrcweir *p->pnInt64 = n; break;
306cdf0e10cSrcweir case SbxBYREF | SbxSALUINT64:
307cdf0e10cSrcweir *p->puInt64 = n; break;
308cdf0e10cSrcweir case SbxBYREF | SbxULONG64:
309cdf0e10cSrcweir *p->pULong64 = ImpDoubleToUINT64( (double)n ); break;
310cdf0e10cSrcweir case SbxBYREF | SbxLONG64:
311cdf0e10cSrcweir *p->pLong64 = ImpDoubleToINT64( (double)n ); break;
312cdf0e10cSrcweir case SbxBYREF | SbxCURRENCY:
313cdf0e10cSrcweir *p->pLong64 = ImpDoubleToCurrency( (double)n ); break;
314cdf0e10cSrcweir
315cdf0e10cSrcweir default:
316cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION );
317cdf0e10cSrcweir }
318cdf0e10cSrcweir }
319cdf0e10cSrcweir
320cdf0e10cSrcweir
321