LibreOffice Module basic (master) 1
sbxulng.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
20#include <sal/config.h>
21
23#include <basic/sberrors.hxx>
24#include "sbxconv.hxx"
25#include <rtlproto.hxx>
26
27sal_uInt32 ImpGetULong( const SbxValues* p )
28{
29 SbxValues aTmp;
30 sal_uInt32 nRes;
31start:
32 switch( +p->eType )
33 {
34 case SbxNULL:
36 [[fallthrough]];
37 case SbxEMPTY:
38 nRes = 0; break;
39 case SbxCHAR:
40 nRes = p->nChar;
41 break;
42 case SbxBYTE:
43 nRes = p->nByte; break;
44 case SbxINTEGER:
45 case SbxBOOL:
46 if( p->nInteger < 0 )
47 {
49 }
50 else
51 nRes = p->nInteger;
52 break;
53 case SbxERROR:
54 case SbxUSHORT:
55 nRes = p->nUShort;
56 break;
57 case SbxLONG:
58 if( p->nLong < 0 )
59 {
61 }
62 else
63 nRes = p->nLong;
64 break;
65 case SbxULONG:
66 nRes = p->nULong; break;
67 case SbxSINGLE:
68 nRes = ImpDoubleToULong(p->nSingle);
69 break;
70 case SbxDATE:
71 case SbxDOUBLE:
72 case SbxSALINT64:
73 case SbxSALUINT64:
74 case SbxCURRENCY:
75 case SbxDECIMAL:
76 case SbxBYREF | SbxDECIMAL:
77 {
78 double dVal;
79 if( p->eType == SbxCURRENCY )
80 dVal = ImpCurrencyToDouble( p->nInt64 );
81 else if( p->eType == SbxSALINT64 )
82 dVal = static_cast< double >(p->nInt64);
83 else if( p->eType == SbxSALUINT64 )
84 dVal = ImpSalUInt64ToDouble( p->uInt64 );
85 else if( p->eType == SbxDECIMAL )
86 {
87 dVal = 0.0;
88 if( p->pDecimal )
89 p->pDecimal->getDouble( dVal );
90 }
91 else
92 dVal = p->nDouble;
93
94 nRes = ImpDoubleToULong(dVal);
95 break;
96 }
97 case SbxBYREF | SbxSTRING:
98 case SbxSTRING:
99 case SbxLPSTR:
100 if( !p->pOUString )
101 nRes = 0;
102 else
103 {
104 double d;
106 if( ImpScan( *p->pOUString, d, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE )
107 nRes = 0;
108 else
109 nRes = ImpDoubleToULong(d);
110 }
111 break;
112 case SbxOBJECT:
113 {
114 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
115 if( pVal )
116 nRes = pVal->GetULong();
117 else
118 {
120 }
121 break;
122 }
123
124 case SbxBYREF | SbxBYTE:
125 nRes = *p->pByte; break;
126 case SbxBYREF | SbxERROR:
127 case SbxBYREF | SbxUSHORT:
128 nRes = *p->pUShort; break;
129 case SbxBYREF | SbxULONG:
130 nRes = *p->pULong; break;
131
132 // from here on tests
133 case SbxBYREF | SbxCHAR:
134 aTmp.nChar = *p->pChar; goto ref;
135 case SbxBYREF | SbxINTEGER:
136 case SbxBYREF | SbxBOOL:
137 aTmp.nInteger = *p->pInteger; goto ref;
138 case SbxBYREF | SbxLONG:
139 aTmp.nLong = *p->pLong; goto ref;
140 case SbxBYREF | SbxSINGLE:
141 aTmp.nSingle = *p->pSingle; goto ref;
142 case SbxBYREF | SbxDATE:
143 case SbxBYREF | SbxDOUBLE:
144 aTmp.nDouble = *p->pDouble; goto ref;
145 case SbxBYREF | SbxCURRENCY:
146 case SbxBYREF | SbxSALINT64:
147 aTmp.nInt64 = *p->pnInt64; goto ref;
148 case SbxBYREF | SbxSALUINT64:
149 aTmp.uInt64 = *p->puInt64; goto ref;
150 ref:
151 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
152 p = &aTmp; goto start;
153
154 default:
156 }
157 return nRes;
158}
159
160void ImpPutULong( SbxValues* p, sal_uInt32 n )
161{
162 SbxValues aTmp;
163start:
164 switch( +p->eType )
165 {
166 case SbxULONG:
167 p->nULong = n; break;
168 case SbxSINGLE:
169 p->nSingle = static_cast<float>(n); break;
170 case SbxDATE:
171 case SbxDOUBLE:
172 p->nDouble = n; break;
173 case SbxCURRENCY:
174 case SbxSALINT64:
175 aTmp.pnInt64 = &p->nInt64; goto direct;
176 case SbxSALUINT64:
177 p->uInt64 = n; break;
178 case SbxDECIMAL:
179 case SbxBYREF | SbxDECIMAL:
181 break;
182
183 // from here on tests
184 case SbxCHAR:
185 aTmp.pChar = &p->nChar; goto direct;
186 case SbxUINT:
187 aTmp.pByte = &p->nByte; goto direct;
188 case SbxINTEGER:
189 case SbxBOOL:
190 aTmp.pInteger = &p->nInteger; goto direct;
191 case SbxLONG:
192 aTmp.pLong = &p->nLong; goto direct;
193 case SbxERROR:
194 case SbxUSHORT:
195 aTmp.pUShort = &p->nUShort; goto direct;
196 direct:
197 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
198 p = &aTmp; goto start;
199
200 case SbxBYREF | SbxSTRING:
201 case SbxSTRING:
202 case SbxLPSTR:
203 if( !p->pOUString )
204 p->pOUString = new OUString;
205 ImpCvtNum( static_cast<double>(n), 0, *p->pOUString );
206 break;
207 case SbxOBJECT:
208 {
209 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
210 if( pVal )
211 pVal->PutULong( n );
212 else
214 break;
215 }
216 case SbxBYREF | SbxCHAR:
217 if( n > SbxMAXCHAR )
218 {
220 }
221 *p->pChar = static_cast<sal_Unicode>(n); break;
222 case SbxBYREF | SbxBYTE:
223 if( n > SbxMAXBYTE )
224 {
226 }
227 *p->pByte = static_cast<sal_uInt8>(n); break;
228 case SbxBYREF | SbxINTEGER:
229 case SbxBYREF | SbxBOOL:
230 if( n > SbxMAXINT )
231 {
233 }
234 *p->pInteger = static_cast<sal_Int16>(n); break;
235 case SbxBYREF | SbxERROR:
236 case SbxBYREF | SbxUSHORT:
237 if( n > SbxMAXUINT )
238 {
240 }
241 *p->pUShort = static_cast<sal_uInt16>(n); break;
242 case SbxBYREF | SbxLONG:
243 if( n > SbxMAXLNG )
244 {
246 }
247 *p->pLong = static_cast<sal_Int32>(n); break;
248 case SbxBYREF | SbxULONG:
249 *p->pULong = n; break;
250 case SbxBYREF | SbxSINGLE:
251 *p->pSingle = static_cast<float>(n); break;
252 case SbxBYREF | SbxDATE:
253 case SbxBYREF | SbxDOUBLE:
254 *p->pDouble = n; break;
255 case SbxBYREF | SbxCURRENCY:
256 *p->pnInt64 = n * CURRENCY_FACTOR; break;
257 case SbxBYREF | SbxSALINT64:
258 *p->pnInt64 = n; break;
259 case SbxBYREF | SbxSALUINT64:
260 *p->puInt64 = n; break;
261
262 default:
264 }
265}
266
267/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
double d
static void SetError(ErrCode)
Definition: sbxbase.cxx:116
void setULong(sal_uInt32 val)
Definition: sbxdec.cxx:323
sal_uInt32 GetULong() const
Definition: sbxvar.hxx:160
bool PutULong(sal_uInt32)
#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_MATH_OVERFLOW
Definition: sberrors.hxx:27
#define ERRCODE_BASIC_CONVERSION
Definition: sberrors.hxx:30
double ImpCurrencyToDouble(const sal_Int64 r)
Definition: sbxconv.hxx:113
auto ImpDoubleToULong(double f)
Definition: sbxconv.hxx:54
double ImpSalUInt64ToDouble(sal_uInt64 n)
Definition: sbxint.cxx:316
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
void ImpCvtNum(double nNum, short nPrec, OUString &rRes, bool bCoreString=false)
Definition: sbxscan.cxx:290
constexpr auto SbxMAXLNG
Definition: sbxdef.hxx:190
SbxBOOL
Definition: sbxdef.hxx:215
constexpr auto SbxMAXCHAR
Definition: sbxdef.hxx:184
constexpr auto SbxMAXINT
Definition: sbxdef.hxx:187
constexpr sal_uInt16 SbxMAXUINT
Definition: sbxdef.hxx:189
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
constexpr auto CURRENCY_FACTOR
Definition: sbxdef.hxx:197
constexpr auto SbxMAXBYTE
Definition: sbxdef.hxx:186
sal_uInt32 ImpGetULong(const SbxValues *p)
Definition: sbxulng.cxx:27
void ImpPutULong(SbxValues *p, sal_uInt32 n)
Definition: sbxulng.cxx:160
float nSingle
Definition: sbxvar.hxx:55
sal_Int32 nLong
Definition: sbxvar.hxx:49
sal_uInt8 * pByte
Definition: sbxvar.hxx:63
sal_uInt16 * pUShort
Definition: sbxvar.hxx:64
sal_Int16 nInteger
Definition: sbxvar.hxx:47
sal_Unicode nChar
Definition: sbxvar.hxx:46
sal_Int64 nInt64
Definition: sbxvar.hxx:53
double nDouble
Definition: sbxvar.hxx:56
sal_uInt64 uInt64
Definition: sbxvar.hxx:52
sal_Int16 * pInteger
Definition: sbxvar.hxx:66
sal_Int32 * pLong
Definition: sbxvar.hxx:68
SbxDataType eType
Definition: sbxvar.hxx:77
sal_Int64 * pnInt64
Definition: sbxvar.hxx:70
sal_Unicode * pChar
Definition: sbxvar.hxx:65
unsigned char sal_uInt8
sal_uInt16 sal_Unicode