LibreOffice Module basic (master) 1
sbxbool.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include <basic/sberrors.hxx>
22#include "sbxconv.hxx"
23#include "sbxres.hxx"
24#include <rtlproto.hxx>
25
27{
28 enum SbxBOOL nRes;
29 switch( +p->eType )
30 {
31 case SbxNULL:
33 [[fallthrough]];
34 case SbxEMPTY:
35 nRes = SbxFALSE; break;
36 case SbxCHAR:
37 nRes = p->nChar ? SbxTRUE : SbxFALSE; break;
38 case SbxBYTE:
39 nRes = p->nByte ? SbxTRUE : SbxFALSE; break;
40 case SbxINTEGER:
41 case SbxBOOL:
42 nRes = p->nInteger ? SbxTRUE : SbxFALSE; break;
43 case SbxERROR:
44 case SbxUSHORT:
45 nRes = p->nUShort ? SbxTRUE : SbxFALSE; break;
46 case SbxLONG:
47 nRes = p->nLong ? SbxTRUE : SbxFALSE; break;
48 case SbxULONG:
49 nRes = p->nULong ? SbxTRUE : SbxFALSE; break;
50 case SbxSINGLE:
51 nRes = p->nSingle ? SbxTRUE : SbxFALSE; break;
52 case SbxDATE:
53 case SbxDOUBLE:
54 nRes = p->nDouble ? SbxTRUE : SbxFALSE; break;
55 case SbxDECIMAL:
56 case SbxBYREF | SbxDECIMAL:
57 {
58 double dVal = 0.0;
59 if( p->pDecimal )
60 p->pDecimal->getDouble( dVal );
61 nRes = dVal ? SbxTRUE : SbxFALSE;
62 }
63 break;
64 case SbxSALINT64:
65 case SbxCURRENCY:
66 nRes = p->nInt64 ? SbxTRUE : SbxFALSE; break;
67 case SbxSALUINT64:
68 nRes = p->uInt64 ? SbxTRUE : SbxFALSE; break;
69 case SbxBYREF | SbxSTRING:
70 case SbxSTRING:
71 case SbxLPSTR:
72 nRes = SbxFALSE;
73 if ( p->pOUString )
74 {
75 if( p->pOUString->equalsIgnoreAsciiCase( GetSbxRes( StringId::True ) ) )
76 nRes = SbxTRUE;
77 else if( !p->pOUString->equalsIgnoreAsciiCase( GetSbxRes( StringId::False ) ) )
78 {
79 // it can be convertible to a number
80 bool bError = true;
81 double n;
83 sal_uInt16 nLen = 0;
84 if( ImpScan( *p->pOUString, n, t, &nLen, !LibreOffice6FloatingPointMode() ) == ERRCODE_NONE )
85 {
86 if( nLen == p->pOUString->getLength() )
87 {
88 bError = false;
89 if( n != 0.0 )
90 nRes = SbxTRUE;
91 }
92 }
93 if( bError )
95 }
96 }
97 break;
98 case SbxOBJECT:
99 {
100 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
101 if( pVal )
102 nRes = pVal->GetBool() ? SbxTRUE : SbxFALSE;
103 else
104 {
106 }
107 break;
108 }
109
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;
134 default:
136 }
137 return nRes;
138}
139
140void ImpPutBool( SbxValues* p, sal_Int16 n )
141{
142 if( n )
143 n = SbxTRUE;
144 switch( +p->eType )
145 {
146 case SbxCHAR:
147 p->nChar = static_cast<sal_Unicode>(n); break;
148 case SbxUINT:
149 p->nByte = static_cast<sal_uInt8>(n); break;
150 case SbxINTEGER:
151 case SbxBOOL:
152 p->nInteger = n; break;
153 case SbxLONG:
154 p->nLong = n; break;
155 case SbxULONG:
156 p->nULong = static_cast<sal_uInt32>(n); break;
157 case SbxERROR:
158 case SbxUSHORT:
159 p->nUShort = static_cast<sal_uInt16>(n); break;
160 case SbxSINGLE:
161 p->nSingle = n; break;
162 case SbxDATE:
163 case SbxDOUBLE:
164 p->nDouble = n; break;
165 case SbxCURRENCY:
166 case SbxSALINT64:
167 p->nInt64 = static_cast<sal_Int64>(n); break;
168 case SbxSALUINT64:
169 p->uInt64 = static_cast<sal_uInt64>(n); break;
170 case SbxDECIMAL:
171 case SbxBYREF | SbxDECIMAL:
172 ImpCreateDecimal( p )->setInt( n );
173 break;
174
175 case SbxBYREF | SbxSTRING:
176 case SbxSTRING:
177 case SbxLPSTR:
178 if ( !p->pOUString )
179 p->pOUString = new OUString( GetSbxRes( n ? StringId::True : StringId::False ) );
180 else
181 *p->pOUString = GetSbxRes( n ? StringId::True : StringId::False );
182 break;
183
184 case SbxOBJECT:
185 {
186 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
187 if( pVal )
188 pVal->PutBool( n != 0 );
189 else
191 break;
192 }
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;
217 default:
219 }
220}
221
222/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
static void SetError(ErrCode)
Definition: sbxbase.cxx:116
void setInt(int val)
Definition: sbxdec.cxx:326
bool PutBool(bool)
Definition: sbxvalue.cxx:543
bool GetBool() const
Definition: sbxvar.hxx:153
#define ERRCODE_NONE
void * p
sal_Int64 n
bool LibreOffice6FloatingPointMode()
Definition: methods1.cxx:2946
#define ERRCODE_BASIC_NO_OBJECT
Definition: sberrors.hxx:34
#define ERRCODE_BASIC_CONVERSION
Definition: sberrors.hxx:30
enum SbxBOOL ImpGetBool(const SbxValues *p)
Definition: sbxbool.cxx:26
void ImpPutBool(SbxValues *p, sal_Int16 n)
Definition: sbxbool.cxx:140
ErrCode ImpScan(const OUString &rSrc, double &nVal, SbxDataType &rType, sal_uInt16 *pLen, bool bOnlyIntntl)
Definition: sbxscan.cxx:71
SbxDecimal * ImpCreateDecimal(SbxValues *p)
Definition: sbxdec.cxx:376
SbxBOOL
Definition: sbxdef.hxx:215
@ SbxFALSE
Definition: sbxdef.hxx:215
@ SbxTRUE
Definition: sbxdef.hxx:215
SbxDataType
Definition: sbxdef.hxx:37
@ SbxOBJECT
Definition: sbxdef.hxx:47
@ SbxSALINT64
Definition: sbxdef.hxx:75
@ SbxLONG
Definition: sbxdef.hxx:41
@ SbxSALUINT64
Definition: sbxdef.hxx:76
@ SbxNULL
Definition: sbxdef.hxx:39
@ SbxBYTE
Definition: sbxdef.hxx:55
@ SbxEMPTY
Definition: sbxdef.hxx:38
@ SbxUINT
Definition: sbxdef.hxx:60
@ SbxDECIMAL
Definition: sbxdef.hxx:77
@ SbxULONG
Definition: sbxdef.hxx:57
@ SbxUSHORT
Definition: sbxdef.hxx:56
@ SbxERROR
Definition: sbxdef.hxx:48
@ SbxDATE
Definition: sbxdef.hxx:45
@ SbxCURRENCY
Definition: sbxdef.hxx:44
@ SbxLPSTR
Definition: sbxdef.hxx:68
@ SbxSINGLE
Definition: sbxdef.hxx:42
@ SbxBYREF
Definition: sbxdef.hxx:81
@ SbxCHAR
Definition: sbxdef.hxx:54
@ SbxSTRING
Definition: sbxdef.hxx:46
@ SbxINTEGER
Definition: sbxdef.hxx:40
@ SbxDOUBLE
Definition: sbxdef.hxx:43
OUString GetSbxRes(StringId nId)
Definition: sbxres.cxx:75
unsigned char sal_uInt8
sal_uInt16 sal_Unicode