Update ooo320-m1
[ooovba.git] / basic / source / sbx / sbxbool.cxx
blobfc9d4616c1a223cec37b9d309b6a735576557071
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sbxbool.cxx,v $
10 * $Revision: 1.8 $
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"
36 #include "sbxres.hxx"
38 // AB 29.10.99 Unicode
39 #ifndef _USE_NO_NAMESPACE
40 using namespace rtl;
41 #endif
43 enum SbxBOOL ImpGetBool( const SbxValues* p )
45 enum SbxBOOL nRes;
46 switch( +p->eType )
48 case SbxNULL:
49 SbxBase::SetError( SbxERR_CONVERSION );
50 case SbxEMPTY:
51 nRes = SbxFALSE; break;
52 case SbxCHAR:
53 nRes = p->nChar ? SbxTRUE : SbxFALSE; break;
54 case SbxBYTE:
55 nRes = p->nByte ? SbxTRUE : SbxFALSE; break;
56 case SbxINTEGER:
57 case SbxBOOL:
58 nRes = p->nInteger ? SbxTRUE : SbxFALSE; break;
59 case SbxERROR:
60 case SbxUSHORT:
61 nRes = p->nUShort ? SbxTRUE : SbxFALSE; break;
62 case SbxLONG:
63 nRes = p->nLong ? SbxTRUE : SbxFALSE; break;
64 case SbxULONG:
65 nRes = p->nULong ? SbxTRUE : SbxFALSE; break;
66 case SbxSINGLE:
67 nRes = p->nSingle ? SbxTRUE : SbxFALSE; break;
68 case SbxDATE:
69 case SbxDOUBLE:
70 nRes = p->nDouble ? SbxTRUE : SbxFALSE; break;
71 case SbxDECIMAL:
72 case SbxBYREF | SbxDECIMAL:
74 double dVal = 0.0;
75 if( p->pDecimal )
76 p->pDecimal->getDouble( dVal );
77 nRes = dVal ? SbxTRUE : SbxFALSE;
79 break;
80 case SbxSALINT64:
81 nRes = p->nInt64 ? SbxTRUE : SbxFALSE; break;
82 case SbxSALUINT64:
83 nRes = p->uInt64 ? SbxTRUE : SbxFALSE; break;
84 case SbxULONG64:
85 nRes = !!p->nULong64 ? SbxTRUE : SbxFALSE; break;
86 case SbxLONG64:
87 case SbxCURRENCY:
88 nRes = !!p->nLong64 ? SbxTRUE : SbxFALSE; break;
89 case SbxBYREF | SbxSTRING:
90 case SbxSTRING:
91 case SbxLPSTR:
92 nRes = SbxFALSE;
93 if( p->pString )
95 if( p->pString->EqualsIgnoreCaseAscii( SbxRes( STRING_TRUE ) ) )
96 nRes = SbxTRUE;
97 else if( !p->pString->EqualsIgnoreCaseAscii( SbxRes( STRING_FALSE ) ) )
99 // Jetzt kann es noch in eine Zahl konvertierbar sein
100 BOOL bError = TRUE;
101 double n;
102 SbxDataType t;
103 USHORT nLen = 0;
104 String s( *p->pString );
105 if( ImpScan( s, n, t, &nLen ) == SbxERR_OK )
107 if( nLen == s.Len() )
109 bError = FALSE;
110 if( n != 0.0 )
111 nRes = SbxTRUE;
114 if( bError )
115 SbxBase::SetError( SbxERR_CONVERSION );
118 break;
119 case SbxOBJECT:
121 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
122 if( pVal )
123 nRes = pVal->GetBool() ? SbxTRUE : SbxFALSE;
124 else
126 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = SbxFALSE;
128 break;
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;
160 default:
161 SbxBase::SetError( SbxERR_CONVERSION ); nRes = SbxFALSE;
163 return nRes;
166 void ImpPutBool( SbxValues* p, INT16 n )
168 if( n )
169 n = SbxTRUE;
170 switch( +p->eType )
172 case SbxCHAR:
173 p->nChar = (xub_Unicode) n; break;
174 case SbxUINT:
175 p->nByte = (BYTE) n; break;
176 case SbxINTEGER:
177 case SbxBOOL:
178 p->nInteger = n; break;
179 case SbxLONG:
180 p->nLong = n; break;
181 case SbxULONG:
182 p->nULong = (UINT32) n; break;
183 case SbxERROR:
184 case SbxUSHORT:
185 p->nUShort = (UINT16) n; break;
186 case SbxSINGLE:
187 p->nSingle = n; break;
188 case SbxDATE:
189 case SbxDOUBLE:
190 p->nDouble = n; break;
191 case SbxSALINT64:
192 p->nInt64 = n; break;
193 case SbxSALUINT64:
194 p->uInt64 = n; break;
195 case SbxULONG64:
196 p->nULong64.Set( (UINT32)n ); break;
197 case SbxLONG64:
198 case SbxCURRENCY:
199 p->nLong64.Set( (INT32)n ); break;
200 case SbxDECIMAL:
201 case SbxBYREF | SbxDECIMAL:
202 ImpCreateDecimal( p )->setInt( (INT16)n );
203 break;
205 case SbxBYREF | SbxSTRING:
206 case SbxSTRING:
207 case SbxLPSTR:
208 if( !p->pString )
209 p->pString = new XubString;
210 *p->pString = SbxRes( n ? STRING_TRUE : STRING_FALSE );
211 break;
213 case SbxOBJECT:
215 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
216 if( pVal )
217 pVal->PutBool( BOOL( n != 0 ) );
218 else
219 SbxBase::SetError( SbxERR_NO_OBJECT );
220 break;
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;
251 default:
252 SbxBase::SetError( SbxERR_CONVERSION );