1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_basic.hxx" 26 #include <tools/errcode.hxx> 27 #include <basic/sbx.hxx> 28 #include "sbxconv.hxx" 29 #include "sbxres.hxx" 30 31 // AB 29.10.99 Unicode 32 #ifndef _USE_NO_NAMESPACE 33 using namespace rtl; 34 #endif 35 36 enum SbxBOOL ImpGetBool( const SbxValues* p ) 37 { 38 enum SbxBOOL nRes; 39 switch( +p->eType ) 40 { 41 case SbxNULL: 42 SbxBase::SetError( SbxERR_CONVERSION ); 43 case SbxEMPTY: 44 nRes = SbxFALSE; break; 45 case SbxCHAR: 46 nRes = p->nChar ? SbxTRUE : SbxFALSE; break; 47 case SbxBYTE: 48 nRes = p->nByte ? SbxTRUE : SbxFALSE; break; 49 case SbxINTEGER: 50 case SbxBOOL: 51 nRes = p->nInteger ? SbxTRUE : SbxFALSE; break; 52 case SbxERROR: 53 case SbxUSHORT: 54 nRes = p->nUShort ? SbxTRUE : SbxFALSE; break; 55 case SbxLONG: 56 nRes = p->nLong ? SbxTRUE : SbxFALSE; break; 57 case SbxULONG: 58 nRes = p->nULong ? SbxTRUE : SbxFALSE; break; 59 case SbxSINGLE: 60 nRes = p->nSingle ? SbxTRUE : SbxFALSE; break; 61 case SbxDATE: 62 case SbxDOUBLE: 63 nRes = p->nDouble ? SbxTRUE : SbxFALSE; break; 64 case SbxDECIMAL: 65 case SbxBYREF | SbxDECIMAL: 66 { 67 double dVal = 0.0; 68 if( p->pDecimal ) 69 p->pDecimal->getDouble( dVal ); 70 nRes = dVal ? SbxTRUE : SbxFALSE; 71 } 72 break; 73 case SbxSALINT64: 74 nRes = p->nInt64 ? SbxTRUE : SbxFALSE; break; 75 case SbxSALUINT64: 76 nRes = p->uInt64 ? SbxTRUE : SbxFALSE; break; 77 case SbxULONG64: 78 nRes = !!p->nULong64 ? SbxTRUE : SbxFALSE; break; 79 case SbxLONG64: 80 case SbxCURRENCY: 81 nRes = !!p->nLong64 ? SbxTRUE : SbxFALSE; break; 82 case SbxBYREF | SbxSTRING: 83 case SbxSTRING: 84 case SbxLPSTR: 85 nRes = SbxFALSE; 86 if ( p->pOUString ) 87 { 88 if( p->pOUString->equalsIgnoreAsciiCase( SbxRes( STRING_TRUE ) ) ) 89 nRes = SbxTRUE; 90 else if( !p->pOUString->equalsIgnoreAsciiCase( SbxRes( STRING_FALSE ) ) ) 91 { 92 // Jetzt kann es noch in eine Zahl konvertierbar sein 93 sal_Bool bError = sal_True; 94 double n; 95 SbxDataType t; 96 sal_uInt16 nLen = 0; 97 if( ImpScan( *p->pOUString, n, t, &nLen ) == SbxERR_OK ) 98 { 99 if( nLen == p->pOUString->getLength() ) 100 { 101 bError = sal_False; 102 if( n != 0.0 ) 103 nRes = SbxTRUE; 104 } 105 } 106 if( bError ) 107 SbxBase::SetError( SbxERR_CONVERSION ); 108 } 109 } 110 break; 111 case SbxOBJECT: 112 { 113 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj); 114 if( pVal ) 115 nRes = pVal->GetBool() ? SbxTRUE : SbxFALSE; 116 else 117 { 118 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = SbxFALSE; 119 } 120 break; 121 } 122 123 case SbxBYREF | SbxCHAR: 124 nRes = *p->pChar ? SbxTRUE : SbxFALSE; break; 125 case SbxBYREF | SbxBYTE: 126 nRes = *p->pByte ? SbxTRUE : SbxFALSE; break; 127 case SbxBYREF | SbxINTEGER: 128 case SbxBYREF | SbxBOOL: 129 nRes = *p->pInteger ? SbxTRUE : SbxFALSE; break; 130 case SbxBYREF | SbxLONG: 131 nRes = *p->pLong ? SbxTRUE : SbxFALSE; break; 132 case SbxBYREF | SbxULONG: 133 nRes = *p->pULong ? SbxTRUE : SbxFALSE; break; 134 case SbxBYREF | SbxERROR: 135 case SbxBYREF | SbxUSHORT: 136 nRes = *p->pUShort ? SbxTRUE : SbxFALSE; break; 137 case SbxBYREF | SbxSINGLE: 138 nRes = ( *p->pSingle != 0 ) ? SbxTRUE : SbxFALSE; break; 139 case SbxBYREF | SbxDATE: 140 case SbxBYREF | SbxDOUBLE: 141 nRes = ( *p->pDouble != 0 ) ? SbxTRUE : SbxFALSE; break; 142 case SbxBYREF | SbxSALINT64: 143 nRes = ( *p->pnInt64 ) ? SbxTRUE : SbxFALSE; break; 144 case SbxBYREF | SbxSALUINT64: 145 nRes = ( *p->puInt64 ) ? SbxTRUE : SbxFALSE; break; 146 case SbxBYREF | SbxULONG64: 147 nRes = !!*p->pULong64 ? SbxTRUE : SbxFALSE; break; 148 case SbxBYREF | SbxLONG64: 149 case SbxBYREF | SbxCURRENCY: 150 nRes = !!*p->pLong64 ? SbxTRUE : SbxFALSE; break; 151 152 default: 153 SbxBase::SetError( SbxERR_CONVERSION ); nRes = SbxFALSE; 154 } 155 return nRes; 156 } 157 158 void ImpPutBool( SbxValues* p, sal_Int16 n ) 159 { 160 if( n ) 161 n = SbxTRUE; 162 switch( +p->eType ) 163 { 164 case SbxCHAR: 165 p->nChar = (xub_Unicode) n; break; 166 case SbxUINT: 167 p->nByte = (sal_uInt8) n; break; 168 case SbxINTEGER: 169 case SbxBOOL: 170 p->nInteger = n; break; 171 case SbxLONG: 172 p->nLong = n; break; 173 case SbxULONG: 174 p->nULong = (sal_uInt32) n; break; 175 case SbxERROR: 176 case SbxUSHORT: 177 p->nUShort = (sal_uInt16) n; break; 178 case SbxSINGLE: 179 p->nSingle = n; break; 180 case SbxDATE: 181 case SbxDOUBLE: 182 p->nDouble = n; break; 183 case SbxSALINT64: 184 p->nInt64 = n; break; 185 case SbxSALUINT64: 186 p->uInt64 = n; break; 187 case SbxULONG64: 188 p->nULong64.Set( (sal_uInt32)n ); break; 189 case SbxLONG64: 190 case SbxCURRENCY: 191 p->nLong64.Set( (sal_Int32)n ); break; 192 case SbxDECIMAL: 193 case SbxBYREF | SbxDECIMAL: 194 ImpCreateDecimal( p )->setInt( (sal_Int16)n ); 195 break; 196 197 case SbxBYREF | SbxSTRING: 198 case SbxSTRING: 199 case SbxLPSTR: 200 if ( !p->pOUString ) 201 p->pOUString = new ::rtl::OUString( SbxRes( n ? STRING_TRUE : STRING_FALSE ) ); 202 else 203 *p->pOUString = SbxRes( n ? STRING_TRUE : STRING_FALSE ); 204 break; 205 206 case SbxOBJECT: 207 { 208 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj); 209 if( pVal ) 210 pVal->PutBool( sal_Bool( n != 0 ) ); 211 else 212 SbxBase::SetError( SbxERR_NO_OBJECT ); 213 break; 214 } 215 case SbxBYREF | SbxCHAR: 216 *p->pChar = (xub_Unicode) n; break; 217 case SbxBYREF | SbxBYTE: 218 *p->pByte = (sal_uInt8) n; break; 219 case SbxBYREF | SbxINTEGER: 220 case SbxBYREF | SbxBOOL: 221 *p->pInteger = (sal_Int16) n; break; 222 case SbxBYREF | SbxERROR: 223 case SbxBYREF | SbxUSHORT: 224 *p->pUShort = (sal_uInt16) n; break; 225 case SbxBYREF | SbxLONG: 226 *p->pLong = n; break; 227 case SbxBYREF | SbxULONG: 228 *p->pULong = (sal_uInt32) n; break; 229 case SbxBYREF | SbxSINGLE: 230 *p->pSingle = n; break; 231 case SbxBYREF | SbxDATE: 232 case SbxBYREF | SbxDOUBLE: 233 *p->pDouble = n; break; 234 case SbxBYREF | SbxSALINT64: 235 *p->pnInt64 = n; break; 236 case SbxBYREF | SbxSALUINT64: 237 *p->puInt64 = n; break; 238 case SbxBYREF | SbxULONG64: 239 p->pULong64->Set( (sal_uInt32)n ); break; 240 case SbxBYREF | SbxLONG64: 241 case SbxBYREF | SbxCURRENCY: 242 p->pLong64->Set( (sal_Int32)n ); break; 243 244 default: 245 SbxBase::SetError( SbxERR_CONVERSION ); 246 } 247 } 248 249