/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ #pragma once
namespace com::sun::star::beans { class XPropertySet; } namespace com::sun::star::uno { class XComponentContext; } namespace com::sun::star::util { class XNumberFormatter2; }
namespace sca::analysis {
class ScaAnyConverter;
inlinebool IsLeapYear( sal_uInt16 nYear );
#ifdef DISABLE_DYNLOADING
// Avoid clash with the functions with same name in // scaddins/source/datefunc/datefunc.cxx. I am not sure if each pair // have identical semantics, but if yes, one copy should be enough, // but what would be a suitable library where such functions could go? // Or can the analysis library depend on the date library or the other // way around?
struct FuncDataBase
{ constchar* pIntName;
TranslateId pUINameID; // resource ID to UI name const TranslateId* pDescrID; // resource ID to description, parameter names and ~ description bool bDouble; // name already exist in Calc bool bWithOpt; // first parameter is internal constchar** pCompListID; // list of valid names
sal_uInt16 nNumOfParams; // number of named / described parameters
FDCategory eCat; // function category constchar* pSuffix; // if bDouble, append a suffix other than "_ADD" for UI
};
class FuncData final
{ private:
OUString aIntName;
TranslateId pUINameID; const TranslateId* pDescrID; // leads also to parameter descriptions! bool bDouble; // flag for names that already exist in Calc bool bWithOpt; // has internal parameter on first position
sal_uInt16 nParam; // num of parameters
std::vector<OUString> aCompList; // list of all valid names
FDCategory eCat; // function category
OUString aSuffix; // if bDouble and not empty, append a suffix other than "_ADD" for UI
sal_Int16 GetMatchingLevel( const OUString& rRef ) const; // 0.0 = no equality // 1.0 = matches exact // rest = matches without an assumed prefix of one character // rest gives power for 10 represented by the prefix (e.g. 3 for k or -9 for n
class ConvertDataLinear final : public ConvertData
{ double fOffs; public: inline ConvertDataLinear(
std::u16string_view sUnitName, double fConvertConstant, double fConvertOffset,
ConvertDataClass eClass, bool bPrefSupport = false );
virtual ~ConvertDataLinear() override;
virtualdouble Convert( double fVal, const ConvertData& rTo,
sal_Int16 nMatchLevelFrom, sal_Int16 nMatchLevelTo ) const override; // for cases where f(x) = a + bx applies (e.g. Temperatures)
// converts fVal from this unit to rFrom unit // throws exception if not from same class // this implementation is for proportional cases only double ConvertToBase( double fVal, sal_Int16 nMatchLevel ) const; double ConvertFromBase( double fVal, sal_Int16 nMatchLevel ) const;
};
class ConvertDataList
{ private:
std::vector<std::unique_ptr<ConvertData>> maVector; public:
ConvertDataList();
~ConvertDataList();
/// Helper class for date calculation for various financial functions class ScaDate
{ private:
sal_uInt16 nOrigDay; /// is the day of the original date.
sal_uInt16 nDay; /// is the calculated day depending on the current month/year.
sal_uInt16 nMonth; /// is the current month (one-based).
sal_uInt16 nYear; /// is the current year. bool bLastDayMode : 1; /// if true, recalculate nDay after every calculation. bool bLastDay : 1; /// is true, if original date was the last day in month. bool b30Days : 1; /// is true, if every month has 30 days in calculations. bool bUSMode : 1; /// is true, if the US method of 30-day-calculations is used.
/// Calculates nDay from nOrigDay and current date. void setDay();
/// @return count of days in current month inline sal_uInt16 getDaysInMonth() const; /// @return count of days in given month inline sal_uInt16 getDaysInMonth( sal_uInt16 _nMon ) const;
/// @ return count of days in the given month range
sal_Int32 getDaysInMonthRange( sal_uInt16 nFrom, sal_uInt16 nTo ) const; /// @ return count of days in the given year range
sal_Int32 getDaysInYearRange( sal_uInt16 nFrom, sal_uInt16 nTo ) const;
/// Adds/subtracts the given count of years, does not adjust day. /// /// @throws css::lang::IllegalArgumentException void doAddYears( sal_Int32 nYearCount );
public:
ScaDate(); /** @param nBase date handling mode (days in month / days in year): 0 = 30 days / 360 days (US NASD) 1 = exact / exact 2 = exact / 360 3 = exact / 365 4 = 30 days / 360 days (Europe)
5 = exact / exact (no last day adjustment) */
ScaDate( sal_Int32 nNullDate, sal_Int32 nDate, sal_Int32 nBase );
ScaDate( const ScaDate& rCopy );
ScaDate& operator=( const ScaDate& rCopy );
/// @return the current month.
sal_uInt16 getMonth() const { return nMonth; }; /// @return the current year.
sal_uInt16 getYear() const { return nYear; };
/// adds/subtracts the given count of months, adjusts day /// /// @throws css::lang::IllegalArgumentException void addMonths( sal_Int32 nMonthCount );
/// sets the given year, adjusts day inlinevoid setYear( sal_uInt16 nNewYear ); /// adds/subtracts the given count of years, adjusts day /// /// @throws css::lang::IllegalArgumentException inlinevoid addYears( sal_Int32 nYearCount );
/// @return the internal number of the current date
sal_Int32 getDate( sal_Int32 nNullDate ) const; /// @return the number of days between the two dates /// /// @throws css::lang::IllegalArgumentException static sal_Int32 getDiff( const ScaDate& rFrom, const ScaDate& rTo );
/// Helper class for Any->double conversion, using the current locale class ScaAnyConverter
{ private:
css::uno::Reference< css::util::XNumberFormatter2 > xFormatter;
sal_Int32 nDefaultFormat; bool bHasValidFormat;
/** Converts a string to double using the number formatter. If the formatter is not valid, ::rtl::math::stringToDouble() with english separators will be used. @throws css::lang::IllegalArgumentException on strings not representing any double value.
@return the converted double value. */ double convertToDouble( const OUString& rString ) const;
/// Initializing with the current locale /// /// @throws css::uno::RuntimeException void init( const css::uno::Reference< css::beans::XPropertySet >& xPropSet );
/** Converts an Any to double (without initialization). The Any can be empty or contain a double or string. @throws css::lang::IllegalArgumentException on other Any types or on invalid strings. @return true if the Any contains a double or a non-empty valid string,
false if the Any is empty or the string is empty */ bool getDouble( double& rfResult, const css::uno::Any& rAny ) const;
/** Converts an Any to double (with initialization). The Any can be empty or contain a double or string. @throws css::lang::IllegalArgumentException on other Any types or on invalid strings. @return true if the Any contains a double or a non-empty valid string,
false if the Any is empty or the string is empty */ bool getDouble( double& rfResult, const css::uno::Reference< css::beans::XPropertySet >& xPropSet, const css::uno::Any& rAny );
/** Converts an Any to double (with initialization). The Any can be empty or contain a double or string. @throws css::lang::IllegalArgumentException on other Any types or on invalid strings.
@return the value of the double or string or fDefault if the Any or string is empty */ double getDouble( const css::uno::Reference< css::beans::XPropertySet >& xPropSet, const css::uno::Any& rAny, double fDefault );
/** Converts an Any to sal_Int32 (with initialization). The Any can be empty or contain a double or string. @throws css::lang::IllegalArgumentException on other Any types or on invalid values or strings. @return true if the Any contains a double or a non-empty valid string,
false if the Any is empty or the string is empty */ bool getInt32(
sal_Int32& rnResult, const css::uno::Reference< css::beans::XPropertySet >& xPropSet, const css::uno::Any& rAny );
/** Converts an Any to sal_Int32 (with initialization). The Any can be empty or contain a double or string. @throws css::lang::IllegalArgumentException on other Any types or on invalid values or strings.
@return the truncated value of the double or string or nDefault if the Any or string is empty */
sal_Int32 getInt32( const css::uno::Reference< css::beans::XPropertySet >& xPropSet, const css::uno::Any& rAny,
sal_Int32 nDefault );
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.