From 48098b596de95dfb8d49ffed07c0ffd74a906b07 Mon Sep 17 00:00:00 2001 From: Lanchid Date: Sat, 22 Dec 2012 20:52:08 +0100 Subject: [PATCH] Removed the parameter from const templates, as types can be stated explicitly (see documentation) --- src/formula/ProbabilisticIntervalOperator.h | 4 +- src/modelChecker/EigenDtmcPrctlModelChecker.h | 14 ++-- src/storage/SquareSparseMatrix.h | 7 +- src/utility/ConstTemplates.h | 76 ++++++++++++------- 4 files changed, 59 insertions(+), 42 deletions(-) diff --git a/src/formula/ProbabilisticIntervalOperator.h b/src/formula/ProbabilisticIntervalOperator.h index 5fd2943af..7a832c480 100644 --- a/src/formula/ProbabilisticIntervalOperator.h +++ b/src/formula/ProbabilisticIntervalOperator.h @@ -49,8 +49,8 @@ public: * Empty constructor */ ProbabilisticIntervalOperator() { - upper = mrmc::utility::constGetZero(upper); - lower = mrmc::utility::constGetZero(lower); + upper = mrmc::utility::constGetZero(); + lower = mrmc::utility::constGetZero(); pathFormula = NULL; } diff --git a/src/modelChecker/EigenDtmcPrctlModelChecker.h b/src/modelChecker/EigenDtmcPrctlModelChecker.h index 9a1760292..845b93c4a 100644 --- a/src/modelChecker/EigenDtmcPrctlModelChecker.h +++ b/src/modelChecker/EigenDtmcPrctlModelChecker.h @@ -64,9 +64,7 @@ public: std::vector* result = new std::vector(stateCount); - // Dummy Type variable for const templates - Type dummy; - mrmc::utility::setVectorValues(result, *rightStates, mrmc::utility::constGetOne(dummy)); + mrmc::utility::setVectorValues(result, *rightStates, mrmc::utility::constGetOne()); Type *p = &((*result)[0]); // get the address storing the data for result MapType vectorMap(p, result->size()); // vectorMap shares data @@ -94,8 +92,8 @@ public: // Create the vector with which to multiply and initialize it correctly. std::vector x(this->getModel().getNumberOfStates()); - Type dummy; - mrmc::utility::setVectorValues(&x, *nextStates, mrmc::utility::constGetOne(dummy)); + + mrmc::utility::setVectorValues(&x, *nextStates, mrmc::utility::constGetOne()); // Delete not needed next states bit vector. delete nextStates; @@ -213,10 +211,8 @@ public: delete eigenSubMatrix; } - // Dummy Type variable for const templates - Type dummy; - mrmc::utility::setVectorValues(result, notExistsPhiUntilPsiStates, mrmc::utility::constGetZero(dummy)); - mrmc::utility::setVectorValues(result, alwaysPhiUntilPsiStates, mrmc::utility::constGetOne(dummy)); + mrmc::utility::setVectorValues(result, notExistsPhiUntilPsiStates, mrmc::utility::constGetZero()); + mrmc::utility::setVectorValues(result, alwaysPhiUntilPsiStates, mrmc::utility::constGetOne()); return result; } diff --git a/src/storage/SquareSparseMatrix.h b/src/storage/SquareSparseMatrix.h index cbb56f196..cd467b660 100644 --- a/src/storage/SquareSparseMatrix.h +++ b/src/storage/SquareSparseMatrix.h @@ -742,12 +742,12 @@ public: uint_fast64_t rowEnd = rowIndications[row + 1]; while (rowStart < rowEnd) { - valueStorage[rowStart] = mrmc::utility::constGetZero(valueStorage[rowStart]); + valueStorage[rowStart] = mrmc::utility::constGetZero(); ++rowStart; } // Set the element on the diagonal to one. - diagonalStorage[row] = mrmc::utility::constGetOne(diagonalStorage[row]); + diagonalStorage[row] = mrmc::utility::constGetOne(); return true; } @@ -885,10 +885,9 @@ public: // no entries apart from those on the diagonal resultDinv->initialize(0); // copy diagonal entries to other matrix - T dummy; for (int i = 0; i < rowCount; ++i) { resultDinv->addNextValue(i, i, resultLU->getValue(i, i)); - resultLU->getValue(i, i) = mrmc::utility::constGetZero(&dummy); + resultLU->getValue(i, i) = mrmc::utility::constGetZero(); } return new mrmc::storage::JacobiDecomposition(resultLU, resultDinv); diff --git a/src/utility/ConstTemplates.h b/src/utility/ConstTemplates.h index 8a4abef6a..2547764df 100644 --- a/src/utility/ConstTemplates.h +++ b/src/utility/ConstTemplates.h @@ -17,75 +17,97 @@ namespace utility { * As (at least) gcc has problems to use the correct template by the return value * only, the function gets a pointer as a parameter to infer the return type. * - * Parameter + * @note + * The template parameter is just inferred by the return type; GCC is not able to infer this + * automatically, hence the type should always be stated explicitly (e.g. @c constGetZero();) * - * The parameter is a reference which is used to infer the return type (So, if you want - * the return value to be of type double, the parameter has to be a double variable). - * In most cases, it is a good choice to use the the variable that is to be set. + * @return Value 0, fit to the return type */ template -static inline _Scalar constGetZero(_Scalar&) { +static inline _Scalar constGetZero() { return _Scalar(0); } /*! @cond TEMPLATE_SPECIALIZATION - * (exclude the specializations from the documentation) */ + * (By default, the template specifications are not included in the documentation) + */ + +/*! + * Template specification for int_fast32_t + * @return Value 0, fit to the type int_fast32_t + */ template <> -inline int_fast32_t constGetZero(int_fast32_t&) { +inline int_fast32_t constGetZero() { return 0; } -/*! @cond TEMPLATE_SPECIALIZATION - * (exclude the specializations from the documentation) */ +/*! + * Template specification for uint_fast64_t + * @return Value 0, fit to the type uint_fast64_t + */ template <> -inline uint_fast64_t constGetZero(uint_fast64_t&) { +inline uint_fast64_t constGetZero() { return 0; } -/*! @cond TEMPLATE_SPECIALIZATION - * Specialization of constGetZero for double +/*! + * Template specification for double + * @return Value 0.0, fit to the type double */ template <> -inline double constGetZero(double&) { +inline double constGetZero() { return 0.0; } + /*! @endcond */ /*! - * Returns a constant value of 0 that is fit to the type it is being written to. + * Returns a constant value of 1 that is fit to the type it is being written to. * As (at least) gcc has problems to use the correct template by the return value * only, the function gets a pointer as a parameter to infer the return type. * - * Parameter + * @note + * The template parameter is just inferred by the return type; GCC is not able to infer this + * automatically, hence the type should always be stated explicitly (e.g. @c constGetOne();) * - * The parameter is a reference which is used to infer the return type (So, if you want - * the return value to be of type double, the parameter has to be a double variable). - * In most cases, it is a good choice to use the the variable that is to be set. */ + * @return Value 1, fit to the return type + */ template -static inline _Scalar constGetOne(_Scalar&) { +static inline _Scalar constGetOne() { return _Scalar(1); } /*! @cond TEMPLATE_SPECIALIZATION - * (exclude the specializations from the documentation) */ + * (By default, the template specifications are not included in the documentation) + */ + +/*! + * Template specification for int_fast32_t + * @return Value 1, fit to the type int_fast32_t + */ template<> -inline int_fast32_t constGetOne(int_fast32_t&) { +inline int_fast32_t constGetOne() { return 1; } -/*! @cond TEMPLATE_SPECIALIZATION - * (exclude the specializations from the documentation) */ +/*! + * Template specification for uint_fast64_t + * @return Value 1, fit to the type uint_fast61_t + */ template<> -inline uint_fast64_t constGetOne(uint_fast64_t&) { +inline uint_fast64_t constGetOne() { return 1; } -/*! @cond TEMPLATE_SPECIALIZATION - * (exclude the specializations from the documentation) */ +/*! + * Template specification for double + * @return Value 1.0, fit to the type double + */ template<> -inline double constGetOne(double&) { +inline double constGetOne() { return 1.0; } + /*! @endcond */ } //namespace utility