bkcrack: include/bkcrack/Progress.hpp Source File

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
10 class Progress
11{
12public:
14 enum class State
15 {
16 Normal,
17 Canceled,
18 EarlyExit
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
Progress::done
std::atomic< int > done
Number of steps already done.
Definition Progress.hpp:34
Progress::state
std::atomic< State > state
State of the long operation.
Definition Progress.hpp:33
Progress::log
void log(F f)
Definition Progress.hpp:27
Progress::total
std::atomic< int > total
Total number of steps.
Definition Progress.hpp:35
Progress::State
State
Possible states of a long operation.
Definition Progress.hpp:15
Progress::State::Canceled
@ Canceled
The operation has been canceled externally.
Definition Progress.hpp:17
Progress::State::EarlyExit
@ EarlyExit
The operation stopped after a partial result was found.
Definition Progress.hpp:18
Progress::State::Normal
@ Normal
The operation is ongoing or is fully completed.
Definition Progress.hpp:16
Progress::Progress
Progress(std::ostream &os)
Constructor.