LibreOffice Module basic (master) 1
sbxlng.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
27#include <rtl/math.hxx>
28
29sal_Int32 ImpGetLong( const SbxValues* p )
30{
31 SbxValues aTmp;
32 sal_Int32 nRes;
33start:
34 switch( +p->eType )
35 {
36 case SbxNULL:
38 [[fallthrough]];
39 case SbxEMPTY:
40 nRes = 0; break;
41 case SbxCHAR:
42 nRes = p->nChar; break;
43 case SbxBYTE:
44 nRes = p->nByte; break;
45 case SbxINTEGER:
46 case SbxBOOL:
47 nRes = p->nInteger; break;
48 case SbxERROR:
49 case SbxUSHORT:
50 nRes = p->nUShort; break;
51 case SbxLONG:
52 nRes = p->nLong; break;
53 case SbxULONG:
54 if( p->nULong > SbxMAXLNG )
55 {
57 }
58 else
59 nRes = static_cast<sal_Int32>(p->nULong);
60 break;
61 case SbxSINGLE:
62 nRes = ImpDoubleToLong(p->nSingle);
63 break;
64 case SbxSALINT64:
65 nRes = p->nInt64;
66 break;
67 case SbxSALUINT64:
68 nRes = p->uInt64;
69 break;
70 case SbxCURRENCY:
71 {
72 sal_Int64 tstVal = p->nInt64 / CURRENCY_FACTOR;
73 nRes = static_cast<sal_Int32>(tstVal);
75 if( SbxMAXLNG < tstVal ) nRes = SbxMAXLNG;
76 if( tstVal < SbxMINLNG ) nRes = SbxMINLNG;
77 break;
78 }
79 case SbxDATE:
80 case SbxDOUBLE:
81 case SbxDECIMAL:
82 case SbxBYREF | SbxDECIMAL:
83 {
84 double dVal;
85 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 = ImpDoubleToLong(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 = ImpDoubleToLong(d);
110 }
111 break;
112 case SbxOBJECT:
113 {
114 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
115 if( pVal )
116 nRes = pVal->GetLong();
117 else
118 {
120 }
121 break;
122 }
123
124 case SbxBYREF | SbxCHAR:
125 nRes = *p->pChar; break;
126 case SbxBYREF | SbxBYTE:
127 nRes = *p->pByte; break;
128 case SbxBYREF | SbxINTEGER:
129 case SbxBYREF | SbxBOOL:
130 nRes = *p->pInteger; break;
131 case SbxBYREF | SbxLONG:
132 nRes = *p->pLong; break;
133
134 // from here had to be tested
135 case SbxBYREF | SbxULONG:
136 aTmp.nULong = *p->pULong; goto ref;
137 case SbxBYREF | SbxERROR:
138 case SbxBYREF | SbxUSHORT:
139 aTmp.nUShort = *p->pUShort; 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
151 ref:
152 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
153 p = &aTmp; goto start;
154
155 default:
157 }
158 return nRes;
159}
160
161void ImpPutLong( SbxValues* p, sal_Int32 n )
162{
163 SbxValues aTmp;
164
165start:
166 switch( +p->eType )
167 {
168 // From here had to be tested
169 case SbxCHAR:
170 aTmp.pChar = &p->nChar; goto direct;
171 case SbxBYTE:
172 aTmp.pByte = &p->nByte; goto direct;
173 case SbxINTEGER:
174 case SbxBOOL:
175 aTmp.pInteger = &p->nInteger; goto direct;
176 case SbxULONG:
177 aTmp.pULong = &p->nULong; goto direct;
178 case SbxSALUINT64:
179 aTmp.puInt64 = &p->uInt64; goto direct;
180 case SbxERROR:
181 case SbxUSHORT:
182 aTmp.pUShort = &p->nUShort;
183 direct:
184 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
185 p = &aTmp; goto start;
186
187 // from here no longer
188 case SbxLONG:
189 p->nLong = n; break;
190 case SbxSINGLE:
191 p->nSingle = static_cast<float>(n); break;
192 case SbxDATE:
193 case SbxDOUBLE:
194 p->nDouble = n; break;
195 case SbxCURRENCY:
196 p->nInt64 = n * CURRENCY_FACTOR; break;
197 case SbxSALINT64:
198 p->nInt64 = n; break;
199 case SbxDECIMAL:
200 case SbxBYREF | SbxDECIMAL:
202 break;
203
204 case SbxBYREF | SbxSTRING:
205 case SbxSTRING:
206 case SbxLPSTR:
207 if( !p->pOUString )
208 p->pOUString = new OUString;
209 ImpCvtNum( static_cast<double>(n), 0, *p->pOUString );
210 break;
211 case SbxOBJECT:
212 {
213 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
214 if( pVal )
215 pVal->PutLong( n );
216 else
218 break;
219 }
220 case SbxBYREF | SbxCHAR:
221 if( n > SbxMAXCHAR )
222 {
224 }
225 else if( n < SbxMINCHAR )
226 {
228 }
229 *p->pChar = static_cast<sal_Unicode>(n); break;
230 case SbxBYREF | SbxBYTE:
231 if( n > SbxMAXBYTE )
232 {
234 }
235 else if( n < 0 )
236 {
238 }
239 *p->pByte = static_cast<sal_uInt8>(n); break;
240 case SbxBYREF | SbxINTEGER:
241 case SbxBYREF | SbxBOOL:
242 if( n > SbxMAXINT )
243 {
245 }
246 else if( n < SbxMININT )
247 {
249 }
250 *p->pInteger = static_cast<sal_Int16>(n); break;
251 case SbxBYREF | SbxERROR:
252 case SbxBYREF | SbxUSHORT:
253 if( n > SbxMAXUINT )
254 {
256 }
257 else if( n < 0 )
258 {
260 }
261 *p->pUShort = static_cast<sal_uInt16>(n); break;
262 case SbxBYREF | SbxLONG:
263 *p->pLong = n; break;
264 case SbxBYREF | SbxULONG:
265 if( n < 0 )
266 {
268 }
269 *p->pULong = static_cast<sal_uInt32>(n); break;
270 case SbxBYREF | SbxSALINT64:
271 *p->pnInt64 = n; break;
272 case SbxBYREF | SbxSALUINT64:
273 if( n < 0 )
274 {
276 }
277 else
278 *p->puInt64 = n;
279 break;
280 case SbxBYREF | SbxSINGLE:
281 *p->pSingle = static_cast<float>(n); break;
282 case SbxBYREF | SbxDATE:
283 case SbxBYREF | SbxDOUBLE:
284 *p->pDouble = static_cast<double>(n); break;
285 case SbxBYREF | SbxCURRENCY:
286 *p->pnInt64 = static_cast<sal_Int64>(n) * sal_Int64(CURRENCY_FACTOR); break;
287 default:
289 }
290}
291
292/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
double d
static void SetError(ErrCode)
Definition: sbxbase.cxx:116
void setLong(sal_Int32 val)
Definition: sbxdec.cxx:321
sal_Int32 GetLong() const
Definition: sbxvar.hxx:142
bool PutLong(sal_Int32)
#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
auto ImpDoubleToLong(double f)
Definition: sbxconv.hxx:55
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
constexpr sal_Int32 SbxMINLNG
Definition: sbxdef.hxx:191
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
@ 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 SbxMINCHAR
Definition: sbxdef.hxx:185
constexpr auto CURRENCY_FACTOR
Definition: sbxdef.hxx:197
constexpr auto SbxMAXBYTE
Definition: sbxdef.hxx:186
constexpr auto SbxMININT
Definition: sbxdef.hxx:188
void ImpPutLong(SbxValues *p, sal_Int32 n)
Definition: sbxlng.cxx:161
sal_Int32 ImpGetLong(const SbxValues *p)
Definition: sbxlng.cxx:29
float nSingle
Definition: sbxvar.hxx:55
sal_uInt64 * puInt64
Definition: sbxvar.hxx:69
sal_uInt8 * pByte
Definition: sbxvar.hxx:63
sal_uInt32 * pULong
Definition: sbxvar.hxx:67
sal_uInt16 * pUShort
Definition: sbxvar.hxx:64
sal_Int64 nInt64
Definition: sbxvar.hxx:53
double nDouble
Definition: sbxvar.hxx:56
sal_uInt16 nUShort
Definition: sbxvar.hxx:45
sal_uInt64 uInt64
Definition: sbxvar.hxx:52
sal_Int16 * pInteger
Definition: sbxvar.hxx:66
SbxDataType eType
Definition: sbxvar.hxx:77
sal_uInt32 nULong
Definition: sbxvar.hxx:48
sal_Unicode * pChar
Definition: sbxvar.hxx:65
unsigned char sal_uInt8
sal_uInt16 sal_Unicode