1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sbxbool.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basic.hxx"
33 #include <tools/errcode.hxx>
34 #include <basic/sbx.hxx>
35 #include "sbxconv.hxx"
38 // AB 29.10.99 Unicode
39 #ifndef _USE_NO_NAMESPACE
43 enum SbxBOOL
ImpGetBool( const SbxValues
* p
)
49 SbxBase::SetError( SbxERR_CONVERSION
);
51 nRes
= SbxFALSE
; break;
53 nRes
= p
->nChar
? SbxTRUE
: SbxFALSE
; break;
55 nRes
= p
->nByte
? SbxTRUE
: SbxFALSE
; break;
58 nRes
= p
->nInteger
? SbxTRUE
: SbxFALSE
; break;
61 nRes
= p
->nUShort
? SbxTRUE
: SbxFALSE
; break;
63 nRes
= p
->nLong
? SbxTRUE
: SbxFALSE
; break;
65 nRes
= p
->nULong
? SbxTRUE
: SbxFALSE
; break;
67 nRes
= p
->nSingle
? SbxTRUE
: SbxFALSE
; break;
70 nRes
= p
->nDouble
? SbxTRUE
: SbxFALSE
; break;
72 case SbxBYREF
| SbxDECIMAL
:
76 p
->pDecimal
->getDouble( dVal
);
77 nRes
= dVal
? SbxTRUE
: SbxFALSE
;
81 nRes
= p
->nInt64
? SbxTRUE
: SbxFALSE
; break;
83 nRes
= p
->uInt64
? SbxTRUE
: SbxFALSE
; break;
85 nRes
= !!p
->nULong64
? SbxTRUE
: SbxFALSE
; break;
88 nRes
= !!p
->nLong64
? SbxTRUE
: SbxFALSE
; break;
89 case SbxBYREF
| SbxSTRING
:
95 if( p
->pString
->EqualsIgnoreCaseAscii( SbxRes( STRING_TRUE
) ) )
97 else if( !p
->pString
->EqualsIgnoreCaseAscii( SbxRes( STRING_FALSE
) ) )
99 // Jetzt kann es noch in eine Zahl konvertierbar sein
104 String
s( *p
->pString
);
105 if( ImpScan( s
, n
, t
, &nLen
) == SbxERR_OK
)
107 if( nLen
== s
.Len() )
115 SbxBase::SetError( SbxERR_CONVERSION
);
121 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
123 nRes
= pVal
->GetBool() ? SbxTRUE
: SbxFALSE
;
126 SbxBase::SetError( SbxERR_NO_OBJECT
); nRes
= SbxFALSE
;
131 case SbxBYREF
| SbxCHAR
:
132 nRes
= *p
->pChar
? SbxTRUE
: SbxFALSE
; break;
133 case SbxBYREF
| SbxBYTE
:
134 nRes
= *p
->pByte
? SbxTRUE
: SbxFALSE
; break;
135 case SbxBYREF
| SbxINTEGER
:
136 case SbxBYREF
| SbxBOOL
:
137 nRes
= *p
->pInteger
? SbxTRUE
: SbxFALSE
; break;
138 case SbxBYREF
| SbxLONG
:
139 nRes
= *p
->pLong
? SbxTRUE
: SbxFALSE
; break;
140 case SbxBYREF
| SbxULONG
:
141 nRes
= *p
->pULong
? SbxTRUE
: SbxFALSE
; break;
142 case SbxBYREF
| SbxERROR
:
143 case SbxBYREF
| SbxUSHORT
:
144 nRes
= *p
->pUShort
? SbxTRUE
: SbxFALSE
; break;
145 case SbxBYREF
| SbxSINGLE
:
146 nRes
= ( *p
->pSingle
!= 0 ) ? SbxTRUE
: SbxFALSE
; break;
147 case SbxBYREF
| SbxDATE
:
148 case SbxBYREF
| SbxDOUBLE
:
149 nRes
= ( *p
->pDouble
!= 0 ) ? SbxTRUE
: SbxFALSE
; break;
150 case SbxBYREF
| SbxSALINT64
:
151 nRes
= ( *p
->pnInt64
) ? SbxTRUE
: SbxFALSE
; break;
152 case SbxBYREF
| SbxSALUINT64
:
153 nRes
= ( *p
->puInt64
) ? SbxTRUE
: SbxFALSE
; break;
154 case SbxBYREF
| SbxULONG64
:
155 nRes
= !!*p
->pULong64
? SbxTRUE
: SbxFALSE
; break;
156 case SbxBYREF
| SbxLONG64
:
157 case SbxBYREF
| SbxCURRENCY
:
158 nRes
= !!*p
->pLong64
? SbxTRUE
: SbxFALSE
; break;
161 SbxBase::SetError( SbxERR_CONVERSION
); nRes
= SbxFALSE
;
166 void ImpPutBool( SbxValues
* p
, INT16 n
)
173 p
->nChar
= (xub_Unicode
) n
; break;
175 p
->nByte
= (BYTE
) n
; break;
178 p
->nInteger
= n
; break;
182 p
->nULong
= (UINT32
) n
; break;
185 p
->nUShort
= (UINT16
) n
; break;
187 p
->nSingle
= n
; break;
190 p
->nDouble
= n
; break;
192 p
->nInt64
= n
; break;
194 p
->uInt64
= n
; break;
196 p
->nULong64
.Set( (UINT32
)n
); break;
199 p
->nLong64
.Set( (INT32
)n
); break;
201 case SbxBYREF
| SbxDECIMAL
:
202 ImpCreateDecimal( p
)->setInt( (INT16
)n
);
205 case SbxBYREF
| SbxSTRING
:
209 p
->pString
= new XubString
;
210 *p
->pString
= SbxRes( n
? STRING_TRUE
: STRING_FALSE
);
215 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
217 pVal
->PutBool( BOOL( n
!= 0 ) );
219 SbxBase::SetError( SbxERR_NO_OBJECT
);
222 case SbxBYREF
| SbxCHAR
:
223 *p
->pChar
= (xub_Unicode
) n
; break;
224 case SbxBYREF
| SbxBYTE
:
225 *p
->pByte
= (BYTE
) n
; break;
226 case SbxBYREF
| SbxINTEGER
:
227 case SbxBYREF
| SbxBOOL
:
228 *p
->pInteger
= (INT16
) n
; break;
229 case SbxBYREF
| SbxERROR
:
230 case SbxBYREF
| SbxUSHORT
:
231 *p
->pUShort
= (UINT16
) n
; break;
232 case SbxBYREF
| SbxLONG
:
233 *p
->pLong
= n
; break;
234 case SbxBYREF
| SbxULONG
:
235 *p
->pULong
= (UINT32
) n
; break;
236 case SbxBYREF
| SbxSINGLE
:
237 *p
->pSingle
= n
; break;
238 case SbxBYREF
| SbxDATE
:
239 case SbxBYREF
| SbxDOUBLE
:
240 *p
->pDouble
= n
; break;
241 case SbxBYREF
| SbxSALINT64
:
242 *p
->pnInt64
= n
; break;
243 case SbxBYREF
| SbxSALUINT64
:
244 *p
->puInt64
= n
; break;
245 case SbxBYREF
| SbxULONG64
:
246 p
->pULong64
->Set( (UINT32
)n
); break;
247 case SbxBYREF
| SbxLONG64
:
248 case SbxBYREF
| SbxCURRENCY
:
249 p
->pLong64
->Set( (INT32
)n
); break;
252 SbxBase::SetError( SbxERR_CONVERSION
);