1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
23 #include <basic/sberrors.hxx>
24 #include <basic/sbx.hxx>
25 #include <basic/sbxcore.hxx>
26 #include <basic/sbxdef.hxx>
28 #include <o3tl/float_int_conversion.hxx>
29 #include <rtl/math.hxx>
30 #include <sal/types.h>
34 template <typename I
> inline I
DoubleTo(double f
, I min
, I max
)
36 f
= rtl::math::round(f
);
37 if (!o3tl::convertsToAtMost(f
, max
))
39 SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW
);
42 if (!o3tl::convertsToAtLeast(f
, min
))
44 SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW
);
50 inline auto ImpDoubleToChar(double f
) { return DoubleTo
<sal_Unicode
>(f
, SbxMINCHAR
, SbxMAXCHAR
); }
51 inline auto ImpDoubleToByte(double f
) { return DoubleTo
<sal_uInt8
>(f
, 0, SbxMAXBYTE
); }
52 inline auto ImpDoubleToUShort(double f
) { return DoubleTo
<sal_uInt16
>(f
, 0, SbxMAXUINT
); }
53 inline auto ImpDoubleToInteger(double f
) { return DoubleTo
<sal_Int16
>(f
, SbxMININT
, SbxMAXINT
); }
54 inline auto ImpDoubleToULong(double f
) { return DoubleTo
<sal_uInt32
>(f
, 0, SbxMAXULNG
); }
55 inline auto ImpDoubleToLong(double f
) { return DoubleTo
<sal_Int32
>(f
, SbxMINLNG
, SbxMAXLNG
); }
56 inline auto ImpDoubleToSalUInt64(double d
) { return DoubleTo
<sal_uInt64
>(d
, 0, SAL_MAX_UINT64
); }
57 inline auto ImpDoubleToSalInt64(double d
)
59 return DoubleTo
<sal_Int64
>(d
, SAL_MIN_INT64
, SAL_MAX_INT64
);
63 extern void ImpCvtNum( double nNum
, short nPrec
, OUString
& rRes
, bool bCoreString
=false );
64 extern ErrCode ImpScan
65 ( const OUString
& rSrc
, double& nVal
, SbxDataType
& rType
, sal_uInt16
* pLen
,
68 // with advanced evaluation (International, "TRUE"/"FALSE")
69 extern bool ImpConvStringExt( OUString
& rSrc
, SbxDataType eTargetType
);
71 void ImpGetIntntlSep( sal_Unicode
& rcDecimalSep
, sal_Unicode
& rcThousandSep
, sal_Unicode
& rcDecimalSepAlt
);
75 sal_Int16
ImpGetInteger( const SbxValues
* );
76 void ImpPutInteger( SbxValues
*, sal_Int16
);
78 sal_Int64
ImpGetInt64( const SbxValues
* );
79 void ImpPutInt64( SbxValues
*, sal_Int64
);
80 sal_uInt64
ImpGetUInt64( const SbxValues
* );
81 void ImpPutUInt64( SbxValues
*, sal_uInt64
);
83 double ImpSalUInt64ToDouble( sal_uInt64 n
);
87 sal_Int32
ImpGetLong( const SbxValues
* );
88 void ImpPutLong( SbxValues
*, sal_Int32
);
92 float ImpGetSingle( const SbxValues
* );
93 void ImpPutSingle( SbxValues
*, float );
97 double ImpGetDouble( const SbxValues
* );
98 void ImpPutDouble( SbxValues
*, double, bool bCoreString
=false );
102 sal_Int64
ImpGetCurrency( const SbxValues
* );
103 void ImpPutCurrency( SbxValues
*, const sal_Int64
);
105 inline sal_Int64
ImpDoubleToCurrency( double d
)
108 return static_cast<sal_Int64
>( d
* CURRENCY_FACTOR
+ 0.5);
110 return static_cast<sal_Int64
>( d
* CURRENCY_FACTOR
- 0.5);
113 inline double ImpCurrencyToDouble( const sal_Int64 r
)
114 { return static_cast<double>(r
) / double(CURRENCY_FACTOR
); }
119 SbxDecimal
* ImpCreateDecimal( SbxValues
* p
);
120 SbxDecimal
* ImpGetDecimal( const SbxValues
* p
);
121 void ImpPutDecimal( SbxValues
* p
, SbxDecimal
* pDec
);
125 double ImpGetDate( const SbxValues
* );
126 void ImpPutDate( SbxValues
*, double );
130 OUString
ImpGetString( const SbxValues
* );
131 OUString
ImpGetCoreString( const SbxValues
* );
132 void ImpPutString( SbxValues
*, const OUString
* );
136 sal_Unicode
ImpGetChar( const SbxValues
* );
137 void ImpPutChar( SbxValues
*, sal_Unicode
);
140 sal_uInt8
ImpGetByte( const SbxValues
* );
141 void ImpPutByte( SbxValues
*, sal_uInt8
);
145 sal_uInt16
ImpGetUShort( const SbxValues
* );
146 void ImpPutUShort( SbxValues
*, sal_uInt16
);
150 sal_uInt32
ImpGetULong( const SbxValues
* );
151 void ImpPutULong( SbxValues
*, sal_uInt32
);
155 enum SbxBOOL
ImpGetBool( const SbxValues
* );
156 void ImpPutBool( SbxValues
*, sal_Int16
);
158 // ByteArray <--> String
159 SbxArray
* StringToByteArray(const OUString
& rStr
);
160 OUString
ByteArrayToString(SbxArray
* pArr
);
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */