Commit 747510a6 authored by Håkan Wennlöf's avatar Håkan Wennlöf
Browse files

Tidied up a little

parent 807f506b
Loading
Loading
Loading
Loading
+6 −16
Original line number Diff line number Diff line
@@ -22,36 +22,26 @@ namespace allpix {
     * checked for overflow problems before the type is converted back to the original type.
     */
    // std::enable_if<std::is_integral_v<T>>
    template <typename T, std::enable_if_t<!std::is_integral_v<T>, bool> = true> T Units::get(T inp, const std::string& str) {
        std::cout << "Input value: " << inp << std::endl;
    template <typename T, std::enable_if_t<!std::is_integral_v<T>, bool> = true>
    T Units::get(T inp, const std::string& str) {
        UnitType out = static_cast<UnitType>(inp) * get(str);
        std::cout << "Middle value: " << out << std::endl;
        if(out > static_cast<UnitType>(std::numeric_limits<T>::max()) ||
           out < static_cast<UnitType>(std::numeric_limits<T>::lowest())) {
            throw std::overflow_error("unit conversion overflows the type");
        }
        std::cout << "Output value 1: " << out << std::endl;
        std::cout << "Output value final: " << static_cast<T>(out) << std::endl;
        return static_cast<T>(out);
        //return out;
    }

    template <typename T, std::enable_if_t<std::is_integral_v<T>, bool> = true> T Units::get(T inp, const std::string& str) {
        std::cout << "Input value int: " << inp << std::endl;
        UnitType out = static_cast<UnitType>(inp) * get(str);
        std::cout << "Middle value int: " << out << std::endl;
        if(out > static_cast<UnitType>(std::numeric_limits<T>::max()) ||
           out < static_cast<UnitType>(std::numeric_limits<T>::lowest())) {
            throw std::overflow_error("unit conversion overflows the type");
        }
        std::cout << "--------------- Output value assert: " << out << ", " << static_cast<T>(out) << std::endl;
        if(out != static_cast<T>(out)) {
            throw std::invalid_argument("Cannot use integer value with non-integer internal unit; the combination " + std::to_string(inp) + " " + str + " is invalid.");
            throw std::invalid_argument("Cannot use integer value with non-integer internal unit; the combination " +
                                        std::to_string(inp) + " " + str + " is invalid.");
        }
        assert(out == static_cast<T>(out));
        //std::cout << "--------------- Output value assert: " << out << ", " << static_cast<T>(out) << std::endl;
        std::cout << "Output value 1 int: " << out << std::endl;
        std::cout << "Output value final int: " << static_cast<T>(out) << std::endl;
        return static_cast<T>(out);
    }