File: ProgressWriter.h

package info (click to toggle)
macromoleculebuilder 4.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 118,996 kB
  • sloc: cpp: 23,722; python: 5,098; ansic: 2,101; awk: 145; perl: 144; makefile: 40; sh: 38
file content (71 lines) | stat: -rw-r--r-- 1,615 bytes parent folder | download | duplicates (4)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef ProgressWriter_H
#define ProgressWriter_H

#ifdef _WINDOWS
#include <windows.h>
#endif // _WINDOWS

#include "ExportMacros.h"
#include <memory>
#include <string>

class MMB_EXPORT AbstractProgressWriter {
public:
    enum class State {
        NOT_STARTED,
        PREPARING,
        RUNNING,
        FINISHED,
        FAILED
    };

    virtual ~AbstractProgressWriter();

    virtual void setTotalSteps(const int total) = 0;
    virtual void update(const State s) = 0;
    virtual void update(const State s, const int step) = 0;
};

class MMB_EXPORT DummyProgressWriter : public AbstractProgressWriter {
public:
    // Dummy writer that does absolutely nothing
    void setTotalSteps(const int total) override;
    void update(const State s) override;
    void update(const State s, const int completed) override;
};

class MMB_EXPORT ProgressWriter : public AbstractProgressWriter {
public:
    explicit ProgressWriter(const std::string &path);
    ~ProgressWriter();
    void setTotalSteps(const int total) override;
    void update(const State s) override;
    void update(const State s, const int step) override;

private:
    void write(const bool wait);

#ifdef _WINDOWS
    std::string _path;
#else
    int _output;
#endif // _WINDOWS

    State _state;
    int _step;
    int _totalSteps;
};

class MMB_EXPORT GlobalProgressWriter {
public:
    static void close();
    static void initialize(const std::string &path);
    static AbstractProgressWriter & get();
    static bool isInitialized();

private:
    static std::unique_ptr<AbstractProgressWriter> _writer;
};

#endif // ProgressWriter_H