From: <den...@us...> - 2010-01-20 15:16:33
|
Revision: 97 http://stdair.svn.sourceforge.net/stdair/?rev=97&view=rev Author: denis_arnaud Date: 2010-01-20 15:16:23 +0000 (Wed, 20 Jan 2010) Log Message: ----------- [Dev] Added BasChronometer class. Modified Paths: -------------- trunk/stdair/stdair/basic/sources.mk Added Paths: ----------- trunk/stdair/stdair/basic/BasChronometer.cpp trunk/stdair/stdair/basic/BasChronometer.hpp Added: trunk/stdair/stdair/basic/BasChronometer.cpp =================================================================== --- trunk/stdair/stdair/basic/BasChronometer.cpp (rev 0) +++ trunk/stdair/stdair/basic/BasChronometer.cpp 2010-01-20 15:16:23 UTC (rev 97) @@ -0,0 +1,45 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> +// Stdair +#include <stdair/basic/BasChronometer.hpp> + +namespace stdair { + + // ////////////////////////////////////////////////////////////////////// + BasChronometer::BasChronometer () : _startTimeLaunched (false) { + } + + // ////////////////////////////////////////////////////////////////////// + void BasChronometer::start () { + // Get the time-stamp of now, and store it for later use + _startTime = boost::posix_time::microsec_clock::local_time(); + + // Update the boolean which states whether the chronometer + // is launched + _startTimeLaunched = true; + } + + // ////////////////////////////////////////////////////////////////////// + double BasChronometer::elapsed () const { + assert (_startTimeLaunched == true); + + // Get the time-stamp of now + const boost::posix_time::ptime lStopTime = + boost::posix_time::microsec_clock::local_time(); + + // Calculate the time elapsed since the last time-stamp + const boost::posix_time::time_duration lElapsedTime = + lStopTime - _startTime; + + // Derived the corresponding number of milliseconds + const double lElapsedTimeInMicroSeconds = + static_cast<const double> (lElapsedTime.total_microseconds()); + + // The elapsed time given in return is expressed in seconds + return (lElapsedTimeInMicroSeconds / 1e6); + } + +} Added: trunk/stdair/stdair/basic/BasChronometer.hpp =================================================================== --- trunk/stdair/stdair/basic/BasChronometer.hpp (rev 0) +++ trunk/stdair/stdair/basic/BasChronometer.hpp 2010-01-20 15:16:23 UTC (rev 97) @@ -0,0 +1,41 @@ +#ifndef __STDAIR_BAS_BASCHRONOMETER_HPP +#define __STDAIR_BAS_BASCHRONOMETER_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// Boost (STL Extension) +// Boost Date-Time (http://boost.org/doc/html/date_time/posix_time.html) +#include <boost/date_time/posix_time/posix_time.hpp> + +namespace stdair { + + /** Structure allowing measuring the time elapsed between two events. */ + struct BasChronometer { + /** Constructor. */ + BasChronometer(); + + /** Start the chronometer from the local time + <br>The elapsed time given is the one elapsed since the start + is launched. */ + void start (); + + /** Get the start time. */ + std::string getStart () const { + return boost::posix_time::to_simple_string (_startTime); + } + + /** Return the time elapsed since the structure has been instanciated. + <br>That elapsed time is expressed in seconds. */ + double elapsed () const; + + private: + /** Start time. */ + boost::posix_time::ptime _startTime; + + /** Boolean which states whether the chronometer is started or not.*/ + bool _startTimeLaunched; + }; + +} +#endif // __STDAIR_BAS_BASCHRONOMETER_HPP Modified: trunk/stdair/stdair/basic/sources.mk =================================================================== --- trunk/stdair/stdair/basic/sources.mk 2010-01-19 18:44:31 UTC (rev 96) +++ trunk/stdair/stdair/basic/sources.mk 2010-01-20 15:16:23 UTC (rev 97) @@ -5,6 +5,8 @@ $(top_srcdir)/stdair/basic/BasConst_BookingClass.hpp \ $(top_srcdir)/stdair/basic/BasConst_Yield.hpp \ $(top_srcdir)/stdair/basic/BasConst_Period_BOM.hpp \ - $(top_srcdir)/stdair/basic/BasConst_TravelSolution.hpp + $(top_srcdir)/stdair/basic/BasConst_TravelSolution.hpp \ + $(top_srcdir)/stdair/basic/BasChronometer.hpp bas_cc_sources = \ - $(top_srcdir)/stdair/basic/BasConst.cpp + $(top_srcdir)/stdair/basic/BasConst.cpp \ + $(top_srcdir)/stdair/basic/BasChronometer.cpp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |