LibreOffice Module basic (master) 1
sbxuint.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_uInt16 ImpGetUShort( const SbxValues* p )
28{
29 SbxValues aTmp;
30 sal_uInt16 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 > SbxMAXUINT )
59 {
61 }
62 else if( p->nLong < 0 )
63 {
65 }
66 else
67 nRes = static_cast<sal_uInt16>(p->nLong);
68 break;
69 case SbxULONG:
70 if( p->nULong > SbxMAXUINT )
71 {
73 }
74 else
75 nRes = static_cast<sal_uInt16>(p->nULong);
76 break;
77 case SbxCURRENCY:
78 if( p->nInt64 / CURRENCY_FACTOR > SbxMAXUINT )
79 {
81 }
82 else if( p->nInt64 < 0 )
83 {
85 }
86 else
87 nRes = static_cast<sal_uInt16>(p->nInt64 / CURRENCY_FACTOR);
88 break;
89 case SbxSALINT64:
90 if( p->nInt64 > SbxMAXUINT )
91 {
93 }
94 else if( p->nInt64 < 0 )
95 {
97 }
98 else
99 nRes = static_cast<sal_uInt16>(p->nInt64);
100 break;
101 case SbxSALUINT64:
102 if( p->uInt64 > SbxMAXUINT )
103 {
105 }
106 else
107 nRes = static_cast<sal_uInt16>(p->uInt64);
108 break;
109 case SbxSINGLE:
110 nRes = ImpDoubleToUShort(p->nSingle);
111 break;
112 case SbxDATE:
113 case SbxDOUBLE:
114 case SbxDECIMAL:
115 case SbxBYREF | SbxDECIMAL:
116 {
117 double dVal;
118 if( p->eType == SbxDECIMAL )
119 {
120 dVal = 0.0;
121 if( p->pDecimal )
122 p->pDecimal->getDouble( dVal );
123 }
124 else
125 dVal = p->nDouble;
126
127 nRes = ImpDoubleToUShort(dVal);
128 break;
129 }
130 case SbxBYREF | SbxSTRING:
131 case SbxSTRING:
132 case SbxLPSTR:
133 if( !p->pOUString )
134 nRes = 0;
135 else
136 {
137 double d;
139 if( ImpScan( *p->pOUString, d, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE )
140 nRes = 0;
141 else
142 nRes = ImpDoubleToUShort(d);
143 }
144 break;
145 case SbxOBJECT:
146 {
147 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
148 if( pVal )
149 nRes = pVal->GetUShort();
150 else
151 {
153 }
154 break;
155 }
156
157 case SbxBYREF | SbxBYTE:
158 nRes = *p->pByte; break;
159 case SbxBYREF | SbxERROR:
160 case SbxBYREF | SbxUSHORT:
161 nRes = *p->pUShort; break;
162
163 // from here on will be tested
164 case SbxBYREF | SbxCHAR:
165 aTmp.nChar = *p->pChar; goto ref;
166 case SbxBYREF | SbxINTEGER:
167 case SbxBYREF | SbxBOOL:
168 aTmp.nInteger = *p->pInteger; goto ref;
169 case SbxBYREF | SbxLONG:
170 aTmp.nLong = *p->pLong; goto ref;
171 case SbxBYREF | SbxULONG:
172 aTmp.nULong = *p->pULong; goto ref;
173 case SbxBYREF | SbxSINGLE:
174 aTmp.nSingle = *p->pSingle; goto ref;
175 case SbxBYREF | SbxDATE:
176 case SbxBYREF | SbxDOUBLE:
177 aTmp.nDouble = *p->pDouble; goto ref;
178 case SbxBYREF | SbxCURRENCY:
179 case SbxBYREF | SbxSALINT64:
180 aTmp.nInt64 = *p->pnInt64; goto ref;
181 case SbxBYREF | SbxSALUINT64:
182 aTmp.uInt64 = *p->puInt64; goto ref;
183 ref:
184 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
185 p = &aTmp; goto start;
186
187 default:
189 }
190 return nRes;
191}
192
193void ImpPutUShort( SbxValues* p, sal_uInt16 n )
194{
195 SbxValues aTmp;
196
197start:
198 switch( +p->eType )
199 {
200 case SbxERROR:
201 case SbxUSHORT:
202 p->nUShort = n; break;
203 case SbxLONG:
204 p->nLong = n; break;
205 case SbxULONG:
206 p->nULong = n; break;
207 case SbxSINGLE:
208 p->nSingle = n; break;
209 case SbxDATE:
210 case SbxDOUBLE:
211 p->nDouble = n; break;
212 case SbxCURRENCY:
213 p->nInt64 = n * CURRENCY_FACTOR; break;
214 case SbxSALINT64:
215 p->nInt64 = n; break;
216 case SbxSALUINT64:
217 p->uInt64 = n; break;
218 case SbxDECIMAL:
219 case SbxBYREF | SbxDECIMAL:
221 break;
222
223 // from here on tests
224 case SbxCHAR:
225 aTmp.pChar = &p->nChar; goto direct;
226 case SbxBYTE:
227 aTmp.pByte = &p->nByte; goto direct;
228 case SbxINTEGER:
229 case SbxBOOL:
230 aTmp.pInteger = &p->nInteger;
231 direct:
232 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
233 p = &aTmp; goto start;
234
235 case SbxBYREF | SbxSTRING:
236 case SbxSTRING:
237 case SbxLPSTR:
238 if( !p->pOUString )
239 p->pOUString = new OUString;
240 ImpCvtNum( static_cast<double>(n), 0, *p->pOUString );
241 break;
242 case SbxOBJECT:
243 {
244 SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
245 if( pVal )
246 pVal->PutUShort( n );
247 else
249 break;
250 }
251
252 case SbxBYREF | SbxCHAR:
253 *p->pChar = static_cast<sal_Unicode>(n); break;
254 case SbxBYREF | SbxBYTE:
255 if( n > SbxMAXBYTE )
256 {
258 }
259 *p->pByte = static_cast<sal_uInt8>(n); break;
260 case SbxBYREF | SbxINTEGER:
261 case SbxBYREF | SbxBOOL:
262 if( n > SbxMAXINT )
263 {
265 }
266 *p->pInteger = static_cast<sal_Int16>(n); break;
267 case SbxBYREF | SbxERROR:
268 case SbxBYREF | SbxUSHORT:
269 *p->pUShort = n; break;
270 case SbxBYREF | SbxLONG:
271 *p->pLong = n; break;
272 case SbxBYREF | SbxULONG:
273 *p->pULong = n; break;
274 case SbxBYREF | SbxSINGLE:
275 *p->pSingle = n; break;
276 case SbxBYREF | SbxDATE:
277 case SbxBYREF | SbxDOUBLE:
278 *p->pDouble = n; break;
279 case SbxBYREF | SbxCURRENCY:
280 *p->pnInt64 = n * CURRENCY_FACTOR; break;
281 case SbxBYREF | SbxSALINT64:
282 *p->pnInt64 = n; break;
283 case SbxBYREF | SbxSALUINT64:
284 *p->puInt64 = n; break;
285
286 default:
288 }
289}
290
291/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
double d
static void SetError(ErrCode)
Definition: sbxbase.cxx:116
void setUInt(unsigned int val)
Definition: sbxdec.cxx:327
bool PutUShort(sal_uInt16)
sal_uInt16 GetUShort() const
Definition: sbxvar.hxx:159
#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 ImpDoubleToUShort(double f)
Definition: sbxconv.hxx:52
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
SbxBOOL
Definition: sbxdef.hxx:215
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 CURRENCY_FACTOR
Definition: sbxdef.hxx:197
constexpr auto SbxMAXBYTE
Definition: sbxdef.hxx:186
sal_uInt16 ImpGetUShort(const SbxValues *p)
Definition: sbxuint.cxx:27
void ImpPutUShort(SbxValues *p, sal_uInt16 n)
Definition: sbxuint.cxx:193
float nSingle
Definition: sbxvar.hxx:55
sal_Int32 nLong
Definition: sbxvar.hxx:49
sal_uInt8 * pByte
Definition: sbxvar.hxx:63
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
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