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_Unicode
ImpGetChar( const SbxValues
* p
)
32 SbxBase::SetError( SbxERR_CONVERSION
);
36 nRes
= p
->nChar
; break;
38 nRes
= (sal_Unicode
) p
->nByte
;
42 if( p
->nInteger
< SbxMINCHAR
)
44 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINCHAR
;
47 nRes
= (sal_Unicode
) p
->nInteger
;
51 nRes
= (sal_Unicode
) p
->nUShort
;
54 if( p
->nLong
> SbxMAXCHAR
)
56 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXCHAR
;
58 else if( p
->nLong
< SbxMINCHAR
)
60 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINCHAR
;
63 nRes
= (sal_Unicode
) p
->nLong
;
66 if( p
->nULong
> SbxMAXCHAR
)
68 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXCHAR
;
71 nRes
= (sal_Unicode
) p
->nULong
;
76 sal_Int64 val
= p
->nInt64
;
78 if ( p
->eType
== SbxCURRENCY
)
79 val
= val
/ CURRENCY_FACTOR
;
81 if( val
> SbxMAXCHAR
)
83 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXCHAR
;
85 else if( p
->nInt64
< SbxMINCHAR
)
87 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINCHAR
;
90 nRes
= (sal_Unicode
) val
;
94 if( p
->uInt64
> SbxMAXCHAR
)
96 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXCHAR
;
99 nRes
= (sal_Unicode
) p
->uInt64
;
102 if( p
->nSingle
> SbxMAXCHAR
)
104 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXCHAR
;
106 else if( p
->nSingle
< SbxMINCHAR
)
108 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINCHAR
;
111 nRes
= (sal_Unicode
) ImpRound( p
->nSingle
);
116 case SbxBYREF
| SbxDECIMAL
:
119 if( p
->eType
== SbxDECIMAL
)
123 p
->pDecimal
->getDouble( dVal
);
128 if( dVal
> SbxMAXCHAR
)
130 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXCHAR
;
132 else if( dVal
< SbxMINCHAR
)
134 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINCHAR
;
137 nRes
= (sal_uInt8
) ImpRound( dVal
);
140 case SbxBYREF
| SbxSTRING
:
147 if( ImpScan( *p
->pOUString
, d
, t
, NULL
) != SbxERR_OK
)
149 else if( d
> SbxMAXCHAR
)
151 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXCHAR
;
153 else if( d
< SbxMINCHAR
)
155 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINCHAR
;
158 nRes
= (sal_Unicode
) ImpRound( d
);
163 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
165 nRes
= pVal
->GetChar();
168 SbxBase::SetError( SbxERR_NO_OBJECT
); nRes
= 0;
173 case SbxBYREF
| SbxCHAR
:
174 nRes
= *p
->pChar
; break;
175 // from here on will be tested
176 case SbxBYREF
| SbxBYTE
:
177 aTmp
.nByte
= *p
->pByte
; goto ref
;
178 case SbxBYREF
| SbxINTEGER
:
179 case SbxBYREF
| SbxBOOL
:
180 aTmp
.nInteger
= *p
->pInteger
; goto ref
;
181 case SbxBYREF
| SbxLONG
:
182 aTmp
.nLong
= *p
->pLong
; goto ref
;
183 case SbxBYREF
| SbxULONG
:
184 aTmp
.nULong
= *p
->pULong
; goto ref
;
185 case SbxBYREF
| SbxERROR
:
186 case SbxBYREF
| SbxUSHORT
:
187 aTmp
.nUShort
= *p
->pUShort
; goto ref
;
188 case SbxBYREF
| SbxSINGLE
:
189 aTmp
.nSingle
= *p
->pSingle
; goto ref
;
190 case SbxBYREF
| SbxDATE
:
191 case SbxBYREF
| SbxDOUBLE
:
192 aTmp
.nDouble
= *p
->pDouble
; goto ref
;
193 case SbxBYREF
| SbxCURRENCY
:
194 case SbxBYREF
| SbxSALINT64
:
195 aTmp
.nInt64
= *p
->pnInt64
; goto ref
;
196 case SbxBYREF
| SbxSALUINT64
:
197 aTmp
.uInt64
= *p
->puInt64
; goto ref
;
199 aTmp
.eType
= SbxDataType( p
->eType
& 0x0FFF );
200 p
= &aTmp
; goto start
;
203 SbxBase::SetError( SbxERR_CONVERSION
); nRes
= 0;
208 void ImpPutChar( SbxValues
* p
, sal_Unicode n
)
218 p
->nInteger
= n
; break;
222 p
->nSingle
= n
; break;
225 p
->nDouble
= n
; break;
227 p
->nInt64
= n
* CURRENCY_FACTOR
; break;
229 p
->nInt64
= n
; break;
231 p
->uInt64
= n
; break;
232 case SbxBYREF
| SbxDECIMAL
:
233 ImpCreateDecimal( p
)->setChar( n
);
236 // from here on will be tested
238 aTmp
.pByte
= &p
->nByte
; goto direct
;
240 aTmp
.pULong
= &p
->nULong
; goto direct
;
243 aTmp
.pUShort
= &p
->nUShort
; goto direct
;
245 aTmp
.eType
= SbxDataType( p
->eType
| SbxBYREF
);
246 p
= &aTmp
; goto start
;
248 case SbxBYREF
| SbxSTRING
:
252 p
->pOUString
= new OUString( n
);
254 *p
->pOUString
= OUString( n
);
258 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
262 SbxBase::SetError( SbxERR_NO_OBJECT
);
265 case SbxBYREF
| SbxCHAR
:
266 *p
->pChar
= n
; break;
267 case SbxBYREF
| SbxBYTE
:
268 *p
->pByte
= (sal_uInt8
) n
; break;
269 case SbxBYREF
| SbxINTEGER
:
270 case SbxBYREF
| SbxBOOL
:
271 *p
->pInteger
= n
; break;
272 case SbxBYREF
| SbxERROR
:
273 case SbxBYREF
| SbxUSHORT
:
274 *p
->pUShort
= (sal_uInt16
) n
; break;
275 case SbxBYREF
| SbxLONG
:
276 *p
->pLong
= (sal_Int32
) n
; break;
277 case SbxBYREF
| SbxULONG
:
278 *p
->pULong
= (sal_uInt32
) n
; break;
279 case SbxBYREF
| SbxSINGLE
:
280 *p
->pSingle
= (float) n
; break;
281 case SbxBYREF
| SbxDATE
:
282 case SbxBYREF
| SbxDOUBLE
:
283 *p
->pDouble
= (double) n
; break;
284 case SbxBYREF
| SbxCURRENCY
:
285 p
->nInt64
= n
* CURRENCY_FACTOR
; break;
286 case SbxBYREF
| SbxSALINT64
:
287 *p
->pnInt64
= n
; break;
288 case SbxBYREF
| SbxSALUINT64
:
289 *p
->puInt64
= n
; break;
292 SbxBase::SetError( SbxERR_CONVERSION
);
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */