diff options
author | Daniel_Burrows@alumni.brown.edu <Daniel_Burrows@alumni.brown.edu> | 2010-05-31 13:51:21 -0700 |
---|---|---|
committer | Daniel Burrows <Daniel Burrows Daniel_Burrows@alumni.brown.edu> | 2010-06-08 20:24:21 -0700 |
commit | d9f47c054877089d98621cc8a5dd312e0f2358c2 (patch) | |
tree | 150b4dd4b35b073580c2dcb0afe01b6e19f355a3 /src | |
parent | dc7eb7a20f57b8b37a4de7e1fce7c783f85b061f (diff) | |
download | aptitude-d9f47c054877089d98621cc8a5dd312e0f2358c2.tar.gz |
Make progress_info objects mutable.
Currently the type can't be changed, because that could introduce weirdness
into the API and it's not really necessary.
The reason for making them mutable is that it's common to want to update
the current progress fraction in a tight loop. By using mutable objects,
we can avoid having to constantly copy the status string. I clocked nearly
a 10% speed increase with this change, and it makes the overhead from the
progress display negligible in my tests.
Diffstat (limited to 'src')
-rw-r--r-- | src/generic/util/progress_info.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/generic/util/progress_info.h b/src/generic/util/progress_info.h index 0c21ac97..85ad2119 100644 --- a/src/generic/util/progress_info.h +++ b/src/generic/util/progress_info.h @@ -80,6 +80,22 @@ namespace aptitude progress_type get_type() const { return type; } double get_progress_fraction() const { return progress_fraction; } + /** \brief Set the current progress of the operation. + * + * This value is meaningful only when the type is "bar"; this + * method has no effect for other types of progress_info + * objects. + * + * \param new_fraction How close to completion the operation + * is, on a scale of 0 (not started) to 1 + * (finished). + */ + void set_progress_fraction(double new_fraction) + { + if(type == progress_type_bar) + progress_fraction = new_fraction; + } + int get_progress_percent_int() const { int rval = (int) (100 * progress_fraction); @@ -91,7 +107,13 @@ namespace aptitude else return rval; } + const std::string &get_progress_status() const { return progress_status; } + /** \brief Set the status message. */ + void set_progress_status(const std::string &msg) + { + progress_status = msg; + } }; // @} |