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 <sal/config.h>
22 #include <comphelper/errcode.hxx>
23 #include <basic/sberrors.hxx>
24 #include "sbxconv.hxx"
26 sal_uInt32
ImpGetULong( const SbxValues
* p
)
34 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
);
42 nRes
= p
->nByte
; break;
47 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= 0;
59 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); nRes
= 0;
65 nRes
= p
->nULong
; break;
67 nRes
= ImpDoubleToULong(p
->nSingle
);
75 case SbxBYREF
| SbxDECIMAL
:
78 if( p
->eType
== SbxCURRENCY
)
79 dVal
= ImpCurrencyToDouble( p
->nInt64
);
80 else if( p
->eType
== SbxSALINT64
)
81 dVal
= static_cast< double >(p
->nInt64
);
82 else if( p
->eType
== SbxSALUINT64
)
83 dVal
= ImpSalUInt64ToDouble( p
->uInt64
);
84 else if( p
->eType
== SbxDECIMAL
)
88 p
->pDecimal
->getDouble( dVal
);
93 nRes
= ImpDoubleToULong(dVal
);
96 case SbxBYREF
| SbxSTRING
:
105 if( ImpScan( *p
->pOUString
, d
, t
, nullptr ) != ERRCODE_NONE
)
108 nRes
= ImpDoubleToULong(d
);
113 SbxValue
* pVal
= dynamic_cast<SbxValue
*>( p
->pObj
);
115 nRes
= pVal
->GetULong();
118 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT
); nRes
= 0;
123 case SbxBYREF
| SbxBYTE
:
124 nRes
= *p
->pByte
; break;
125 case SbxBYREF
| SbxERROR
:
126 case SbxBYREF
| SbxUSHORT
:
127 nRes
= *p
->pUShort
; break;
128 case SbxBYREF
| SbxULONG
:
129 nRes
= *p
->pULong
; break;
131 // from here on tests
132 case SbxBYREF
| SbxCHAR
:
133 aTmp
.nChar
= *p
->pChar
; goto ref
;
134 case SbxBYREF
| SbxINTEGER
:
135 case SbxBYREF
| SbxBOOL
:
136 aTmp
.nInteger
= *p
->pInteger
; goto ref
;
137 case SbxBYREF
| SbxLONG
:
138 aTmp
.nLong
= *p
->pLong
; goto ref
;
139 case SbxBYREF
| SbxSINGLE
:
140 aTmp
.nSingle
= *p
->pSingle
; goto ref
;
141 case SbxBYREF
| SbxDATE
:
142 case SbxBYREF
| SbxDOUBLE
:
143 aTmp
.nDouble
= *p
->pDouble
; goto ref
;
144 case SbxBYREF
| SbxCURRENCY
:
145 case SbxBYREF
| SbxSALINT64
:
146 aTmp
.nInt64
= *p
->pnInt64
; goto ref
;
147 case SbxBYREF
| SbxSALUINT64
:
148 aTmp
.uInt64
= *p
->puInt64
; goto ref
;
150 aTmp
.eType
= SbxDataType( p
->eType
& 0x0FFF );
151 p
= &aTmp
; goto start
;
154 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
); nRes
= 0;
159 void ImpPutULong( SbxValues
* p
, sal_uInt32 n
)
166 p
->nULong
= n
; break;
168 p
->nSingle
= static_cast<float>(n
); break;
171 p
->nDouble
= n
; break;
174 aTmp
.pnInt64
= &p
->nInt64
; goto direct
;
176 p
->uInt64
= n
; break;
178 case SbxBYREF
| SbxDECIMAL
:
179 ImpCreateDecimal( p
)->setULong( n
);
182 // from here on tests
184 aTmp
.pChar
= &p
->nChar
; goto direct
;
186 aTmp
.pByte
= &p
->nByte
; goto direct
;
189 aTmp
.pInteger
= &p
->nInteger
; goto direct
;
191 aTmp
.pLong
= &p
->nLong
; goto direct
;
194 aTmp
.pUShort
= &p
->nUShort
; goto direct
;
196 aTmp
.eType
= SbxDataType( p
->eType
| SbxBYREF
);
197 p
= &aTmp
; goto start
;
199 case SbxBYREF
| SbxSTRING
:
203 p
->pOUString
= new OUString
;
204 ImpCvtNum( static_cast<double>(n
), 0, *p
->pOUString
);
208 SbxValue
* pVal
= dynamic_cast<SbxValue
*>( p
->pObj
);
212 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT
);
215 case SbxBYREF
| SbxCHAR
:
218 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXCHAR
;
220 *p
->pChar
= static_cast<sal_Unicode
>(n
); break;
221 case SbxBYREF
| SbxBYTE
:
224 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXBYTE
;
226 *p
->pByte
= static_cast<sal_uInt8
>(n
); break;
227 case SbxBYREF
| SbxINTEGER
:
228 case SbxBYREF
| SbxBOOL
:
231 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXINT
;
233 *p
->pInteger
= static_cast<sal_Int16
>(n
); break;
234 case SbxBYREF
| SbxERROR
:
235 case SbxBYREF
| SbxUSHORT
:
238 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXUINT
;
240 *p
->pUShort
= static_cast<sal_uInt16
>(n
); break;
241 case SbxBYREF
| SbxLONG
:
244 SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW
); n
= SbxMAXLNG
;
246 *p
->pLong
= static_cast<sal_Int32
>(n
); break;
247 case SbxBYREF
| SbxULONG
:
248 *p
->pULong
= n
; break;
249 case SbxBYREF
| SbxSINGLE
:
250 *p
->pSingle
= static_cast<float>(n
); break;
251 case SbxBYREF
| SbxDATE
:
252 case SbxBYREF
| SbxDOUBLE
:
253 *p
->pDouble
= n
; break;
254 case SbxBYREF
| SbxCURRENCY
:
255 *p
->pnInt64
= CurFrom(n
); break;
256 case SbxBYREF
| SbxSALINT64
:
257 *p
->pnInt64
= n
; break;
258 case SbxBYREF
| SbxSALUINT64
:
259 *p
->puInt64
= n
; break;
262 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
);
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */