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_Int32
ImpGetLong( const SbxValues
* p
)
32 SbxBase::SetError( SbxERR_CONVERSION
);
36 nRes
= p
->nChar
; break;
38 nRes
= p
->nByte
; break;
41 nRes
= p
->nInteger
; break;
44 nRes
= p
->nUShort
; break;
46 nRes
= p
->nLong
; break;
48 if( p
->nULong
> SbxMAXLNG
)
50 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXLNG
;
53 nRes
= (sal_Int32
) p
->nULong
;
56 if( p
->nSingle
> SbxMAXLNG
)
58 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXLNG
;
60 else if( p
->nSingle
< SbxMINLNG
)
62 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINLNG
;
65 nRes
= (sal_Int32
) ImpRound( p
->nSingle
);
75 sal_Int64 tstVal
= p
->nInt64
/ CURRENCY_FACTOR
;
76 nRes
= (sal_Int32
) (tstVal
);
77 if( tstVal
< SbxMINLNG
|| SbxMAXLNG
< tstVal
) SbxBase::SetError( SbxERR_OVERFLOW
);
78 if( SbxMAXLNG
< tstVal
) nRes
= SbxMAXLNG
;
79 if( tstVal
< SbxMINLNG
) nRes
= SbxMINLNG
;
85 case SbxBYREF
| SbxDECIMAL
:
88 if( p
->eType
== SbxDECIMAL
)
92 p
->pDecimal
->getDouble( dVal
);
97 if( dVal
> SbxMAXLNG
)
99 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXLNG
;
101 else if( dVal
< SbxMINLNG
)
103 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINLNG
;
106 nRes
= (sal_Int32
) ImpRound( dVal
);
109 case SbxBYREF
| SbxSTRING
:
118 if( ImpScan( *p
->pOUString
, d
, t
, NULL
) != SbxERR_OK
)
120 else if( d
> SbxMAXLNG
)
122 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXLNG
;
124 else if( d
< SbxMINLNG
)
126 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINLNG
;
129 nRes
= (sal_Int32
) ImpRound( d
);
134 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
136 nRes
= pVal
->GetLong();
139 SbxBase::SetError( SbxERR_NO_OBJECT
); nRes
= 0;
144 case SbxBYREF
| SbxCHAR
:
145 nRes
= *p
->pChar
; break;
146 case SbxBYREF
| SbxBYTE
:
147 nRes
= *p
->pByte
; break;
148 case SbxBYREF
| SbxINTEGER
:
149 case SbxBYREF
| SbxBOOL
:
150 nRes
= *p
->pInteger
; break;
151 case SbxBYREF
| SbxLONG
:
152 nRes
= *p
->pLong
; break;
154 // from here had to be tested
155 case SbxBYREF
| SbxULONG
:
156 aTmp
.nULong
= *p
->pULong
; goto ref
;
157 case SbxBYREF
| SbxERROR
:
158 case SbxBYREF
| SbxUSHORT
:
159 aTmp
.nUShort
= *p
->pUShort
; goto ref
;
160 case SbxBYREF
| SbxSINGLE
:
161 aTmp
.nSingle
= *p
->pSingle
; goto ref
;
162 case SbxBYREF
| SbxDATE
:
163 case SbxBYREF
| SbxDOUBLE
:
164 aTmp
.nDouble
= *p
->pDouble
; goto ref
;
165 case SbxBYREF
| SbxCURRENCY
:
166 case SbxBYREF
| SbxSALINT64
:
167 aTmp
.nInt64
= *p
->pnInt64
; goto ref
;
168 case SbxBYREF
| SbxSALUINT64
:
169 aTmp
.uInt64
= *p
->puInt64
; goto ref
;
172 aTmp
.eType
= SbxDataType( p
->eType
& 0x0FFF );
173 p
= &aTmp
; goto start
;
176 SbxBase::SetError( SbxERR_CONVERSION
); nRes
= 0;
181 void ImpPutLong( SbxValues
* p
, sal_Int32 n
)
188 // From here had to be tested
190 aTmp
.pChar
= &p
->nChar
; goto direct
;
192 aTmp
.pByte
= &p
->nByte
; goto direct
;
195 aTmp
.pInteger
= &p
->nInteger
; goto direct
;
197 aTmp
.pULong
= &p
->nULong
; goto direct
;
199 aTmp
.puInt64
= &p
->uInt64
; goto direct
;
202 aTmp
.pUShort
= &p
->nUShort
;
204 aTmp
.eType
= SbxDataType( p
->eType
| SbxBYREF
);
205 p
= &aTmp
; goto start
;
207 // from here no longer
211 p
->nSingle
= (float) n
; break;
214 p
->nDouble
= n
; break;
216 p
->nInt64
= n
* CURRENCY_FACTOR
; break;
218 p
->nInt64
= n
; break;
220 case SbxBYREF
| SbxDECIMAL
:
221 ImpCreateDecimal( p
)->setLong( n
);
224 case SbxBYREF
| SbxSTRING
:
228 p
->pOUString
= new ::rtl::OUString
;
229 ImpCvtNum( (double) n
, 0, *p
->pOUString
);
233 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
237 SbxBase::SetError( SbxERR_NO_OBJECT
);
240 case SbxBYREF
| SbxCHAR
:
243 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXCHAR
;
245 else if( n
< SbxMINCHAR
)
247 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMINCHAR
;
249 *p
->pChar
= (sal_Unicode
) n
; break;
250 case SbxBYREF
| SbxBYTE
:
253 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXBYTE
;
257 SbxBase::SetError( SbxERR_OVERFLOW
); n
= 0;
259 *p
->pByte
= (sal_uInt8
) n
; break;
260 case SbxBYREF
| SbxINTEGER
:
261 case SbxBYREF
| SbxBOOL
:
264 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXINT
;
266 else if( n
< SbxMININT
)
268 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMININT
;
270 *p
->pInteger
= (sal_Int16
) n
; break;
271 case SbxBYREF
| SbxERROR
:
272 case SbxBYREF
| SbxUSHORT
:
275 SbxBase::SetError( SbxERR_OVERFLOW
); n
= SbxMAXUINT
;
279 SbxBase::SetError( SbxERR_OVERFLOW
); n
= 0;
281 *p
->pUShort
= (sal_uInt16
) n
; break;
282 case SbxBYREF
| SbxLONG
:
283 *p
->pLong
= n
; break;
284 case SbxBYREF
| SbxULONG
:
287 SbxBase::SetError( SbxERR_OVERFLOW
); n
= 0;
289 *p
->pULong
= (sal_uInt32
) n
; break;
290 case SbxBYREF
| SbxSALINT64
:
291 *p
->pnInt64
= n
; break;
292 case SbxBYREF
| SbxSALUINT64
:
295 SbxBase::SetError( SbxERR_OVERFLOW
); *p
->puInt64
= 0;
300 case SbxBYREF
| SbxSINGLE
:
301 *p
->pSingle
= (float) n
; break;
302 case SbxBYREF
| SbxDATE
:
303 case SbxBYREF
| SbxDOUBLE
:
304 *p
->pDouble
= (double) n
; break;
305 case SbxBYREF
| SbxCURRENCY
:
306 *p
->pnInt64
= (sal_Int64
)n
* (sal_Int64
)CURRENCY_FACTOR
; break;
308 SbxBase::SetError( SbxERR_CONVERSION
);
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */