File indexing completed on 2024-06-16 03:42:35

0001 /*
0002     File                 : Double2BigIntFilter.h
0003     Project              : AbstractColumn
0004     Description          : conversion filter double -> bigint
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2020 Stefan Gerlach <stefan.gerlach@uni.kn>
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #ifndef DOUBLE2BIGINT_FILTER_H
0011 #define DOUBLE2BIGINT_FILTER_H
0012 
0013 #include "../AbstractSimpleFilter.h"
0014 #include <QLocale>
0015 #include <cmath>
0016 
0017 //! conversion filter double -> int.
0018 class Double2BigIntFilter : public AbstractSimpleFilter {
0019     Q_OBJECT
0020 
0021 public:
0022     Double2BigIntFilter() {
0023     }
0024 
0025     qint64 bigIntAt(int row) const override {
0026         if (!m_inputs.value(0))
0027             return 0;
0028 
0029         double value = m_inputs.value(0)->valueAt(row);
0030 
0031         int result = 0;
0032         if (!std::isnan(value))
0033             result = (qint64)round(value);
0034         // DEBUG("Double2BigInt::integerAt() " << value << " -> " << result);
0035 
0036         return result;
0037     }
0038 
0039     //! Return the data type of the column
0040     AbstractColumn::ColumnMode columnMode() const override {
0041         return AbstractColumn::ColumnMode::BigInt;
0042     }
0043 
0044 protected:
0045     //! Using typed ports: only double inputs are accepted.
0046     bool inputAcceptable(int, const AbstractColumn* source) override {
0047         return source->columnMode() == AbstractColumn::ColumnMode::Double;
0048     }
0049 };
0050 
0051 #endif // ifndef DOUBLE2BIGINT_FILTER_H