| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2003-2015 Dmitry Tsarkov and The University of Manchester |
| 3 | Copyright (C) 2015-2017 Dmitry Tsarkov |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #ifndef PROGRESSINDICATORINTERFACE_H |
| 21 | #define PROGRESSINDICATORINTERFACE_H |
| 22 | |
| 23 | /// interface of the progress indicator |
| 24 | class ProgressIndicatorInterface |
| 25 | { |
| 26 | protected: // members |
| 27 | /// limit of the progress: indicate [0..uLimit] |
| 28 | unsigned long uLimit = 0; |
| 29 | /// current value of an indicator |
| 30 | unsigned long uCurrent = 0; |
| 31 | |
| 32 | protected: // methods |
| 33 | /// initial exposure method: can be overridden in derived classes |
| 34 | virtual void initExposure ( void ) {} |
| 35 | /// indicate current value somehow |
| 36 | virtual void expose ( void ) = 0; |
| 37 | /// check whether the limit is reached |
| 38 | bool checkMax ( void ) |
| 39 | { |
| 40 | if ( uCurrent > uLimit ) |
| 41 | { |
| 42 | uCurrent = uLimit; |
| 43 | return true; |
| 44 | } |
| 45 | else |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | public: // interface |
| 50 | /// empty c'tor |
| 51 | ProgressIndicatorInterface() = default; |
| 52 | /// init c'tor |
| 53 | explicit ProgressIndicatorInterface ( unsigned long limit ) { setLimit (limit); } |
| 54 | /// empty d'tor |
| 55 | virtual ~ProgressIndicatorInterface() = default; |
| 56 | |
| 57 | /// set indicator to a given VALUE |
| 58 | void setIndicator ( unsigned long value ) |
| 59 | { |
| 60 | if ( uCurrent != value ) |
| 61 | { |
| 62 | uCurrent = value; |
| 63 | checkMax (); |
| 64 | expose (); |
| 65 | } |
| 66 | } |
| 67 | /// increment current value of an indicator to DELTA steps |
| 68 | void incIndicator ( unsigned long delta = 1 ) { setIndicator(uCurrent+delta); } |
| 69 | /// set indicator to 0 |
| 70 | void reset ( void ) { setIndicator (0); } |
| 71 | /// set the limit of an indicator to a given VALUE |
| 72 | void setLimit ( unsigned long limit ) { uLimit = limit; reset(); initExposure(); } |
| 73 | }; // ProgressIndicatorInterface |
| 74 | |
| 75 | #endif |