LibreOffice Module basic (master) 1
sbxconv.hxx
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#pragma once
21
22#include "sbxdec.hxx"
23#include <basic/sberrors.hxx>
24#include <basic/sbx.hxx>
25#include <basic/sbxcore.hxx>
26#include <basic/sbxdef.hxx>
27
29#include <rtl/math.hxx>
30#include <sal/types.h>
31
32class SbxArray;
33
34template <typename I> inline I DoubleTo(double f, I min, I max)
35{
36 f = rtl::math::round(f);
38 {
40 return max;
41 }
43 {
45 return min;
46 }
47 return f;
48}
49
50inline auto ImpDoubleToChar(double f) { return DoubleTo<sal_Unicode>(f, SbxMINCHAR, SbxMAXCHAR); }
51inline auto ImpDoubleToByte(double f) { return DoubleTo<sal_uInt8>(f, 0, SbxMAXBYTE); }
52inline auto ImpDoubleToUShort(double f) { return DoubleTo<sal_uInt16>(f, 0, SbxMAXUINT); }
53inline auto ImpDoubleToInteger(double f) { return DoubleTo<sal_Int16>(f, SbxMININT, SbxMAXINT); }
54inline auto ImpDoubleToULong(double f) { return DoubleTo<sal_uInt32>(f, 0, SbxMAXULNG); }
55inline auto ImpDoubleToLong(double f) { return DoubleTo<sal_Int32>(f, SbxMINLNG, SbxMAXLNG); }
56inline auto ImpDoubleToSalUInt64(double d) { return DoubleTo<sal_uInt64>(d, 0, SAL_MAX_UINT64); }
57inline auto ImpDoubleToSalInt64(double d)
58{
59 return DoubleTo<sal_Int64>(d, SAL_MIN_INT64, SAL_MAX_INT64);
60}
61
62// SBXSCAN.CXX
63extern void ImpCvtNum( double nNum, short nPrec, OUString& rRes, bool bCoreString=false );
64extern ErrCode ImpScan
65 ( const OUString& rSrc, double& nVal, SbxDataType& rType, sal_uInt16* pLen,
66 bool bOnlyIntntl );
67
68// with advanced evaluation (International, "TRUE"/"FALSE")
69extern bool ImpConvStringExt( OUString& rSrc, SbxDataType eTargetType );
70
71void ImpGetIntntlSep( sal_Unicode& rcDecimalSep, sal_Unicode& rcThousandSep, sal_Unicode& rcDecimalSepAlt );
72
73// SBXINT.CXX
74
75sal_Int16 ImpGetInteger( const SbxValues* );
76void ImpPutInteger( SbxValues*, sal_Int16 );
77
78sal_Int64 ImpGetInt64( const SbxValues* );
79void ImpPutInt64( SbxValues*, sal_Int64 );
80sal_uInt64 ImpGetUInt64( const SbxValues* );
81void ImpPutUInt64( SbxValues*, sal_uInt64 );
82
83double ImpSalUInt64ToDouble( sal_uInt64 n );
84
85// SBXLNG.CXX
86
87sal_Int32 ImpGetLong( const SbxValues* );
88void ImpPutLong( SbxValues*, sal_Int32 );
89
90// SBXSNG.CXX
91
92float ImpGetSingle( const SbxValues* );
93void ImpPutSingle( SbxValues*, float );
94
95// SBXDBL.CXX
96
97double ImpGetDouble( const SbxValues* );
98void ImpPutDouble( SbxValues*, double, bool bCoreString=false );
99
100// SBXCURR.CXX
101
102sal_Int64 ImpGetCurrency( const SbxValues* );
103void ImpPutCurrency( SbxValues*, const sal_Int64 );
104
105inline sal_Int64 ImpDoubleToCurrency( double d )
106{
107 if (d > 0)
108 return static_cast<sal_Int64>( d * CURRENCY_FACTOR + 0.5);
109 else
110 return static_cast<sal_Int64>( d * CURRENCY_FACTOR - 0.5);
111}
112
113inline double ImpCurrencyToDouble( const sal_Int64 r )
114 { return static_cast<double>(r) / double(CURRENCY_FACTOR); }
115
116
117// SBXDEC.CXX
118
121void ImpPutDecimal( SbxValues* p, SbxDecimal* pDec );
122
123// SBXDATE.CXX
124
125double ImpGetDate( const SbxValues* );
126void ImpPutDate( SbxValues*, double );
127
128// SBXSTR.CXX
129
130OUString ImpGetString( const SbxValues* );
131OUString ImpGetCoreString( const SbxValues* );
132void ImpPutString( SbxValues*, const OUString* );
133
134// SBXCHAR.CXX
135
138
139// SBXBYTE.CXX
142
143// SBXUINT.CXX
144
145sal_uInt16 ImpGetUShort( const SbxValues* );
146void ImpPutUShort( SbxValues*, sal_uInt16 );
147
148// SBXULNG.CXX
149
150sal_uInt32 ImpGetULong( const SbxValues* );
151void ImpPutULong( SbxValues*, sal_uInt32 );
152
153// SBXBOOL.CXX
154
155enum SbxBOOL ImpGetBool( const SbxValues* );
156void ImpPutBool( SbxValues*, sal_Int16 );
157
158// ByteArray <--> String
159SbxArray* StringToByteArray(const OUString& rStr);
160OUString ByteArrayToString(SbxArray* pArr);
161
162/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double d
Definition: sbx.hxx:95
static void SetError(ErrCode)
Definition: sbxbase.cxx:116
#define max(a, b)
constexpr std::enable_if_t< std::is_floating_point_v< F > &&std::is_integral_v< I >, bool > convertsToAtLeast(F value, I min)
constexpr std::enable_if_t< std::is_floating_point_v< F > &&std::is_integral_v< I >, bool > convertsToAtMost(F value, I max)
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
#define ERRCODE_BASIC_MATH_OVERFLOW
Definition: sberrors.hxx:27
void ImpPutDecimal(SbxValues *p, SbxDecimal *pDec)
Definition: sbxdec.cxx:512
void ImpPutLong(SbxValues *, sal_Int32)
Definition: sbxlng.cxx:161
void ImpPutInt64(SbxValues *, sal_Int64)
Definition: sbxint.cxx:443
sal_Int16 ImpGetInteger(const SbxValues *)
Definition: sbxint.cxx:30
void ImpPutUInt64(SbxValues *, sal_uInt64)
Definition: sbxint.cxx:696
void ImpPutCurrency(SbxValues *, const sal_Int64)
Definition: sbxcurr.cxx:324
sal_Int64 ImpGetInt64(const SbxValues *)
Definition: sbxint.cxx:327
double ImpGetDouble(const SbxValues *)
Definition: sbxdbl.cxx:27
double ImpCurrencyToDouble(const sal_Int64 r)
Definition: sbxconv.hxx:113
sal_uInt32 ImpGetULong(const SbxValues *)
Definition: sbxulng.cxx:27
void ImpPutSingle(SbxValues *, float)
Definition: sbxsng.cxx:173
void ImpPutDouble(SbxValues *, double, bool bCoreString=false)
Definition: sbxdbl.cxx:138
sal_uInt64 ImpGetUInt64(const SbxValues *)
Definition: sbxint.cxx:583
auto ImpDoubleToChar(double f)
Definition: sbxconv.hxx:50
auto ImpDoubleToInteger(double f)
Definition: sbxconv.hxx:53
void ImpPutChar(SbxValues *, sal_Unicode)
Definition: sbxchar.cxx:212
void ImpPutInteger(SbxValues *, sal_Int16)
Definition: sbxint.cxx:197
void ImpPutULong(SbxValues *, sal_uInt32)
Definition: sbxulng.cxx:160
sal_Unicode ImpGetChar(const SbxValues *)
Definition: sbxchar.cxx:27
SbxArray * StringToByteArray(const OUString &rStr)
Definition: sbxstr.cxx:266
sal_uInt16 ImpGetUShort(const SbxValues *)
Definition: sbxuint.cxx:27
double ImpGetDate(const SbxValues *)
Definition: sbxdate.cxx:36
void ImpPutBool(SbxValues *, sal_Int16)
Definition: sbxbool.cxx:140
auto ImpDoubleToSalUInt64(double d)
Definition: sbxconv.hxx:56
sal_Int32 ImpGetLong(const SbxValues *)
Definition: sbxlng.cxx:29
auto ImpDoubleToLong(double f)
Definition: sbxconv.hxx:55
I DoubleTo(double f, I min, I max)
Definition: sbxconv.hxx:34
OUString ImpGetString(const SbxValues *)
Definition: sbxstr.cxx:32
auto ImpDoubleToUShort(double f)
Definition: sbxconv.hxx:52
void ImpPutString(SbxValues *, const OUString *)
Definition: sbxstr.cxx:161
float ImpGetSingle(const SbxValues *)
Definition: sbxsng.cxx:27
OUString ImpGetCoreString(const SbxValues *)
Definition: sbxstr.cxx:142
auto ImpDoubleToULong(double f)
Definition: sbxconv.hxx:54
sal_uInt8 ImpGetByte(const SbxValues *)
Definition: sbxbyte.cxx:31
OUString ByteArrayToString(SbxArray *pArr)
Definition: sbxstr.cxx:302
double ImpSalUInt64ToDouble(sal_uInt64 n)
Definition: sbxint.cxx:316
sal_Int64 ImpGetCurrency(const SbxValues *)
Definition: sbxcurr.cxx:159
bool ImpConvStringExt(OUString &rSrc, SbxDataType eTargetType)
Definition: sbxscan.cxx:301
void ImpPutDate(SbxValues *, double)
Definition: sbxdate.cxx:214
ErrCode ImpScan(const OUString &rSrc, double &nVal, SbxDataType &rType, sal_uInt16 *pLen, bool bOnlyIntntl)
Definition: sbxscan.cxx:71
sal_Int64 ImpDoubleToCurrency(double d)
Definition: sbxconv.hxx:105
void ImpPutUShort(SbxValues *, sal_uInt16)
Definition: sbxuint.cxx:193
enum SbxBOOL ImpGetBool(const SbxValues *)
Definition: sbxbool.cxx:26
void ImpPutByte(SbxValues *, sal_uInt8)
Definition: sbxbyte.cxx:231
void ImpGetIntntlSep(sal_Unicode &rcDecimalSep, sal_Unicode &rcThousandSep, sal_Unicode &rcDecimalSepAlt)
Definition: sbxscan.cxx:54
auto ImpDoubleToSalInt64(double d)
Definition: sbxconv.hxx:57
SbxDecimal * ImpCreateDecimal(SbxValues *p)
Definition: sbxdec.cxx:376
SbxDecimal * ImpGetDecimal(const SbxValues *p)
Definition: sbxdec.cxx:390
auto ImpDoubleToByte(double f)
Definition: sbxconv.hxx:51
void ImpCvtNum(double nNum, short nPrec, OUString &rRes, bool bCoreString=false)
Definition: sbxscan.cxx:290
constexpr sal_uInt32 SbxMAXULNG
Definition: sbxdef.hxx:192
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
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
#define SAL_MAX_INT64
unsigned char sal_uInt8
#define SAL_MAX_UINT64
#define SAL_MIN_INT64
sal_uInt16 sal_Unicode