File: stdoutreporter.h

package info (click to toggle)
aoflagger 3.4.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,960 kB
  • sloc: cpp: 83,076; python: 10,187; sh: 260; makefile: 178
file content (30 lines) | stat: -rw-r--r-- 923 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef UTIL_PROGRESS_STD_OUT_REPORTER_H_
#define UTIL_PROGRESS_STD_OUT_REPORTER_H_

#include "progresslistener.h"

#include <exception>
#include <string>
#include <iostream>

class StdOutReporter final : public ProgressListener {
 public:
  void OnStartTask(const std::string& description) override {
    std::cout << description << "...\n";
  }
  void OnProgress(size_t progress, size_t max_progress) override {
    const unsigned two_percent = (max_progress + 49) / 50;
    if ((progress % two_percent) == 0) {
      if (((progress / two_percent) % 5) == 0)
        std::cout << (100 * progress / max_progress) << std::flush;
      else
        std::cout << '.' << std::flush;
    }
  }
  void OnFinish() override { std::cout << "100\n"; }
  void OnException(std::exception& thrown_exception) override {
    std::cerr << "ERROR! " << thrown_exception.what() << '\n';
  }
};

#endif  // UTIL_PROGRESS_STD_OUT_REPORTER_H_