StdAir Logo  1.00.3
C++ Standard Airline IT Object Library
BasChronometer.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 // Stdair
8 
9 namespace stdair {
10 
11  // //////////////////////////////////////////////////////////////////////
12  BasChronometer::BasChronometer () : _startTimeLaunched (false) {
13  }
14 
15  // //////////////////////////////////////////////////////////////////////
17  // Get the time-stamp of now, and store it for later use
18  _startTime = boost::posix_time::microsec_clock::local_time();
19 
20  // Update the boolean which states whether the chronometer
21  // is launched
22  _startTimeLaunched = true;
23  }
24 
25  // //////////////////////////////////////////////////////////////////////
26  double BasChronometer::elapsed () const {
27  assert (_startTimeLaunched == true);
28 
29  // Get the time-stamp of now
30  const boost::posix_time::ptime lStopTime =
31  boost::posix_time::microsec_clock::local_time();
32 
33  // Calculate the time elapsed since the last time-stamp
34  const boost::posix_time::time_duration lElapsedTime =
35  lStopTime - _startTime;
36 
37  // Derived the corresponding number of milliseconds
38  const double lElapsedTimeInMicroSeconds =
39  static_cast<const double> (lElapsedTime.total_microseconds());
40 
41  // The elapsed time given in return is expressed in seconds
42  return (lElapsedTimeInMicroSeconds / 1e6);
43  }
44 
45 }
Handle on the StdAir library context.
double elapsed() const