Libmagicxx v10.0.3
A modern C++23 wrapper for libmagic — the library that powers the Unix file command.
Loading...
Searching...
No Matches
progress_tracker.hpp File Reference

Thread-safe progress tracking for batch file operations. More...

#include <chrono>
#include <condition_variable>
#include <mutex>
#include "percentage.hpp"
Include dependency graph for progress_tracker.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Recognition::Utility::ProgressTracker
 Thread-safe tracker for monitoring multi-step job progress. More...
class  Recognition::Utility::MarkTrackerAsCompleted
 RAII helper that marks a ProgressTracker as completed on destruction. More...
class  Recognition::Utility::AdvanceTracker
 RAII helper that advances a ProgressTracker on destruction. More...

Namespaces

namespace  Recognition
 Root namespace for the libmagicxx library.
namespace  Recognition::Utility
 Utility components for the libmagicxx library.

Typedefs

using Recognition::Utility::SharedProgressTrackerT = std::shared_ptr<ProgressTracker>
 Shared pointer type for ProgressTracker.

Functions

SharedProgressTrackerT Recognition::Utility::MakeSharedProgressTracker (std::uint64_t total_steps=1u) noexcept
 Factory function to create a shared ProgressTracker.

Detailed Description

Thread-safe progress tracking for batch file operations.

This file provides classes for tracking the progress of long-running operations such as batch file identification. The ProgressTracker class is thread-safe and can be shared between the worker thread and the UI/monitoring thread.

Overview

  • ProgressTracker: Core class for tracking completed/total steps
  • SharedProgressTrackerT: Shared pointer type for thread-safe sharing
  • MakeSharedProgressTracker(): Factory function for creating trackers
  • MarkTrackerAsCompleted: RAII helper for completion marking
  • AdvanceTracker: RAII helper for automatic step advancement

Usage Example

using namespace Recognition;
using namespace std::chrono_literals;
// Create a shared progress tracker
// Start batch identification in background
auto future = std::async([tracker] {
return magic.IdentifyFiles("/path/to/directory", tracker);
});
// Monitor progress in main thread
while (!tracker->IsCompleted()) {
auto percentage = tracker->GetCompletionPercentage();
std::println("Progress: {} ({}/{})",
percentage.ToString(),
tracker->GetCompletedSteps(),
tracker->GetTotalSteps());
std::this_thread::sleep_for(100ms);
}
auto results = future.get();
A modern C++23 wrapper for libmagic — the library that powers the Unix file command.
Definition magic.hpp:216
FileTypeMapT IdentifyFiles(const std::filesystem::path &directory, std::filesystem::directory_options option=std::filesystem::directory_options::follow_directory_symlink) const
Identify all files in a directory.
Definition magic.hpp:1037
@ Mime
Definition magic.hpp:328
SharedProgressTrackerT MakeSharedProgressTracker(std::uint64_t total_steps=1u) noexcept
Factory function to create a shared ProgressTracker.
Definition progress_tracker.hpp:440
Root namespace for the libmagicxx library.
See also
Percentage
Magic::IdentifyFiles()