Hello community, here is the log from the commit of package alkimia for openSUSE:Factory checked in at 2018-03-22 12:04:29 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/alkimia (Old) and /work/SRC/openSUSE:Factory/.alkimia.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "alkimia" Thu Mar 22 12:04:29 2018 rev:2 rq:589191 version:7.0.1 Changes: -------- --- /work/SRC/openSUSE:Factory/alkimia/alkimia.changes 2018-01-31 19:54:06.271302930 +0100 +++ /work/SRC/openSUSE:Factory/.alkimia.new/alkimia.changes 2018-03-22 12:10:23.250338976 +0100 @@ -1,0 +2,6 @@ +Fri Mar 16 21:02:17 UTC 2018 - [email protected] + +- update to version 7.0.1: + * now also supports MPIR instead of GMP + +------------------------------------------------------------------- Old: ---- alkimia-7.0.tar.xz New: ---- alkimia-7.0.1.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ alkimia.spec ++++++ --- /var/tmp/diff_new_pack.s5K9Ve/_old 2018-03-22 12:10:23.938314317 +0100 +++ /var/tmp/diff_new_pack.s5K9Ve/_new 2018-03-22 12:10:23.942314173 +0100 @@ -20,7 +20,7 @@ %define sonum 7 Name: alkimia -Version: 7.0 +Version: 7.0.1 Release: 0 Summary: Library with common classes and functionality used by finance applications License: LGPL-2.1+ ++++++ alkimia-7.0.tar.xz -> alkimia-7.0.1.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/alkimia-7.0/.arcconfig new/alkimia-7.0.1/.arcconfig --- old/alkimia-7.0/.arcconfig 1970-01-01 01:00:00.000000000 +0100 +++ new/alkimia-7.0.1/.arcconfig 2018-03-15 20:28:26.733594572 +0100 @@ -0,0 +1,3 @@ +{ + "phabricator.uri" : "https://phabricator.kde.org/" +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/alkimia-7.0/CMakeLists.txt new/alkimia-7.0.1/CMakeLists.txt --- old/alkimia-7.0/CMakeLists.txt 2018-01-05 14:47:41.677028838 +0100 +++ new/alkimia-7.0.1/CMakeLists.txt 2018-03-15 20:28:26.733594572 +0100 @@ -1,7 +1,7 @@ # The CMake version we require (must be first) -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.0.2) -project(alkimia) +project(alkimia VERSION 7.0.1) find_package(ECM 0.0.11 REQUIRED NO_MODULE) @@ -12,7 +12,7 @@ include(KDECompilerSettings NO_POLICY_SCOPE) include(FeatureSummary) -# check for PkgConfig, Qt and GMP +# check for PkgConfig, Qt and MPIR/GMP find_package(PkgConfig) if(BUILD_QT4) find_package(Qt4 REQUIRED COMPONENTS QtCore QtDBus QtTest) @@ -31,7 +31,24 @@ set(PC_TARGET_QTPREFIX Qt5) set(PC_TARGET_SUFFIX 5) endif() -find_package(GMP REQUIRED) + +# figure out which multi-precision library to use +# MPIR is preferred over GMP +find_package(MPIR) +if(MPIR_FOUND) + set(MP_INCLUDE_DIR ${MPIR_INCLUDE_DIR}) + set(MP_LIBRARIES ${MPIR_LIBRARIES}) + set(MP_HEADER mpirxx.h) + set(MP_CMAKE_MODULE "MPIR") + set(PC_LIB mpir) +else() + find_package(GMP REQUIRED) + set(MP_INCLUDE_DIR ${GMP_INCLUDE_DIR}) + set(MP_LIBRARIES ${GMP_LIBRARIES}) + set(MP_HEADER gmpxx.h) + set(MP_CMAKE_MODULE "GMP") + set(PC_LIB gmp) +endif() # check for Doxygen (for API documentation) find_package(Doxygen) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/alkimia-7.0/README.md new/alkimia-7.0.1/README.md --- old/alkimia-7.0/README.md 2018-01-05 14:47:41.677028838 +0100 +++ new/alkimia-7.0.1/README.md 2018-03-15 20:28:26.733594572 +0100 @@ -5,7 +5,7 @@ * git * cmake supported C++ compiler including linker * Qt4 or Qt5 development package - +* libMPIR or libGMP Fetch alkimia source package from git repo and unpack into a subdirectory with diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/alkimia-7.0/autotests/CMakeLists.txt new/alkimia-7.0.1/autotests/CMakeLists.txt --- old/alkimia-7.0/autotests/CMakeLists.txt 2018-01-05 14:47:41.677028838 +0100 +++ new/alkimia-7.0.1/autotests/CMakeLists.txt 2018-03-15 20:28:26.733594572 +0100 @@ -1,7 +1,7 @@ include(ECMAddTests) if(BUILD_QT4) - set(TEST_LIB QtTest) + set(TEST_LIB ${QT_QTTEST_LIBRARY}) else() set(TEST_LIB Qt5::Test) endif() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/alkimia-7.0/cmake/modules/FindMPIR.cmake new/alkimia-7.0.1/cmake/modules/FindMPIR.cmake --- old/alkimia-7.0/cmake/modules/FindMPIR.cmake 1970-01-01 01:00:00.000000000 +0100 +++ new/alkimia-7.0.1/cmake/modules/FindMPIR.cmake 2018-03-15 20:28:26.733594572 +0100 @@ -0,0 +1,24 @@ +# Try to find the MPIR librairies +# MPIR_FOUND - system has MPIR lib +# MPIR_INCLUDE_DIR - the MPIR include directory +# MPIR_LIBRARIES - Libraries needed to use MPIR + +# Copyright (c) 2006, Laurent Montel, <[email protected]> +# Copyright (c) 2018, Thomas Baumgart <[email protected]> +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + + +if (MPIR_INCLUDE_DIR AND MPIR_LIBRARIES) + # Already in cache, be silent + set(MPIR_FIND_QUIETLY TRUE) +endif (MPIR_INCLUDE_DIR AND MPIR_LIBRARIES) + +find_path(MPIR_INCLUDE_DIR NAMES mpir.h ) +find_library(MPIR_LIBRARIES NAMES mpir libmpir) + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(MPIR DEFAULT_MSG MPIR_INCLUDE_DIR MPIR_LIBRARIES) + +mark_as_advanced(MPIR_INCLUDE_DIR MPIR_LIBRARIES) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/alkimia-7.0/src/CMakeLists.txt new/alkimia-7.0.1/src/CMakeLists.txt --- old/alkimia-7.0/src/CMakeLists.txt 2018-01-05 14:47:41.677028838 +0100 +++ new/alkimia-7.0.1/src/CMakeLists.txt 2018-03-15 20:28:26.733594572 +0100 @@ -1,17 +1,11 @@ -######################### libalkimia Version ########################## -# The current version of libalkimia (used for packages and config.h) -set(VERSION_MAJOR "7") -set(VERSION_MINOR "0") -set(VERSION_PATCH "0") - include(GenerateExportHeader) include(ECMGenerateHeaders) include(ECMGeneratePriFile) -include(ECMPackageConfigHelpers) +include(CMakePackageConfigHelpers) include(ECMSetupVersion) -set(ALKIMIA_LIB_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") -set(ALKIMIA_LIB_SOVERSION "${VERSION_MAJOR}") +set(ALKIMIA_LIB_VERSION ${alkimia_VERSION}) +set(ALKIMIA_LIB_SOVERSION "${alkimia_VERSION_MAJOR}") set(alkimia_LIB_SRCS alkvalue.cpp @@ -20,7 +14,7 @@ ) set(alkimia_HEADERS - alkvalue.h + ${CMAKE_CURRENT_BINARY_DIR}/alkvalue.h alkquoteitem.h alkcompany.h ${CMAKE_CURRENT_BINARY_DIR}/alk_export.h @@ -30,29 +24,34 @@ kde_target_enable_exceptions(alkimia PUBLIC) -target_include_directories(alkimia PUBLIC ${GMP_INCLUDE_DIR}) -target_link_libraries(alkimia PUBLIC ${QT_USE_LIBSPREFIX}Core ${QT_USE_LIBSPREFIX}DBus ${GMP_LIBRARIES}) +target_include_directories(alkimia PRIVATE ${MP_INCLUDE_DIR}) +target_link_libraries(alkimia PUBLIC ${QT_USE_LIBSPREFIX}Core ${QT_USE_LIBSPREFIX}DBus ${MP_LIBRARIES}) generate_export_header(alkimia BASE_NAME alk) -set_target_properties(alkimia PROPERTIES VERSION ${ALKIMIA_LIB_VERSION} SOVERSION ${ALKIMIA_LIB_SOVERSION}) +if(WIN32) + set_target_properties(alkimia PROPERTIES SUFFIX "${ALKIMIA_LIB_SOVERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}") +else() + set_target_properties(alkimia PROPERTIES VERSION ${ALKIMIA_LIB_VERSION} SOVERSION ${ALKIMIA_LIB_SOVERSION}) +endif() set_target_properties(alkimia PROPERTIES OUTPUT_NAME alkimia${ALKIMIA_LIB_SUFFIX}) set(INCLUDE_INSTALL_DIR include/alkimia/${ALKIMIA_INCLUDE_SUFFIX}) if (NOT WIN32) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libalkimia.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libalkimia${ALKIMIA_PATH_SUFFIX}.pc IMMEDIATE @ONLY) endif(NOT WIN32) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/alkvalue.h.in ${CMAKE_CURRENT_BINARY_DIR}/alkvalue.h IMMEDIATE) ########### create package configuration file ########### # create a Config.cmake and a ConfigVersion.cmake file and install them -set(CMAKECONFIG_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/LibAlkimia${ALKIMIA_PATH_SUFFIX}-${VERSION_MAJOR}.${VERSION_MINOR}") +set(CMAKECONFIG_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/LibAlkimia${ALKIMIA_PATH_SUFFIX}-${alkimia_VERSION_MAJOR}.${alkimia_VERSION_MINOR}") -ecm_setup_version(${ALKIMIA_LIB_VERSION} VARIABLE_PREFIX ALKIMIA +ecm_setup_version(${alkimia_VERSION} VARIABLE_PREFIX ALKIMIA PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/LibAlkimia${ALKIMIA_PATH_SUFFIX}ConfigVersion.cmake" COMPATIBILITY SameMajorVersion ) -ecm_configure_package_config_file( +configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/LibAlkimiaConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/LibAlkimia${ALKIMIA_PATH_SUFFIX}Config.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} @@ -84,7 +83,7 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/LibAlkimia${ALKIMIA_PATH_SUFFIX}Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/LibAlkimia${ALKIMIA_PATH_SUFFIX}ConfigVersion.cmake" - "../cmake/modules/FindGMP.cmake" + "../cmake/modules/Find${MP_CMAKE_MODULE}.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/alkimia-7.0/src/LibAlkimiaConfig.cmake.in new/alkimia-7.0.1/src/LibAlkimiaConfig.cmake.in --- old/alkimia-7.0/src/LibAlkimiaConfig.cmake.in 2018-01-05 14:47:41.677028838 +0100 +++ new/alkimia-7.0.1/src/LibAlkimiaConfig.cmake.in 2018-03-15 20:28:26.733594572 +0100 @@ -8,10 +8,9 @@ find_dependency(Qt5Core) find_dependency(Qt5DBus) endif() -find_dependency(GMP) +find_dependency(@MP_CMAKE_MODULE@) include("${CMAKE_CURRENT_LIST_DIR}/LibAlkimia@[email protected]") -set_and_check(LIBALKIMIA_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") -set_property(TARGET Alkimia::alkimia PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${LIBALKIMIA_INCLUDE_DIR}) +set_property(TARGET Alkimia::alkimia PROPERTY INTERFACE_INCLUDE_DIRECTORIES "@PACKAGE_INCLUDE_INSTALL_DIR@" ${@MP_CMAKE_MODULE@_INCLUDE_DIR}) message(STATUS "Found LibAlkimia: ${CMAKE_CURRENT_LIST_DIR}/LibAlkimia@[email protected] (found version \"@ALKIMIA_LIB_VERSION@\")") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/alkimia-7.0/src/alkvalue.cpp new/alkimia-7.0.1/src/alkvalue.cpp --- old/alkimia-7.0/src/alkvalue.cpp 2018-01-05 14:47:41.677028838 +0100 +++ new/alkimia-7.0.1/src/alkvalue.cpp 2018-03-15 20:28:26.737594656 +0100 @@ -1,5 +1,6 @@ /*************************************************************************** - * Copyright 2010 Thomas Baumgart [email protected] * + * Copyright 2010 Thomas Baumgart [email protected] * + * Copyright 2018 Thomas Baumgart [email protected] * * * * This file is part of libalkimia. * * * @@ -46,7 +47,7 @@ QString result = QString::fromLatin1(p); // and free up the resources allocated by gmp_asprintf - __gmp_freefunc_t freefunc; + void (*freefunc) (void *, size_t); mp_get_memory_functions(NULL, NULL, &freefunc); (*freefunc)(p, std::strlen(p) + 1); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/alkimia-7.0/src/alkvalue.h new/alkimia-7.0.1/src/alkvalue.h --- old/alkimia-7.0/src/alkvalue.h 2018-01-05 14:47:41.677028838 +0100 +++ new/alkimia-7.0.1/src/alkvalue.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,262 +0,0 @@ -/*************************************************************************** - * Copyright 2010 Thomas Baumgart [email protected] * - * * - * This file is part of libalkimia. * - * * - * libalkimia is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public License * - * as published by the Free Software Foundation; either version 2.1 of * - * the License or (at your option) version 3 or any later version. * - * * - * libalkimia is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see <http://www.gnu.org/licenses/> * - ***************************************************************************/ - -#ifndef ALKVALUE_H -#define ALKVALUE_H - -// Workaround: include before gmpxx.h to fix build with gcc-4.9 -/** @todo When gmp version is higer than 5.1.3, remove cstddef include */ -#include <cstddef> -#include <gmpxx.h> // krazy:exclude=camelcase -#include <QString> -#include <QSharedDataPointer> - -#include "alk_export.h" - -/** - * This class represents a financial value within Alkimia. - * It can be used to represent balances, shares, amounts etc. - * - * @author Thomas Baumgart - */ -class ALK_EXPORT AlkValue -{ -public: - enum RoundingMethod { - RoundNever = 0, /**< - * Don't do any rounding, simply truncate and - * print a warning in case of a remainder. - * Otherwise the same as RoundTrunc. - */ - - RoundFloor, /**< - * Round to the largest integral value not - * greater than @p this. - * e.g. 0.5 -> 0.0 and -0.5 -> -1.0 - */ - - RoundCeil, /**< - * Round to the smallest integral value not - * less than @p this. - * e.g. 0.5 -> 1.0 and -0.5 -> -0.0 - */ - - RoundTruncate, /**< - * No rounding, simply truncate any fraction - */ - - RoundPromote, /**< - * Use RoundCeil for positive and RoundFloor - * for negative values of @p this. - * e.g. 0.5 -> 1.0 and -0.5 -> -1.0 - */ - - RoundHalfDown, /**< - * Round up or down with the following - * constraints: - * 0.1 .. 0.5 -> 0.0 and 0.6 .. 0.9 -> 1.0 - */ - - RoundHalfUp, /**< - * Round up or down with the following - * constraints: - * 0.1 .. 0.4 -> 0.0 and 0.5 .. 0.9 -> 1.0 - */ - - RoundRound /**< - * Use RoundHalfDown for 0.1 .. 0.4 and - * RoundHalfUp for 0.6 .. 0.9. Use RoundHalfUp - * for 0.5 in case the resulting numerator - * is odd, RoundHalfDown in case the resulting - * numerator is even. - * e.g. 0.5 -> 0.0 and 1.5 -> 2.0 - */ - }; - - // Constructors / Destructor - /** - * This is the standard constructor of an AlkValue object. - * The value will be initialized to 0. - */ - AlkValue(); - - /// The destructor - ~AlkValue(); - - /// Copy constructor - AlkValue(const AlkValue &val); - - /** - * This constructor converts an int into an AlkValue. It can - * also convert a rational number when a @a denom is supplied. - * - * @param num numerator of the rational number - * @param denom denominator of the rational number (defaults to 1) - */ - explicit AlkValue(const int num, const unsigned int denom = 1); - - /** - * Convenience ctor for usage with mpz_class objects as numerator - * and denominator. - * - * @param num numerator of the rational number - * @param denom denominator of the rational number (defaults to 1) - */ - explicit AlkValue(const mpz_class &num, const mpz_class &denom); - - /** - * Convenience ctor to create an AlkValue object based on an mpq_class object - */ - explicit AlkValue(const mpq_class &val); - - /** - * This constructor converts a double into an AlkValue. In case - * a @a denom is supplied with a value different from zero, the - * @a val will be rounded to be based on the supplied @a denom. - * e.g. val = 1.234 and denom = 100 will construct an AlkValue - * of 1.23. The rounding method is @p RoundRound. - * - * @sa AlkValue::convertDenominator() - * - * @param val the double value - * @param denom the denominator of the resulting AlkValue - * - * @note In case one wants to use the number of decimal places - * to specify the length of the fractional part, use - * - * @code - * AlkValue alk(1.234, AlkValue::precisionToDenominator(2).get_ui()); - * // alk == 1.23 - * @endcode - */ - explicit AlkValue(const double &val, const unsigned int denom = 0); - - /** - * This constructor converts a QString into an AlkValue. - * Several formats are supported: - * - * -# prices in the form "8 5/16" - * -# our own toString() format - * -# others - - * Others may be enclosed in "(" and ")" and treated as negative. - * They may start or end with a dash and treated as negative. - * The decimal symbols is identified as provided in @a decimalSymbol. - * All other non-numeric characters are skipped - */ - AlkValue(const QString &str, const QChar &decimalSymbol); - - /** - * Returns the current value converted to the given @a denom (default is 100 - * or two digits of precision). The rounding method used is controlled by - * the @a how argument and defaults to @p RoundRound. - */ - AlkValue convertDenominator(const int denom = 100, const RoundingMethod how = RoundRound) const; - - /** - * This is a convenience function for convertDenom but instead of providing - * the new denominator one provides the number of digits for the @a precision. - * This value defaults to 2. The rounding method used is controlled by - * the @a how argument and defaults to @p RoundRound. - */ - AlkValue convertPrecision(const int precision = 2, const RoundingMethod how = RoundRound) const; - - // assignment operators - const AlkValue & operator=(const AlkValue &val); - const AlkValue & operator=(int num); - const AlkValue & operator=(double num); - const AlkValue & operator=(const QString &str); - - // comparison - bool operator==(const AlkValue &val) const; - bool operator!=(const AlkValue &val) const; - bool operator<(const AlkValue &val) const; - bool operator>(const AlkValue &val) const; - bool operator<=(const AlkValue &val) const; - bool operator>=(const AlkValue &val) const; - - // calculation - AlkValue operator+(const AlkValue &summand) const; - AlkValue operator-(const AlkValue &minuend) const; - AlkValue operator*(const AlkValue &factor) const; - AlkValue operator/(const AlkValue &divisor) const; - - AlkValue operator*(int factor) const; - - // unary operators - AlkValue operator-() const; - AlkValue & operator+= (const AlkValue &val); - AlkValue & operator-= (const AlkValue &val); - AlkValue & operator/= (const AlkValue &val); - AlkValue & operator*= (const AlkValue &val); - - // functions - - /// @return the absolute value of the AlkValue - AlkValue abs() const; - - /// @return QString representation in form '[-]num/denom'. - QString toString() const; - - /** - * This method transforms the AlkValue into its canonicalized - * form by reducing it to the smallest denominator. Example: - * 25/100 will be converted to 1/4. Use this function at the - * end of a longer calculation as all AlkValue methods require - * the object to be in the canonicalized form. For speed purposes - * the conversion is not performed before each operation. - * - * @return const reference to the object - */ - const AlkValue& canonicalize(); - - /// convert a denominator to a precision - /// e.g. 100 -> 2, 1000 -> 3 - /// in case of a negative @a denom, the function returns 0 - static mpz_class denominatorToPrecision(mpz_class denom); - - /// convert a precision to the corresponding denominator - /// e.g. 2 -> 100, 4 -> 10000 - /// in case of a negative @a prec, the function returns 1 - static mpz_class precisionToDenominator(mpz_class prec); - -protected: - /// \internal unit test class - friend class AlkValueTest; - - /// provides an access method to the private value storage - /// for derived classes - const mpq_class &valueRef() const; - mpq_class &valueRef(); - -private: - /// \internal d-pointer class. - class Private; - /// \internal d-pointer instance. - QSharedDataPointer<Private> d; - /// \internal shared zero value. - static QSharedDataPointer<AlkValue::Private>& sharedZero(); - - // The following methods are not implemented (yet) - // ALKIMIA_EXPORT friend QDataStream &operator<<(QDataStream &, const AlkValue &); - // ALKIMIA_EXPORT friend QDataStream &operator>>(QDataStream &, AlkValue &); -}; - -#endif - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/alkimia-7.0/src/alkvalue.h.in new/alkimia-7.0.1/src/alkvalue.h.in --- old/alkimia-7.0/src/alkvalue.h.in 1970-01-01 01:00:00.000000000 +0100 +++ new/alkimia-7.0.1/src/alkvalue.h.in 2018-03-15 20:28:26.737594656 +0100 @@ -0,0 +1,263 @@ +/*************************************************************************** + * Copyright 2010 Thomas Baumgart [email protected] * + * Copyright 2018 Thomas Baumgart [email protected] * + * * + * This file is part of libalkimia. * + * * + * libalkimia is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public License * + * as published by the Free Software Foundation; either version 2.1 of * + * the License or (at your option) version 3 or any later version. * + * * + * libalkimia is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/> * + ***************************************************************************/ + +#ifndef ALKVALUE_H +#define ALKVALUE_H + +// Workaround: include before gmpxx.h to fix build with gcc-4.9 +/** @todo When gmp version is higer than 5.1.3, remove cstddef include */ +#include <cstddef> +#include <@MP_HEADER@> // krazy:exclude=camelcase +#include <QString> +#include <QSharedDataPointer> + +#include "alk_export.h" + +/** + * This class represents a financial value within Alkimia. + * It can be used to represent balances, shares, amounts etc. + * + * @author Thomas Baumgart + */ +class ALK_EXPORT AlkValue +{ +public: + enum RoundingMethod { + RoundNever = 0, /**< + * Don't do any rounding, simply truncate and + * print a warning in case of a remainder. + * Otherwise the same as RoundTrunc. + */ + + RoundFloor, /**< + * Round to the largest integral value not + * greater than @p this. + * e.g. 0.5 -> 0.0 and -0.5 -> -1.0 + */ + + RoundCeil, /**< + * Round to the smallest integral value not + * less than @p this. + * e.g. 0.5 -> 1.0 and -0.5 -> -0.0 + */ + + RoundTruncate, /**< + * No rounding, simply truncate any fraction + */ + + RoundPromote, /**< + * Use RoundCeil for positive and RoundFloor + * for negative values of @p this. + * e.g. 0.5 -> 1.0 and -0.5 -> -1.0 + */ + + RoundHalfDown, /**< + * Round up or down with the following + * constraints: + * 0.1 .. 0.5 -> 0.0 and 0.6 .. 0.9 -> 1.0 + */ + + RoundHalfUp, /**< + * Round up or down with the following + * constraints: + * 0.1 .. 0.4 -> 0.0 and 0.5 .. 0.9 -> 1.0 + */ + + RoundRound /**< + * Use RoundHalfDown for 0.1 .. 0.4 and + * RoundHalfUp for 0.6 .. 0.9. Use RoundHalfUp + * for 0.5 in case the resulting numerator + * is odd, RoundHalfDown in case the resulting + * numerator is even. + * e.g. 0.5 -> 0.0 and 1.5 -> 2.0 + */ + }; + + // Constructors / Destructor + /** + * This is the standard constructor of an AlkValue object. + * The value will be initialized to 0. + */ + AlkValue(); + + /// The destructor + ~AlkValue(); + + /// Copy constructor + AlkValue(const AlkValue &val); + + /** + * This constructor converts an int into an AlkValue. It can + * also convert a rational number when a @a denom is supplied. + * + * @param num numerator of the rational number + * @param denom denominator of the rational number (defaults to 1) + */ + explicit AlkValue(const int num, const unsigned int denom = 1); + + /** + * Convenience ctor for usage with mpz_class objects as numerator + * and denominator. + * + * @param num numerator of the rational number + * @param denom denominator of the rational number (defaults to 1) + */ + explicit AlkValue(const mpz_class &num, const mpz_class &denom); + + /** + * Convenience ctor to create an AlkValue object based on an mpq_class object + */ + explicit AlkValue(const mpq_class &val); + + /** + * This constructor converts a double into an AlkValue. In case + * a @a denom is supplied with a value different from zero, the + * @a val will be rounded to be based on the supplied @a denom. + * e.g. val = 1.234 and denom = 100 will construct an AlkValue + * of 1.23. The rounding method is @p RoundRound. + * + * @sa AlkValue::convertDenominator() + * + * @param val the double value + * @param denom the denominator of the resulting AlkValue + * + * @note In case one wants to use the number of decimal places + * to specify the length of the fractional part, use + * + * @code + * AlkValue alk(1.234, AlkValue::precisionToDenominator(2).get_ui()); + * // alk == 1.23 + * @endcode + */ + explicit AlkValue(const double &val, const unsigned int denom = 0); + + /** + * This constructor converts a QString into an AlkValue. + * Several formats are supported: + * + * -# prices in the form "8 5/16" + * -# our own toString() format + * -# others + + * Others may be enclosed in "(" and ")" and treated as negative. + * They may start or end with a dash and treated as negative. + * The decimal symbols is identified as provided in @a decimalSymbol. + * All other non-numeric characters are skipped + */ + AlkValue(const QString &str, const QChar &decimalSymbol); + + /** + * Returns the current value converted to the given @a denom (default is 100 + * or two digits of precision). The rounding method used is controlled by + * the @a how argument and defaults to @p RoundRound. + */ + AlkValue convertDenominator(const int denom = 100, const RoundingMethod how = RoundRound) const; + + /** + * This is a convenience function for convertDenom but instead of providing + * the new denominator one provides the number of digits for the @a precision. + * This value defaults to 2. The rounding method used is controlled by + * the @a how argument and defaults to @p RoundRound. + */ + AlkValue convertPrecision(const int precision = 2, const RoundingMethod how = RoundRound) const; + + // assignment operators + const AlkValue & operator=(const AlkValue &val); + const AlkValue & operator=(int num); + const AlkValue & operator=(double num); + const AlkValue & operator=(const QString &str); + + // comparison + bool operator==(const AlkValue &val) const; + bool operator!=(const AlkValue &val) const; + bool operator<(const AlkValue &val) const; + bool operator>(const AlkValue &val) const; + bool operator<=(const AlkValue &val) const; + bool operator>=(const AlkValue &val) const; + + // calculation + AlkValue operator+(const AlkValue &summand) const; + AlkValue operator-(const AlkValue &minuend) const; + AlkValue operator*(const AlkValue &factor) const; + AlkValue operator/(const AlkValue &divisor) const; + + AlkValue operator*(int factor) const; + + // unary operators + AlkValue operator-() const; + AlkValue & operator+= (const AlkValue &val); + AlkValue & operator-= (const AlkValue &val); + AlkValue & operator/= (const AlkValue &val); + AlkValue & operator*= (const AlkValue &val); + + // functions + + /// @return the absolute value of the AlkValue + AlkValue abs() const; + + /// @return QString representation in form '[-]num/denom'. + QString toString() const; + + /** + * This method transforms the AlkValue into its canonicalized + * form by reducing it to the smallest denominator. Example: + * 25/100 will be converted to 1/4. Use this function at the + * end of a longer calculation as all AlkValue methods require + * the object to be in the canonicalized form. For speed purposes + * the conversion is not performed before each operation. + * + * @return const reference to the object + */ + const AlkValue& canonicalize(); + + /// convert a denominator to a precision + /// e.g. 100 -> 2, 1000 -> 3 + /// in case of a negative @a denom, the function returns 0 + static mpz_class denominatorToPrecision(mpz_class denom); + + /// convert a precision to the corresponding denominator + /// e.g. 2 -> 100, 4 -> 10000 + /// in case of a negative @a prec, the function returns 1 + static mpz_class precisionToDenominator(mpz_class prec); + +protected: + /// \internal unit test class + friend class AlkValueTest; + + /// provides an access method to the private value storage + /// for derived classes + const mpq_class &valueRef() const; + mpq_class &valueRef(); + +private: + /// \internal d-pointer class. + class Private; + /// \internal d-pointer instance. + QSharedDataPointer<Private> d; + /// \internal shared zero value. + static QSharedDataPointer<AlkValue::Private>& sharedZero(); + + // The following methods are not implemented (yet) + // ALKIMIA_EXPORT friend QDataStream &operator<<(QDataStream &, const AlkValue &); + // ALKIMIA_EXPORT friend QDataStream &operator>>(QDataStream &, AlkValue &); +}; + +#endif + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/alkimia-7.0/src/libalkimia.pc.in new/alkimia-7.0.1/src/libalkimia.pc.in --- old/alkimia-7.0/src/libalkimia.pc.in 2018-01-05 14:47:41.677028838 +0100 +++ new/alkimia-7.0.1/src/libalkimia.pc.in 2018-03-15 20:28:26.737594656 +0100 @@ -14,6 +14,6 @@ Version: @ALKIMIA_LIB_VERSION@ Libs: -lalkimia@PC_TARGET_SUFFIX@ -Libs.private: -lgmp -l@PC_TARGET_QTPREFIX@Core -l@PC_TARGET_QTPREFIX@DBus -lstdc++ -Cflags: -I${includedir} +Libs.private: -l@PC_LIB@ -l@PC_TARGET_QTPREFIX@Core -l@PC_TARGET_QTPREFIX@DBus -lstdc++ +Cflags: -I${includedir} -I@MP_INCLUDE_DIR@
