StdAir Logo  0.45.0
C++ Standard Airline IT Object Library
BasChronometer.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 // Stdair
00007 #include <stdair/basic/BasChronometer.hpp>
00008 
00009 namespace stdair {
00010 
00011   // //////////////////////////////////////////////////////////////////////
00012   BasChronometer::BasChronometer () : _startTimeLaunched (false) {
00013   }
00014 
00015   // //////////////////////////////////////////////////////////////////////
00016   void BasChronometer::start () {
00017     // Get the time-stamp of now, and store it for later use
00018     _startTime = boost::posix_time::microsec_clock::local_time();
00019     
00020     // Update the boolean which states whether the chronometer
00021     // is launched
00022     _startTimeLaunched = true;
00023   }
00024     
00025   // //////////////////////////////////////////////////////////////////////
00026   double BasChronometer::elapsed () const {
00027     assert (_startTimeLaunched == true);
00028     
00029     // Get the time-stamp of now
00030     const boost::posix_time::ptime lStopTime =
00031       boost::posix_time::microsec_clock::local_time();
00032     
00033     // Calculate the time elapsed since the last time-stamp
00034     const boost::posix_time::time_duration lElapsedTime =
00035       lStopTime - _startTime;
00036 
00037     // Derived the corresponding number of milliseconds
00038     const double lElapsedTimeInMicroSeconds =
00039       static_cast<const double> (lElapsedTime.total_microseconds());
00040     
00041     // The elapsed time given in return is expressed in seconds
00042     return (lElapsedTimeInMicroSeconds / 1e6);
00043   }
00044 
00045 }