1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
|
/**************************************************************************
* *
* Regina - A Normal Surface Theory Calculator *
* Computational Engine *
* *
* Copyright (c) 1999-2009, Ben Burton *
* For further details contact Ben Burton (bab@debian.org). *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* You should have received a copy of the GNU General Public *
* License along with this program; if not, write to the Free *
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
**************************************************************************/
/* end stub */
/*! \file nprogresstypes.h
* \brief Provides specific methods of representing progress reports.
*/
#ifndef __NPROGRESSTYPES_H
#ifndef __DOXYGEN
#define __NPROGRESSTYPES_H
#endif
#include "progress/nprogress.h"
namespace regina {
/**
* \weakgroup progress
* @{
*/
/**
* A progress report in which the current state of progress is stored as a
* string message.
*
* \ifacespython Not present; all progress classes communicate with
* external interfaces through the NProgress interface.
*/
class NProgressMessage : public NProgress {
private:
std::string message;
/**< The current state of progress. */
public:
/**
* Creates a new progress report with an empty progress message.
* Note that the internal mutex is not locked during construction.
*/
NProgressMessage();
/**
* Creates a new progress report with the given progress message.
* Note that the internal mutex is not locked during construction.
*
* @param newMessage the current state of progress.
*/
NProgressMessage(const std::string& newMessage);
/**
* Creates a new progress report with the given progress message.
* Note that the internal mutex is not locked during construction.
*
* @param newMessage the current state of progress.
*/
NProgressMessage(const char* newMessage);
/**
* Returns a reference to the current progress message.
*
* @return the current progress message.
*/
std::string getMessage() const;
/**
* Sets the current progress message to the given string.
*
* @param newMessage the new state of progress.
*/
void setMessage(const std::string& newMessage);
/**
* Sets the current progress message to the given string.
*
* @param newMessage the new state of progress.
*/
void setMessage(const char* newMessage);
protected:
virtual std::string internalGetDescription() const;
};
/**
* A simple structure used for passing around a numeric state of
* progress.
*/
struct NProgressStateNumeric {
long completed;
/**< The number of items that have already been completed. */
long outOf;
/**< The expected total number of items, or -1 if this is not known. */
/**
* Initialises a new structure using the given values.
*
* @param newCompleted the number of items that have already been
* completed.
* @param newOutOf the expected total number of items, or -1 if this
* is not known.
*/
NProgressStateNumeric(long newCompleted = 0, long newOutOf = -1);
};
/**
* A progress report in which the current state of progress is stored as
* a number of items completed.
* The expected total number of items can be optionally specified.
*
* \ifacespython Not present; all progress classes communicate with
* external interfaces through the NProgress interface.
*/
class NProgressNumber : public NProgress {
private:
long completed;
/**< The number of items completed. */
long outOf;
/**< The expected total number of items, or -1 if this
* total is not known. */
public:
/**
* Creates a new progress report containing the given details.
* Note that the internal mutex is not locked during construction.
*
* \pre The new number of items completed is non-negative.
* \pre If the new expected total is non-negative, then the new
* number of items completed is at most the new expected total.
*
* @param newCompleted the number of items completed; this
* defaults to 0.
* @param newOutOf the expected total number of items, or -1 if
* this total is not known (the default).
*/
NProgressNumber(long newCompleted = 0, long newOutOf = -1);
/**
* Returns the number of items completed.
*
* @return the number of items completed.
*/
long getCompleted() const;
/**
* Returns the expected total number of items.
*
* @return the expected total number of items, or -1 if this
* total is not known.
*/
long getOutOf() const;
/**
* Returns both the number of items completed and the expected
* total number of items.
*
* @return the current state of progress.
*/
NProgressStateNumeric getNumericState() const;
/**
* Sets the number of items completed.
*
* \pre The new number of items completed is non-negative.
* \pre If the expected total is non-negative, then the new
* number of items completed is at most the expected total.
*
* @param newCompleted the number of items completed.
*/
void setCompleted(long newCompleted);
/**
* Increases the number of items completed by the given amount.
*
* \pre If the expected total is non-negative, then the new
* total number of items completed is at most the expected total.
*
* @param extraCompleted the number of items to add to the number of
* items already completed.
*/
void incCompleted(unsigned long extraCompleted = 1);
/**
* Sets the expected total number of items.
*
* \pre If the new expected total is non-negative, then the
* new expected total is at least the number of items completed.
*
* @param newOutOf the expected total number of items, or -1 if
* this total is not known.
*/
void setOutOf(long newOutOf);
virtual bool isPercent() const;
protected:
virtual std::string internalGetDescription() const;
virtual double internalGetPercent() const;
};
/*@}*/
// Inline functions for NProgressMessage
inline NProgressMessage::NProgressMessage() : NProgress() {
}
inline NProgressMessage::NProgressMessage(const std::string& newMessage) :
NProgress(), message(newMessage) {
}
inline NProgressMessage::NProgressMessage(const char* newMessage) :
NProgress(), message(newMessage) {
}
inline std::string NProgressMessage::getMessage() const {
MutexLock(this);
changed = false;
return message;
}
inline void NProgressMessage::setMessage(const std::string& newMessage) {
MutexLock(this);
message = newMessage;
changed = true;
}
inline void NProgressMessage::setMessage(const char* newMessage) {
MutexLock(this);
message = newMessage;
changed = true;
}
inline std::string NProgressMessage::internalGetDescription() const {
MutexLock(this);
return message;
}
// Inline functions for NProgressStateNumeric
inline NProgressStateNumeric::NProgressStateNumeric(long newCompleted,
long newOutOf) : completed(newCompleted), outOf(newOutOf) {
}
// Inline functions for NProgressNumber
inline NProgressNumber::NProgressNumber(long newCompleted, long newOutOf) :
NProgress(), completed(newCompleted), outOf(newOutOf) {
}
inline long NProgressNumber::getCompleted() const {
MutexLock(this);
changed = false;
return completed;
}
inline long NProgressNumber::getOutOf() const {
MutexLock(this);
changed = false;
return outOf;
}
inline NProgressStateNumeric NProgressNumber::getNumericState() const {
MutexLock(this);
changed = false;
return NProgressStateNumeric(completed, outOf);
}
inline void NProgressNumber::setCompleted(long newCompleted) {
MutexLock(this);
completed = newCompleted;
changed = true;
}
inline void NProgressNumber::incCompleted(unsigned long extraCompleted) {
MutexLock(this);
completed += extraCompleted;
changed = true;
}
inline void NProgressNumber::setOutOf(long newOutOf) {
MutexLock(this);
outOf = newOutOf;
changed = true;
}
inline bool NProgressNumber::isPercent() const {
MutexLock(this);
return (outOf >= 0);
}
inline double NProgressNumber::internalGetPercent() const {
MutexLock(this);
return (outOf > 0 ? double(completed) * 100 / double(outOf) : double(0));
}
} // namespace regina
#endif
|