1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
)
32 SbxBase::SetError( SbxERR_CONVERSION
);
39 nRes
= p
->nByte
; break;
44 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
56 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
62 nRes
= p
->nULong
; break;
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;
73 nRes
= (sal_uInt32
) ( p
->nSingle
+ 0.5 );
81 case SbxBYREF
| SbxDECIMAL
:
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
)
94 p
->pDecimal
->getDouble( dVal
);
99 if( dVal
> SbxMAXULNG
)
101 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXULNG
;
105 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
108 nRes
= (sal_uInt32
) ( dVal
+ 0.5 );
111 case SbxBYREF
| SbxSTRING
:
120 if( ImpScan( *p
->pOUString
, d
, t
, NULL
) != SbxERR_OK
)
122 else if( d
> SbxMAXULNG
)
124 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXULNG
;
128 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= 0;
131 nRes
= (sal_uInt32
) ( d
+ 0.5 );
136 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
138 nRes
= pVal
->GetULong();
141 SbxBase::SetError( SbxERR_NO_OBJECT
); nRes
= 0;
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
;
173 aTmp
.eType
= SbxDataType( p
->eType
& 0x0FFF );
174 p
= &aTmp
; goto start
;
177 SbxBase::SetError( SbxERR_CONVERSION
); nRes
= 0;
182 void ImpPutULong( SbxValues
* p
, sal_uInt32 n
)
189 p
->nULong
= n
; break;
191 p
->nSingle
= (float) n
; break;
194 p
->nDouble
= n
; break;
197 aTmp
.pnInt64
= &p
->nInt64
; goto direct
;
199 p
->uInt64
= n
; break;
201 case SbxBYREF
| SbxDECIMAL
:
202 ImpCreateDecimal( p
)->setULong( n
);
205 // from here on tests
207 aTmp
.pChar
= &p
->nChar
; goto direct
;
209 aTmp
.pByte
= &p
->nByte
; goto direct
;
212 aTmp
.pInteger
= &p
->nInteger
; goto direct
;
214 aTmp
.pLong
= &p
->nLong
; goto direct
;
217 aTmp
.pUShort
= &p
->nUShort
; goto direct
;
219 aTmp
.eType
= SbxDataType( p
->eType
| SbxBYREF
);
220 p
= &aTmp
; goto start
;
222 case SbxBYREF
| SbxSTRING
:
226 p
->pOUString
= new OUString
;
227 ImpCvtNum( (double) n
, 0, *p
->pOUString
);
231 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
235 SbxBase::SetError( SbxERR_NO_OBJECT
);
238 case SbxBYREF
| SbxCHAR
:
241 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXCHAR
;
243 *p
->pChar
= (sal_Unicode
) n
; break;
244 case SbxBYREF
| SbxBYTE
:
247 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXBYTE
;
249 *p
->pByte
= (sal_uInt8
) n
; break;
250 case SbxBYREF
| SbxINTEGER
:
251 case SbxBYREF
| SbxBOOL
:
254 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXINT
;
256 *p
->pInteger
= (sal_Int16
) n
; break;
257 case SbxBYREF
| SbxERROR
:
258 case SbxBYREF
| SbxUSHORT
:
261 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXUINT
;
263 *p
->pUShort
= (sal_uInt16
) n
; break;
264 case SbxBYREF
| SbxLONG
:
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;
285 SbxBase::SetError( SbxERR_CONVERSION
);
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */