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 {
19 };
20
22 explicit Progress(std::ostream& os);
23
26 template <std::invocable<std::ostream&> F>
27 void log(F f)
28 {
29 const auto lock = std::scoped_lock{m_os_mutex};
30 f(m_os);
31 }
32
33 std::atomic<State> state = State::Normal;
34 std::atomic<int> done = 0;
35 std::atomic<int> total = 0;
36
37private:
38 std::mutex m_os_mutex;
39 std::ostream& m_os;
40};
41
42#endif // BKCRACK_PROGRESS_HPP
std::atomic< int > done
Number of steps already done.
Definition Progress.hpp:34
std::atomic< State > state
State of the long operation.
Definition Progress.hpp:33
void log(F f)
Definition Progress.hpp:27
std::atomic< int > total
Total number of steps.
Definition Progress.hpp:35
State
Possible states of a long operation.
Definition Progress.hpp:15
@ Canceled
The operation has been canceled externally.
Definition Progress.hpp:17
@ EarlyExit
The operation stopped after a partial result was found.
Definition Progress.hpp:18
@ Normal
The operation is ongoing or is fully completed.
Definition Progress.hpp:16
Progress(std::ostream &os)
Constructor.