xtd 0.2.0
Loading...
Searching...
No Matches
xtd::iprogress< type_t > Class Template Referenceabstract
Inheritance diagram for xtd::iprogress< type_t >:
xtd::interface

Definition

template<typename type_t>
class xtd::iprogress< type_t >

Defines a provider for progress updates.

Namespace
xtd
Library
xtd.core
Template Parameters
type_tThe type of progress update value. This type parameter is contravariant. That is, you can use either the type you specified or any type that is less derived The following example shows how to use xtd::iprogress interface.
#include <xtd/as>
#include <xtd/console>
#include <xtd/iprogress>
#include <xtd/math>
using namespace xtd;
class generic_progress {
public:
generic_progress() = default;
generic_progress(int val, int min = 0, int max = 100, const string& msg = "") : message_(msg) {
minimum(min);
maximum(max);
value(val);
}
int maximum() const noexcept {return maximum_;}
generic_progress& maximum(int maximum) noexcept {
maximum_ = maximum;
minimum_ = math::min(minimum(), maximum);
value_ = math::min(value(), maximum);
return *this;
}
int minimum() const noexcept {return minimum_;}
generic_progress& minimum(int minimum) noexcept {
minimum_ = minimum;
maximum_ = math::max(maximum(), minimum);
value_ = math::max(value(), minimum);
return *this;
}
const string& message() const noexcept {return message_;}
generic_progress& message(const string& message) noexcept {
message_ = message;
return *this;
}
float percent() const noexcept {return maximum_ - minimum_ ? as<float>(value() - minimum()) / (maximum() - minimum()) : 1;}
generic_progress& increment(int increment) noexcept {
value(value() + increment);
return *this;
}
generic_progress& perform_step() noexcept {return increment(step());}
generic_progress& perform_step(const string& message) noexcept {
message_ = message;
return perform_step();
}
int value() const noexcept {return value_;}
generic_progress& value(int value) noexcept {
value_ = math::clamp(value, minimum(), maximum());
return *this;
}
int step() const noexcept {return step_;}
generic_progress& step(int step) noexcept {
step_ = step;
return *this;
}
private:
int minimum_ = 0;
int maximum_ = 100;
int step_ = 1;
int value_ = 0;
string message_;
};
class print_generic_progress : public iprogress<generic_progress> {
public:
print_generic_progress() = default;
void report(const generic_progress& value) noexcept override {
console::write_line("completion={,3}%, message=\"{}\"", as<int>(value.percent() * 100), value.message());
}
};
auto main() -> int {
console::write_line("Started");
auto print_progress = print_generic_progress {};
auto progress = generic_progress {0, 0, 5, "Initialized"};
print_progress.report(progress);
// Open device....
print_progress.report(progress.perform_step("Device opened"));
// Update 1 device....
print_progress.report(progress.perform_step("Device updated 1"));
// Update 2 device....
print_progress.report(progress.perform_step("Device updated 2"));
// Update 3 device....
print_progress.report(progress.perform_step("Device updated 3"));
// Close device....
print_progress.report(progress.perform_step("Device closed"));
}
// The example displays output similar to the following:
//
// Started
// completion= 0%, message="Initialized"
// completion= 20%, message="Device opened"
// completion= 40%, message="Device updated 1"
// completion= 60%, message="Device updated 2"
// completion= 80%, message="Device updated 3"
// completion=100%, message="Device closed"
// Ended
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
Defines a provider for progress updates.
Definition iprogress.h:19
@ percent
The control should be sized as a percentage of the parent container.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Examples
iprogress.cpp.

Public Methods

virtual void report (const type_t &value) noexcept=0
 Reports a progress update.
 

Member Function Documentation

◆ report()

template<typename type_t >
virtual void xtd::iprogress< type_t >::report ( const type_t &  value)
pure virtualnoexcept

Reports a progress update.

Parameters
valueThe value of the updated progress.

The documentation for this class was generated from the following file: