bkcrack 1.8.1
Crack legacy zip encryption with Biham and Kocher's known plaintext attack.
Progress.hpp
1#ifndef BKCRACK_PROGRESS_HPP
2#define BKCRACK_PROGRESS_HPP
3
4#include <atomic>
5#include <concepts>
6#include <iostream>
7#include <mutex>
8
11{
12public:
14 enum class State
15 {
16 Normal,
17 Canceled,
18 EarlyExit
19 };
20
22 explicit Progress(std::ostream& os);
23
25 virtual ~Progress() = default;
26
29 template <std::invocable<std::ostream&> F>
30 void log(F f)
31 {
32 const auto lock = std::scoped_lock{m_os_mutex};
33 beforeLog(m_os);
34 f(m_os);
35 }
36
37 std::atomic<State> state = State::Normal;
38 std::atomic<int> done = 0;
39 std::atomic<int> total = 0;
40
41protected:
42 virtual void beforeLog(std::ostream&) {}
43
44 std::mutex m_os_mutex;
45 std::ostream& m_os;
46};
47
48#endif // BKCRACK_PROGRESS_HPP
std::atomic< int > done
Number of steps already done.
Definition Progress.hpp:38
std::atomic< State > state
State of the long operation.
Definition Progress.hpp:37
void log(F f)
Definition Progress.hpp:30
virtual ~Progress()=default
Destructor.
std::atomic< int > total
Total number of steps.
Definition Progress.hpp:39
State
Possible states of a long operation.
Definition Progress.hpp:15
@ Normal
The operation is ongoing or is fully completed.
Definition Progress.hpp:16
Progress(std::ostream &os)
Constructor.