Advertisement
Jarquafelmu

DurationTracker.h

Nov 20th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #pragma once
  2. #include <chrono>
  3. #include <string>
  4.  
  5. using namespace std;
  6. using namespace chrono;
  7.  
  8. class DurationTracker
  9. {
  10. public:
  11.     DurationTracker( const DurationTracker& other )  // NOLINT(hicpp-use-equals-default)
  12.         : _startTime ( other._startTime ),
  13.           _endTime ( other._endTime ),
  14.           _timeElapsed ( other._timeElapsed ) {}
  15.  
  16.     DurationTracker( DurationTracker&& other ) noexcept
  17.         : _startTime ( std::move(other._startTime) ),
  18.           _endTime ( std::move(other._endTime) ),
  19.           _timeElapsed ( other._timeElapsed ) {}
  20.  
  21.     DurationTracker& operator=( const DurationTracker& other )
  22.     {
  23.         if ( this == &other )
  24.             return *this;
  25.         _startTime = other._startTime;
  26.         _endTime = other._endTime;
  27.         _timeElapsed = other._timeElapsed;
  28.         return *this;
  29.     }
  30.  
  31.     DurationTracker& operator=( DurationTracker&& other ) noexcept
  32.     {
  33.         if ( this == &other )
  34.             return *this;
  35.         _startTime = std::move ( other._startTime );
  36.         _endTime = std::move ( other._endTime );
  37.         _timeElapsed = other._timeElapsed;
  38.         return *this;
  39.     }
  40.  
  41.     DurationTracker ();
  42.     ~DurationTracker ();
  43.     void start ();
  44.     void stop ();
  45.     string results () const;
  46.     double getTimeElapsed () const;
  47.  
  48. private:
  49.     void process ();
  50.  
  51.     high_resolution_clock::time_point _startTime;
  52.     high_resolution_clock::time_point _endTime;
  53.     double _timeElapsed;
  54. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement