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 <vcl/errcode.hxx>
21 #include <basic/sberrors.hxx>
22 #include "sbxconv.hxx"
24 #include <rtlproto.hxx>
26 enum SbxBOOL
ImpGetBool( const SbxValues
* p
)
32 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
);
35 nRes
= SbxFALSE
; break;
37 nRes
= p
->nChar
? SbxTRUE
: SbxFALSE
; break;
39 nRes
= p
->nByte
? SbxTRUE
: SbxFALSE
; break;
42 nRes
= p
->nInteger
? SbxTRUE
: SbxFALSE
; break;
45 nRes
= p
->nUShort
? SbxTRUE
: SbxFALSE
; break;
47 nRes
= p
->nLong
? SbxTRUE
: SbxFALSE
; break;
49 nRes
= p
->nULong
? SbxTRUE
: SbxFALSE
; break;
51 nRes
= p
->nSingle
? SbxTRUE
: SbxFALSE
; break;
54 nRes
= p
->nDouble
? SbxTRUE
: SbxFALSE
; break;
56 case SbxBYREF
| SbxDECIMAL
:
60 p
->pDecimal
->getDouble( dVal
);
61 nRes
= dVal
? SbxTRUE
: SbxFALSE
;
66 nRes
= p
->nInt64
? SbxTRUE
: SbxFALSE
; break;
68 nRes
= p
->uInt64
? SbxTRUE
: SbxFALSE
; break;
69 case SbxBYREF
| SbxSTRING
:
75 if( p
->pOUString
->equalsIgnoreAsciiCase( GetSbxRes( StringId::True
) ) )
77 else if( !p
->pOUString
->equalsIgnoreAsciiCase( GetSbxRes( StringId::False
) ) )
79 // it can be convertible to a number
84 if( ImpScan( *p
->pOUString
, n
, t
, &nLen
, !LibreOffice6FloatingPointMode() ) == ERRCODE_NONE
)
86 if( nLen
== p
->pOUString
->getLength() )
94 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
);
100 SbxValue
* pVal
= dynamic_cast<SbxValue
*>( p
->pObj
);
102 nRes
= pVal
->GetBool() ? SbxTRUE
: SbxFALSE
;
105 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT
); nRes
= SbxFALSE
;
110 case SbxBYREF
| SbxCHAR
:
111 nRes
= *p
->pChar
? SbxTRUE
: SbxFALSE
; break;
112 case SbxBYREF
| SbxBYTE
:
113 nRes
= *p
->pByte
? SbxTRUE
: SbxFALSE
; break;
114 case SbxBYREF
| SbxINTEGER
:
115 case SbxBYREF
| SbxBOOL
:
116 nRes
= *p
->pInteger
? SbxTRUE
: SbxFALSE
; break;
117 case SbxBYREF
| SbxLONG
:
118 nRes
= *p
->pLong
? SbxTRUE
: SbxFALSE
; break;
119 case SbxBYREF
| SbxULONG
:
120 nRes
= *p
->pULong
? SbxTRUE
: SbxFALSE
; break;
121 case SbxBYREF
| SbxERROR
:
122 case SbxBYREF
| SbxUSHORT
:
123 nRes
= *p
->pUShort
? SbxTRUE
: SbxFALSE
; break;
124 case SbxBYREF
| SbxSINGLE
:
125 nRes
= ( *p
->pSingle
!= 0 ) ? SbxTRUE
: SbxFALSE
; break;
126 case SbxBYREF
| SbxDATE
:
127 case SbxBYREF
| SbxDOUBLE
:
128 nRes
= ( *p
->pDouble
!= 0 ) ? SbxTRUE
: SbxFALSE
; break;
129 case SbxBYREF
| SbxCURRENCY
:
130 case SbxBYREF
| SbxSALINT64
:
131 nRes
= ( *p
->pnInt64
) ? SbxTRUE
: SbxFALSE
; break;
132 case SbxBYREF
| SbxSALUINT64
:
133 nRes
= ( *p
->puInt64
) ? SbxTRUE
: SbxFALSE
; break;
135 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
); nRes
= SbxFALSE
;
140 void ImpPutBool( SbxValues
* p
, sal_Int16 n
)
147 p
->nChar
= static_cast<sal_Unicode
>(n
); break;
149 p
->nByte
= static_cast<sal_uInt8
>(n
); break;
152 p
->nInteger
= n
; break;
156 p
->nULong
= static_cast<sal_uInt32
>(n
); break;
159 p
->nUShort
= static_cast<sal_uInt16
>(n
); break;
161 p
->nSingle
= n
; break;
164 p
->nDouble
= n
; break;
167 p
->nInt64
= static_cast<sal_Int64
>(n
); break;
169 p
->uInt64
= static_cast<sal_uInt64
>(n
); break;
171 case SbxBYREF
| SbxDECIMAL
:
172 ImpCreateDecimal( p
)->setInt( n
);
175 case SbxBYREF
| SbxSTRING
:
179 p
->pOUString
= new OUString( GetSbxRes( n
? StringId::True
: StringId::False
) );
181 *p
->pOUString
= GetSbxRes( n
? StringId::True
: StringId::False
);
186 SbxValue
* pVal
= dynamic_cast<SbxValue
*>( p
->pObj
);
188 pVal
->PutBool( n
!= 0 );
190 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT
);
193 case SbxBYREF
| SbxCHAR
:
194 *p
->pChar
= static_cast<sal_Unicode
>(n
); break;
195 case SbxBYREF
| SbxBYTE
:
196 *p
->pByte
= static_cast<sal_uInt8
>(n
); break;
197 case SbxBYREF
| SbxINTEGER
:
198 case SbxBYREF
| SbxBOOL
:
199 *p
->pInteger
= n
; break;
200 case SbxBYREF
| SbxERROR
:
201 case SbxBYREF
| SbxUSHORT
:
202 *p
->pUShort
= static_cast<sal_uInt16
>(n
); break;
203 case SbxBYREF
| SbxLONG
:
204 *p
->pLong
= n
; break;
205 case SbxBYREF
| SbxULONG
:
206 *p
->pULong
= static_cast<sal_uInt32
>(n
); break;
207 case SbxBYREF
| SbxSINGLE
:
208 *p
->pSingle
= n
; break;
209 case SbxBYREF
| SbxDATE
:
210 case SbxBYREF
| SbxDOUBLE
:
211 *p
->pDouble
= n
; break;
212 case SbxBYREF
| SbxCURRENCY
:
213 case SbxBYREF
| SbxSALINT64
:
214 *p
->pnInt64
= static_cast<sal_Int64
>(n
); break;
215 case SbxBYREF
| SbxSALUINT64
:
216 *p
->puInt64
= static_cast<sal_uInt64
>(n
); break;
218 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
);
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */