File indexing completed on 2024-05-12 15:57:03

0001 /*
0002  *  SPDX-FileCopyrightText: 2017 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef KISROLLINGMEANACCUMULATORWRAPPER_H
0008 #define KISROLLINGMEANACCUMULATORWRAPPER_H
0009 
0010 #include <QtGlobal>
0011 #include <QScopedPointer>
0012 #include "kritaglobal_export.h"
0013 
0014 /**
0015  * @brief A simple wrapper class that hides boost includes from QtCreator preventing it
0016  * from crashing when one adds boost's accumulator into a file
0017  */
0018 
0019 class KRITAGLOBAL_EXPORT KisRollingMeanAccumulatorWrapper
0020 {
0021 public:
0022     /**
0023      * Create a rolling mean accumulator with window \p windowSize
0024      */
0025     KisRollingMeanAccumulatorWrapper(int windowSize);
0026     ~KisRollingMeanAccumulatorWrapper();
0027 
0028     /**
0029      * Add \p value to a set of numbers
0030      */
0031     void operator()(qreal value);
0032 
0033     /**
0034      * Get rolling mean of the numbers passed to the operator. If there are no elements
0035      * in the rolling window, returns NaN.
0036      */
0037     qreal rollingMean() const;
0038 
0039     /**
0040      * Get rolling mean of the numbers passed to the operator. If there are no elements
0041      * in the rolling window, returns 0.
0042      */
0043     qreal rollingMeanSafe() const;
0044 
0045     /**
0046      * Get the number of elements in the rolling window
0047      */
0048     int rollingCount() const;
0049 
0050     /**
0051      * Reset  accumulator and any stored value
0052      */
0053     void reset(int windowSize);
0054 
0055 private:
0056     struct Private;
0057     const QScopedPointer<Private> m_d;
0058 };
0059 
0060 #endif // KISROLLINGMEANACCUMULATORWRAPPER_H