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 <comphelper/errcode.hxx>
21 #include <basic/sberrors.hxx>
22 #include "sbxconv.hxx"
25 enum SbxBOOL
ImpGetBool( const SbxValues
* p
)
31 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
);
34 nRes
= SbxFALSE
; break;
36 nRes
= p
->nChar
? SbxTRUE
: SbxFALSE
; break;
38 nRes
= p
->nByte
? SbxTRUE
: SbxFALSE
; break;
41 nRes
= p
->nInteger
? SbxTRUE
: SbxFALSE
; break;
44 nRes
= p
->nUShort
? SbxTRUE
: SbxFALSE
; break;
46 nRes
= p
->nLong
? SbxTRUE
: SbxFALSE
; break;
48 nRes
= p
->nULong
? SbxTRUE
: SbxFALSE
; break;
50 nRes
= p
->nSingle
? SbxTRUE
: SbxFALSE
; break;
53 nRes
= p
->nDouble
? SbxTRUE
: SbxFALSE
; break;
55 case SbxBYREF
| SbxDECIMAL
:
59 p
->pDecimal
->getDouble( dVal
);
60 nRes
= dVal
? SbxTRUE
: SbxFALSE
;
65 nRes
= p
->nInt64
? SbxTRUE
: SbxFALSE
; break;
67 nRes
= p
->uInt64
? SbxTRUE
: SbxFALSE
; break;
68 case SbxBYREF
| SbxSTRING
:
74 if( p
->pOUString
->equalsIgnoreAsciiCase( GetSbxRes( StringId::True
) ) )
76 else if( !p
->pOUString
->equalsIgnoreAsciiCase( GetSbxRes( StringId::False
) ) )
78 // it can be convertible to a number
83 if( ImpScan( *p
->pOUString
, n
, t
, &nLen
) == ERRCODE_NONE
)
85 if( nLen
== p
->pOUString
->getLength() )
93 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
);
99 SbxValue
* pVal
= dynamic_cast<SbxValue
*>( p
->pObj
);
101 nRes
= pVal
->GetBool() ? SbxTRUE
: SbxFALSE
;
104 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT
); nRes
= SbxFALSE
;
109 case SbxBYREF
| SbxCHAR
:
110 nRes
= *p
->pChar
? SbxTRUE
: SbxFALSE
; break;
111 case SbxBYREF
| SbxBYTE
:
112 nRes
= *p
->pByte
? SbxTRUE
: SbxFALSE
; break;
113 case SbxBYREF
| SbxINTEGER
:
114 case SbxBYREF
| SbxBOOL
:
115 nRes
= *p
->pInteger
? SbxTRUE
: SbxFALSE
; break;
116 case SbxBYREF
| SbxLONG
:
117 nRes
= *p
->pLong
? SbxTRUE
: SbxFALSE
; break;
118 case SbxBYREF
| SbxULONG
:
119 nRes
= *p
->pULong
? SbxTRUE
: SbxFALSE
; break;
120 case SbxBYREF
| SbxERROR
:
121 case SbxBYREF
| SbxUSHORT
:
122 nRes
= *p
->pUShort
? SbxTRUE
: SbxFALSE
; break;
123 case SbxBYREF
| SbxSINGLE
:
124 nRes
= ( *p
->pSingle
!= 0 ) ? SbxTRUE
: SbxFALSE
; break;
125 case SbxBYREF
| SbxDATE
:
126 case SbxBYREF
| SbxDOUBLE
:
127 nRes
= ( *p
->pDouble
!= 0 ) ? SbxTRUE
: SbxFALSE
; break;
128 case SbxBYREF
| SbxCURRENCY
:
129 case SbxBYREF
| SbxSALINT64
:
130 nRes
= ( *p
->pnInt64
) ? SbxTRUE
: SbxFALSE
; break;
131 case SbxBYREF
| SbxSALUINT64
:
132 nRes
= ( *p
->puInt64
) ? SbxTRUE
: SbxFALSE
; break;
134 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
); nRes
= SbxFALSE
;
139 void ImpPutBool( SbxValues
* p
, sal_Int16 n
)
146 p
->nChar
= static_cast<sal_Unicode
>(n
); break;
148 p
->nByte
= static_cast<sal_uInt8
>(n
); break;
151 p
->nInteger
= n
; break;
155 p
->nULong
= static_cast<sal_uInt32
>(n
); break;
158 p
->nUShort
= static_cast<sal_uInt16
>(n
); break;
160 p
->nSingle
= n
; break;
163 p
->nDouble
= n
; break;
166 p
->nInt64
= static_cast<sal_Int64
>(n
); break;
168 p
->uInt64
= static_cast<sal_uInt64
>(n
); break;
170 case SbxBYREF
| SbxDECIMAL
:
171 ImpCreateDecimal( p
)->setInt( n
);
174 case SbxBYREF
| SbxSTRING
:
178 p
->pOUString
= new OUString( GetSbxRes( n
? StringId::True
: StringId::False
) );
180 *p
->pOUString
= GetSbxRes( n
? StringId::True
: StringId::False
);
185 SbxValue
* pVal
= dynamic_cast<SbxValue
*>( p
->pObj
);
187 pVal
->PutBool( n
!= 0 );
189 SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT
);
192 case SbxBYREF
| SbxCHAR
:
193 *p
->pChar
= static_cast<sal_Unicode
>(n
); break;
194 case SbxBYREF
| SbxBYTE
:
195 *p
->pByte
= static_cast<sal_uInt8
>(n
); break;
196 case SbxBYREF
| SbxINTEGER
:
197 case SbxBYREF
| SbxBOOL
:
198 *p
->pInteger
= n
; break;
199 case SbxBYREF
| SbxERROR
:
200 case SbxBYREF
| SbxUSHORT
:
201 *p
->pUShort
= static_cast<sal_uInt16
>(n
); break;
202 case SbxBYREF
| SbxLONG
:
203 *p
->pLong
= n
; break;
204 case SbxBYREF
| SbxULONG
:
205 *p
->pULong
= static_cast<sal_uInt32
>(n
); break;
206 case SbxBYREF
| SbxSINGLE
:
207 *p
->pSingle
= n
; break;
208 case SbxBYREF
| SbxDATE
:
209 case SbxBYREF
| SbxDOUBLE
:
210 *p
->pDouble
= n
; break;
211 case SbxBYREF
| SbxCURRENCY
:
212 case SbxBYREF
| SbxSALINT64
:
213 *p
->pnInt64
= static_cast<sal_Int64
>(n
); break;
214 case SbxBYREF
| SbxSALUINT64
:
215 *p
->puInt64
= static_cast<sal_uInt64
>(n
); break;
217 SbxBase::SetError( ERRCODE_BASIC_CONVERSION
);
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */