19 #pragma warning(disable : 4103) 20 #include <boost/timer/timer.hpp> 80 if (a_percentComplete >
m_p->m_percentComplete + .02)
82 double elapsedTime =
m_p->ElapsedTimeInSeconds();
83 m_p->m_percentComplete = a_percentComplete;
87 double rem =
m_p->EstimatedTimeRemainingInSec(a_percentComplete, elapsedTime);
100 (void)a_remainingSeconds;
108 (void)a_elapsedSeconds;
118 m_p->BeginOperationString();
184 boost::timer::cpu_times
const elapsed_times(
m_timer.elapsed());
185 boost::timer::nanosecond_type time = elapsed_times.wall;
186 const double NANO_PER_SEC = 1e9;
187 double seconds = time / NANO_PER_SEC;
198 if (a_percentComplete < .01)
201 double percentRemaining = 1 - a_percentComplete;
202 double timeRemaining = (a_elapsedTime * percentRemaining) / a_percentComplete;
203 return timeRemaining;
211 #include <boost/thread/thread.hpp> 233 m_percentComplete = a_percentComplete;
234 int i = (int)(xms::Round(m_percentComplete * 100));
235 m_info <<
"Percent complete: " << i <<
"%.\n";
242 if (!m_info.str().empty())
244 m_info <<
"Begin operation: " << a_operation <<
".\n";
251 m_elapsedSeconds = a_elapsedSeconds;
252 int i = (int)(xms::Round(m_elapsedSeconds * 10));
253 m_info <<
"Elapsed seconds: 0." << i <<
".\n";
262 m_remainingSeconds = a_secondsRemaining;
263 int i = (int)(xms::Round(m_remainingSeconds * 10));
264 m_info <<
"Time remaining (seconds): 0." << i <<
".\n";
287 const long long tenth_second = 100000000LL;
288 while (a_timer.elapsed().wall < tenth_second * a_count)
302 boost::timer::cpu_timer timer;
305 m_prog->BeginOperationString(
"Generating mesh points");
306 for (
int i = 0; i < 4; ++i)
308 WaitForNextTenthSecond(timer, count);
309 m_prog->ProgressStatus((
double)(i + 1) / 4);
312 m_prog->BeginOperationString(
"Triangulating");
313 for (
int i = 0; i < 5; ++i)
315 WaitForNextTenthSecond(timer, count);
316 m_prog->ProgressStatus((
double)(i + 1) / 5);
319 m_prog->BeginOperationString(
"Generating unstructured grid");
320 for (
int i = 0; i < 3; ++i)
322 WaitForNextTenthSecond(timer, count);
323 m_prog->ProgressStatus((
double)(i + 1) / 3);
343 return *CxxTest::TestGroup::GetGroup(CxxTest::TG_INTERMEDIATE);
354 boost::this_thread::sleep(boost::posix_time::millisec(100));
357 const double DELTA = 1e-5;
375 std::string outStr(p->m_info.str());
376 std::string baseStr =
377 "Begin operation: Generating mesh points.\n" 378 "Percent complete: 25%.\n" 379 "Elapsed seconds: 0.1.\n" 380 "Time remaining (seconds): 0.3.\n" 381 "Percent complete: 50%.\n" 382 "Elapsed seconds: 0.2.\n" 383 "Time remaining (seconds): 0.2.\n" 384 "Percent complete: 75%.\n" 385 "Elapsed seconds: 0.3.\n" 386 "Time remaining (seconds): 0.1.\n" 387 "Percent complete: 100%.\n" 388 "Elapsed seconds: 0.4.\n" 389 "Time remaining (seconds): 0.0.\n" 391 "Begin operation: Triangulating.\n" 392 "Percent complete: 20%.\n" 393 "Elapsed seconds: 0.1.\n" 394 "Time remaining (seconds): 0.4.\n" 395 "Percent complete: 40%.\n" 396 "Elapsed seconds: 0.2.\n" 397 "Time remaining (seconds): 0.3.\n" 398 "Percent complete: 60%.\n" 399 "Elapsed seconds: 0.3.\n" 400 "Time remaining (seconds): 0.2.\n" 401 "Percent complete: 80%.\n" 402 "Elapsed seconds: 0.4.\n" 403 "Time remaining (seconds): 0.1.\n" 404 "Percent complete: 100%.\n" 405 "Elapsed seconds: 0.5.\n" 406 "Time remaining (seconds): 0.0.\n" 408 "Begin operation: Generating unstructured grid.\n" 409 "Percent complete: 33%.\n" 410 "Elapsed seconds: 0.1.\n" 411 "Time remaining (seconds): 0.2.\n" 412 "Percent complete: 67%.\n" 413 "Elapsed seconds: 0.2.\n" 414 "Time remaining (seconds): 0.1.\n" 415 "Percent complete: 100%.\n" 416 "Elapsed seconds: 0.3.\n" 417 "Time remaining (seconds): 0.0.\n";
418 TS_ASSERT_EQUALS(baseStr, outStr);
double m_percentComplete
percent complete
virtual void TimeRemainingInSeconds(double a_remainingSeconds)
Virtual method to publish the time remaining.
virtual void TimeElapsedInSeconds(double a_elapsedSeconds)
Virtual method to publish the elasped time.
void PretendMeshing()
mock meshing method
virtual void TimeRemainingInSeconds(double a_secondsRemaining) override
void WaitForNextTenthSecond(boost::timer::cpu_timer &a_timer, int &a_count)
wait until next tenth second passed
double EstimatedTimeRemainingInSec(double a_percentComplete, double a_elapsedTime)
Returns the elapsed time for the operation being observed.
virtual void OnProgressStatus(double a_percentComplete) override
captures the progress of an operation
void UpdateMessage(const std::string &a_message)
Updates the message but not the percent complete.
virtual void OnEndOperation()
Virtual function for derived class to get end operation event.
void BeginOperationString(const std::string &a_operation)
Publishes the name of the operation and starts the timing of the operation.
double m_remainingSeconds
seconds remaining
Implementation of the observer class.
void EndOperation()
Stops the timer.
BSHP< xms::Observer > m_prog
observer class to report progress
mock meshing class to show how the observer works
virtual void OnUpdateMessage(const std::string &a_message)
bool ProgressStatus(double a_percentComplete)
Method to publish the progress status.
virtual void OnBeginOperationString(const std::string &a_operation) override
std::stringstream m_info
string info captured by the class
BSHP< impl > m_p
implementation class
virtual void OnBeginOperationString(const std::string &a_operation)
Virtual function for derived class to get the operation string.
virtual void OnProgressStatus(double a_percentComplete)=0
void EndOperation()
Ends the operation.
boost::timer::cpu_timer m_timer
timer to get elapsed time
void BeginOperationString()
Starts the timer to know the elapsed time for the operation and to estimate the time remaining...
double m_elapsedSeconds
seconds elapsed
Derived class used for testing use of Observer class.
Class used with the observer pattern.
virtual void TimeElapsedInSeconds(double a_elapsedSeconds) override
void SetObserver(BSHP< xms::Observer > a_)
set the observer class
double ElapsedTimeInSeconds()
Returns the elapsed time for the operation being observed.