bump product version to 4.1.6.2
[LibreOffice.git] / basic / source / sbx / sbxulng.cxx
blobb96d8b41a4205524741e4be9884d03c7ec6356b8
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 sal_uInt32 ImpGetULong( const SbxValues* p )
26 SbxValues aTmp;
27 sal_uInt32 nRes;
28 start:
29 switch( +p->eType )
31 case SbxNULL:
32 SbxBase::SetError( SbxERR_CONVERSION );
33 case SbxEMPTY:
34 nRes = 0; break;
35 case SbxCHAR:
36 nRes = p->nChar;
37 break;
38 case SbxBYTE:
39 nRes = p->nByte; break;
40 case SbxINTEGER:
41 case SbxBOOL:
42 if( p->nInteger < 0 )
44 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
46 else
47 nRes = p->nInteger;
48 break;
49 case SbxERROR:
50 case SbxUSHORT:
51 nRes = p->nUShort;
52 break;
53 case SbxLONG:
54 if( p->nLong < 0 )
56 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
58 else
59 nRes = p->nLong;
60 break;
61 case SbxULONG:
62 nRes = p->nULong; break;
63 case SbxSINGLE:
64 if( p->nSingle > SbxMAXULNG )
66 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXULNG;
68 else if( p->nSingle < 0 )
70 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
72 else
73 nRes = (sal_uInt32) ( p->nSingle + 0.5 );
74 break;
75 case SbxDATE:
76 case SbxDOUBLE:
77 case SbxSALINT64:
78 case SbxSALUINT64:
79 case SbxCURRENCY:
80 case SbxDECIMAL:
81 case SbxBYREF | SbxDECIMAL:
83 double dVal;
84 if( p->eType == SbxCURRENCY )
85 dVal = ImpCurrencyToDouble( p->nInt64 );
86 else if( p->eType == SbxSALINT64 )
87 dVal = static_cast< double >(p->nInt64);
88 else if( p->eType == SbxSALUINT64 )
89 dVal = ImpSalUInt64ToDouble( p->uInt64 );
90 else if( p->eType == SbxDECIMAL )
92 dVal = 0.0;
93 if( p->pDecimal )
94 p->pDecimal->getDouble( dVal );
96 else
97 dVal = p->nDouble;
99 if( dVal > SbxMAXULNG )
101 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXULNG;
103 else if( dVal < 0 )
105 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
107 else
108 nRes = (sal_uInt32) ( dVal + 0.5 );
109 break;
111 case SbxBYREF | SbxSTRING:
112 case SbxSTRING:
113 case SbxLPSTR:
114 if( !p->pOUString )
115 nRes = 0;
116 else
118 double d;
119 SbxDataType t;
120 if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
121 nRes = 0;
122 else if( d > SbxMAXULNG )
124 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXULNG;
126 else if( d < 0 )
128 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
130 else
131 nRes = (sal_uInt32) ( d + 0.5 );
133 break;
134 case SbxOBJECT:
136 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
137 if( pVal )
138 nRes = pVal->GetULong();
139 else
141 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
143 break;
146 case SbxBYREF | SbxBYTE:
147 nRes = *p->pByte; break;
148 case SbxBYREF | SbxERROR:
149 case SbxBYREF | SbxUSHORT:
150 nRes = *p->pUShort; break;
151 case SbxBYREF | SbxULONG:
152 nRes = *p->pULong; break;
154 // from here on tests
155 case SbxBYREF | SbxCHAR:
156 aTmp.nChar = *p->pChar; goto ref;
157 case SbxBYREF | SbxINTEGER:
158 case SbxBYREF | SbxBOOL:
159 aTmp.nInteger = *p->pInteger; goto ref;
160 case SbxBYREF | SbxLONG:
161 aTmp.nLong = *p->pLong; goto ref;
162 case SbxBYREF | SbxSINGLE:
163 aTmp.nSingle = *p->pSingle; goto ref;
164 case SbxBYREF | SbxDATE:
165 case SbxBYREF | SbxDOUBLE:
166 aTmp.nDouble = *p->pDouble; goto ref;
167 case SbxBYREF | SbxCURRENCY:
168 case SbxBYREF | SbxSALINT64:
169 aTmp.nInt64 = *p->pnInt64; goto ref;
170 case SbxBYREF | SbxSALUINT64:
171 aTmp.uInt64 = *p->puInt64; goto ref;
172 ref:
173 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
174 p = &aTmp; goto start;
176 default:
177 SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
179 return nRes;
182 void ImpPutULong( SbxValues* p, sal_uInt32 n )
184 SbxValues aTmp;
185 start:
186 switch( +p->eType )
188 case SbxULONG:
189 p->nULong = n; break;
190 case SbxSINGLE:
191 p->nSingle = (float) n; break;
192 case SbxDATE:
193 case SbxDOUBLE:
194 p->nDouble = n; break;
195 case SbxCURRENCY:
196 case SbxSALINT64:
197 aTmp.pnInt64 = &p->nInt64; goto direct;
198 case SbxSALUINT64:
199 p->uInt64 = n; break;
200 case SbxDECIMAL:
201 case SbxBYREF | SbxDECIMAL:
202 ImpCreateDecimal( p )->setULong( n );
203 break;
205 // from here on tests
206 case SbxCHAR:
207 aTmp.pChar = &p->nChar; goto direct;
208 case SbxUINT:
209 aTmp.pByte = &p->nByte; goto direct;
210 case SbxINTEGER:
211 case SbxBOOL:
212 aTmp.pInteger = &p->nInteger; goto direct;
213 case SbxLONG:
214 aTmp.pLong = &p->nLong; goto direct;
215 case SbxERROR:
216 case SbxUSHORT:
217 aTmp.pUShort = &p->nUShort; goto direct;
218 direct:
219 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
220 p = &aTmp; goto start;
222 case SbxBYREF | SbxSTRING:
223 case SbxSTRING:
224 case SbxLPSTR:
225 if( !p->pOUString )
226 p->pOUString = new OUString;
227 ImpCvtNum( (double) n, 0, *p->pOUString );
228 break;
229 case SbxOBJECT:
231 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
232 if( pVal )
233 pVal->PutULong( n );
234 else
235 SbxBase::SetError( SbxERR_NO_OBJECT );
236 break;
238 case SbxBYREF | SbxCHAR:
239 if( n > SbxMAXCHAR )
241 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCHAR;
243 *p->pChar = (sal_Unicode) n; break;
244 case SbxBYREF | SbxBYTE:
245 if( n > SbxMAXBYTE )
247 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
249 *p->pByte = (sal_uInt8) n; break;
250 case SbxBYREF | SbxINTEGER:
251 case SbxBYREF | SbxBOOL:
252 if( n > SbxMAXINT )
254 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXINT;
256 *p->pInteger = (sal_Int16) n; break;
257 case SbxBYREF | SbxERROR:
258 case SbxBYREF | SbxUSHORT:
259 if( n > SbxMAXUINT )
261 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXUINT;
263 *p->pUShort = (sal_uInt16) n; break;
264 case SbxBYREF | SbxLONG:
265 if( n > SbxMAXLNG )
267 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXLNG;
269 *p->pLong = (sal_Int32) n; break;
270 case SbxBYREF | SbxULONG:
271 *p->pULong = n; break;
272 case SbxBYREF | SbxSINGLE:
273 *p->pSingle = (float) n; break;
274 case SbxBYREF | SbxDATE:
275 case SbxBYREF | SbxDOUBLE:
276 *p->pDouble = n; break;
277 case SbxBYREF | SbxCURRENCY:
278 *p->pnInt64 = n * CURRENCY_FACTOR; break;
279 case SbxBYREF | SbxSALINT64:
280 *p->pnInt64 = n; break;
281 case SbxBYREF | SbxSALUINT64:
282 *p->puInt64 = n; break;
284 default:
285 SbxBase::SetError( SbxERR_CONVERSION );
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */