Supporting utilities for the libmagicxx library.
More...
|
| SharedProgressTrackerT | Recognition::Utility::MakeSharedProgressTracker (std::uint64_t total_steps=1u) noexcept |
| | Factory function to create a shared ProgressTracker.
|
template<RangeContainer ContainerT, typename StringConverterT>
requires StringConverter<typename ContainerT::value_type, StringConverterT> |
| std::string | Recognition::Utility::ToString (const ContainerT &container, const std::string &value_separator, StringConverterT string_converter) |
| | Convert a container to a string using a custom converter.
|
| std::string | Recognition::Utility::ToString (const FileContainer auto &container, const std::string &separator=", ") |
| | Convert a FileContainer to a string.
|
Supporting utilities for the libmagicxx library.
The utility module provides foundational components used by the Magic class and also available for direct use by library consumers.
Concepts
| Concept | Description |
| RangeContainer | Types satisfying std::ranges::range with value_type |
| StringConverter | Callables converting a value to std::string |
| FileContainer | Containers of std::filesystem::path with push_back() |
Classes
| Class | Description |
| Percentage | Represents a percentage value (0-100%) |
| ProgressTracker | Thread-safe progress monitoring |
Functions
| Function | Description |
| ToString() | Convert containers to strings with custom separator |
| MakeSharedProgressTracker() | Factory for shared progress trackers |
- See also
- Recognition::Utility namespace
-
Recognition::Magic::ProgressTrackerT
◆ SharedProgressTrackerT
Shared pointer type for ProgressTracker.
This type alias is used throughout the library for thread-safe sharing of progress trackers between threads.
- See also
- ProgressTracker
-
MakeSharedProgressTracker()
- Since
- 10.0.0
◆ MakeSharedProgressTracker()
Factory function to create a shared ProgressTracker.
Creates a ProgressTracker wrapped in a shared_ptr for thread-safe sharing between the producer (worker) and consumer (monitor) threads.
- Parameters
-
| [in] | total_steps | Total number of steps (minimum 1, default 1). |
- Returns
- A shared pointer to the newly created ProgressTracker.
auto future = std::async([tracker] {
for (int i = 0; i < 100; ++i) {
DoStep();
tracker->Advance();
}
});
while (!tracker->IsCompleted()) {
std::println("{}", tracker->GetCompletionPercentage().ToString());
}
SharedProgressTrackerT MakeSharedProgressTracker(std::uint64_t total_steps=1u) noexcept
Factory function to create a shared ProgressTracker.
Definition progress_tracker.hpp:440
- See also
- SharedProgressTrackerT
-
ProgressTracker
- Since
- 10.0.0
- Examples
- magic_examples.cpp.
◆ ToString() [1/2]
template<RangeContainer ContainerT, typename StringConverterT>
requires StringConverter<typename ContainerT::value_type, StringConverterT>
| std::string Recognition::Utility::ToString |
( |
const ContainerT & | container, |
|
|
const std::string & | value_separator, |
|
|
StringConverterT | string_converter ) |
|
inlinenodiscard |
Convert a container to a string using a custom converter.
Converts each element in the container to a string using the provided converter function, then joins them with the specified separator.
- Template Parameters
-
| ContainerT | Container type satisfying RangeContainer. |
| StringConverterT | Callable type satisfying StringConverter. |
- Parameters
-
| [in] | container | The container to convert. |
| [in] | value_separator | Separator string between elements. |
| [in] | string_converter | Callable that converts each element to string. |
- Returns
- All elements joined as a string, or empty string if container is empty.
std::vector<int> numbers = {1, 2, 3};
auto result =
ToString(numbers,
", ", [](
int x) {
return std::to_string(x);
});
std::string ToString(const ContainerT &container, const std::string &value_separator, StringConverterT string_converter)
Convert a container to a string using a custom converter.
Definition utility.hpp:192
- Since
- 10.0.0
◆ ToString() [2/2]
| std::string Recognition::Utility::ToString |
( |
const FileContainer auto & | container, |
|
|
const std::string & | separator = ", " ) |
|
inlinenodiscard |
Convert a FileContainer to a string.
Converts each path in the container to its string representation and joins them with the specified separator.
- Parameters
-
| [in] | container | The container of file paths to convert. |
| [in] | separator | Separator string between paths (default: ", "). |
- Returns
- All paths joined as a string, or empty string if container is empty.
std::vector<std::filesystem::path> files = {
"/path/to/file1.txt",
"/path/to/file2.png"
};
std::string newlineSeparated =
ToString(files,
"\n");
- See also
- FileContainer
- Since
- 10.0.0