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"
25 enum SbxBOOL
ImpGetBool( const SbxValues
* p
)
31 SbxBase::SetError( SbxERR_CONVERSION
);
33 nRes
= SbxFALSE
; break;
35 nRes
= p
->nChar
? SbxTRUE
: SbxFALSE
; break;
37 nRes
= p
->nByte
? SbxTRUE
: SbxFALSE
; break;
40 nRes
= p
->nInteger
? SbxTRUE
: SbxFALSE
; break;
43 nRes
= p
->nUShort
? SbxTRUE
: SbxFALSE
; break;
45 nRes
= p
->nLong
? SbxTRUE
: SbxFALSE
; break;
47 nRes
= p
->nULong
? SbxTRUE
: SbxFALSE
; break;
49 nRes
= p
->nSingle
? SbxTRUE
: SbxFALSE
; break;
52 nRes
= p
->nDouble
? SbxTRUE
: SbxFALSE
; break;
54 case SbxBYREF
| SbxDECIMAL
:
58 p
->pDecimal
->getDouble( dVal
);
59 nRes
= dVal
? SbxTRUE
: SbxFALSE
;
64 nRes
= p
->nInt64
? SbxTRUE
: SbxFALSE
; break;
66 nRes
= p
->uInt64
? SbxTRUE
: SbxFALSE
; break;
67 case SbxBYREF
| SbxSTRING
:
73 if( p
->pOUString
->equalsIgnoreAsciiCase( SbxRes( STRING_TRUE
) ) )
75 else if( !p
->pOUString
->equalsIgnoreAsciiCase( SbxRes( STRING_FALSE
) ) )
77 // it can be convertible to a number
82 if( ImpScan( *p
->pOUString
, n
, t
, &nLen
) == SbxERR_OK
)
84 if( nLen
== p
->pOUString
->getLength() )
92 SbxBase::SetError( SbxERR_CONVERSION
);
98 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
100 nRes
= pVal
->GetBool() ? SbxTRUE
: SbxFALSE
;
103 SbxBase::SetError( SbxERR_NO_OBJECT
); nRes
= SbxFALSE
;
108 case SbxBYREF
| SbxCHAR
:
109 nRes
= *p
->pChar
? SbxTRUE
: SbxFALSE
; break;
110 case SbxBYREF
| SbxBYTE
:
111 nRes
= *p
->pByte
? SbxTRUE
: SbxFALSE
; break;
112 case SbxBYREF
| SbxINTEGER
:
113 case SbxBYREF
| SbxBOOL
:
114 nRes
= *p
->pInteger
? SbxTRUE
: SbxFALSE
; break;
115 case SbxBYREF
| SbxLONG
:
116 nRes
= *p
->pLong
? SbxTRUE
: SbxFALSE
; break;
117 case SbxBYREF
| SbxULONG
:
118 nRes
= *p
->pULong
? SbxTRUE
: SbxFALSE
; break;
119 case SbxBYREF
| SbxERROR
:
120 case SbxBYREF
| SbxUSHORT
:
121 nRes
= *p
->pUShort
? SbxTRUE
: SbxFALSE
; break;
122 case SbxBYREF
| SbxSINGLE
:
123 nRes
= ( *p
->pSingle
!= 0 ) ? SbxTRUE
: SbxFALSE
; break;
124 case SbxBYREF
| SbxDATE
:
125 case SbxBYREF
| SbxDOUBLE
:
126 nRes
= ( *p
->pDouble
!= 0 ) ? SbxTRUE
: SbxFALSE
; break;
127 case SbxBYREF
| SbxCURRENCY
:
128 case SbxBYREF
| SbxSALINT64
:
129 nRes
= ( *p
->pnInt64
) ? SbxTRUE
: SbxFALSE
; break;
130 case SbxBYREF
| SbxSALUINT64
:
131 nRes
= ( *p
->puInt64
) ? SbxTRUE
: SbxFALSE
; break;
133 SbxBase::SetError( SbxERR_CONVERSION
); nRes
= SbxFALSE
;
138 void ImpPutBool( SbxValues
* p
, sal_Int16 n
)
145 p
->nChar
= (sal_Unicode
) n
; break;
147 p
->nByte
= (sal_uInt8
) n
; break;
150 p
->nInteger
= n
; break;
154 p
->nULong
= (sal_uInt32
) n
; break;
157 p
->nUShort
= (sal_uInt16
) n
; break;
159 p
->nSingle
= n
; break;
162 p
->nDouble
= n
; break;
165 p
->nInt64
= (sal_Int64
) n
; break;
167 p
->uInt64
= (sal_uInt64
) n
; break;
169 case SbxBYREF
| SbxDECIMAL
:
170 ImpCreateDecimal( p
)->setInt( (sal_Int16
)n
);
173 case SbxBYREF
| SbxSTRING
:
177 p
->pOUString
= new OUString( SbxRes( n
? STRING_TRUE
: STRING_FALSE
) );
179 *p
->pOUString
= SbxRes( n
? STRING_TRUE
: STRING_FALSE
);
184 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
186 pVal
->PutBool( sal_Bool( n
!= 0 ) );
188 SbxBase::SetError( SbxERR_NO_OBJECT
);
191 case SbxBYREF
| SbxCHAR
:
192 *p
->pChar
= (sal_Unicode
) n
; break;
193 case SbxBYREF
| SbxBYTE
:
194 *p
->pByte
= (sal_uInt8
) n
; break;
195 case SbxBYREF
| SbxINTEGER
:
196 case SbxBYREF
| SbxBOOL
:
197 *p
->pInteger
= (sal_Int16
) n
; break;
198 case SbxBYREF
| SbxERROR
:
199 case SbxBYREF
| SbxUSHORT
:
200 *p
->pUShort
= (sal_uInt16
) n
; break;
201 case SbxBYREF
| SbxLONG
:
202 *p
->pLong
= n
; break;
203 case SbxBYREF
| SbxULONG
:
204 *p
->pULong
= (sal_uInt32
) n
; break;
205 case SbxBYREF
| SbxSINGLE
:
206 *p
->pSingle
= n
; break;
207 case SbxBYREF
| SbxDATE
:
208 case SbxBYREF
| SbxDOUBLE
:
209 *p
->pDouble
= n
; break;
210 case SbxBYREF
| SbxCURRENCY
:
211 case SbxBYREF
| SbxSALINT64
:
212 *p
->pnInt64
= (sal_Int64
) n
; break;
213 case SbxBYREF
| SbxSALUINT64
:
214 *p
->puInt64
= (sal_uInt64
) n
; break;
216 SbxBase::SetError( SbxERR_CONVERSION
);
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */