00001 00002 // Copyright Florian Winter 2010 - 2010. 00003 // Distributed under the Boost Software License, Version 1.0. 00004 // (See accompanying file LICENSE_1_0.txt or copy at 00005 // http://www.boost.org/LICENSE_1_0.txt) 00006 00013 #ifndef TK11_CLOCK_HPP 00014 #define TK11_CLOCK_HPP 00015 00016 #include "time.hpp" 00017 00018 #include <boost/optional.hpp> 00019 00020 namespace tk11 { 00021 00023 00033 class Precision_Clock { 00034 public: 00036 typedef Duration time_type; 00037 00039 Precision_Clock(); 00040 00042 time_type operator()() const; 00043 00044 private: 00046 boost::int_least64_t frequency; 00047 00049 boost::int_least64_t start_counter; 00050 }; 00051 00052 00054 00068 class Secondary_Clock { 00069 public: 00071 typedef Duration input_time_type; 00072 00074 typedef Duration time_type; 00075 00077 00080 Secondary_Clock(const time_type& start_time = seconds(0)); 00081 00083 00089 time_type operator()() const { 00090 return current_time; 00091 } 00092 00094 00100 void update(const input_time_type& now); 00101 00103 00108 void pause(); 00109 00111 00114 void resume(); 00115 00116 private: 00118 time_type current_time; 00119 00121 boost::optional<input_time_type> last_time; 00122 00124 bool paused; 00125 }; 00126 00127 } 00128 00129 #endif