X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=ETL%2Ftrunk%2FETL%2F_clock_base.h;fp=ETL%2Ftrunk%2FETL%2F_clock_base.h;h=760d668f9c1ae704e4aa3b7258b1833cf28fe87f;hb=b3016b249333ac0ab0008d8c6c4d9029b2ff30c9;hp=0000000000000000000000000000000000000000;hpb=7f4273493da74d7d5746a65551e20c7786d0f155;p=synfig.git diff --git a/ETL/trunk/ETL/_clock_base.h b/ETL/trunk/ETL/_clock_base.h new file mode 100644 index 0000000..760d668 --- /dev/null +++ b/ETL/trunk/ETL/_clock_base.h @@ -0,0 +1,132 @@ +/*! ======================================================================== +** Extended Template and Library +** Clock Abstraction Implementation +** $Id: _clock_base.h,v 1.1.1.1 2005/01/04 01:31:46 darco Exp $ +** +** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** +** === N O T E S =========================================================== +** +** This is an internal header file, included by other ETL headers. +** You should not attempt to use it directly. +** +** ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __ETL__CLOCK_H +#define __ETL__CLOCK_H + +/* === H E A D E R S ======================================================= */ + +#ifndef WIN32 +#include +#else +inline void sleep(int i) { Sleep(i*1000); } +#endif + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +_ETL_BEGIN_NAMESPACE + +inline void yield() { sleep(0); } + +/*! ======================================================================== +** \class clock_base +** \brief clock abstraction +** +** A more detailed description needs to be written. +*/ +template +class clock_base : public DESC +{ +public: + typedef typename DESC::value_type value_type; + +private: + typedef clock_base _clock; + typedef typename DESC::timestamp timestamp; + + timestamp base_time; + + using DESC::get_current_time; + using DESC::realtime; + using DESC::one_second; +public: + + clock_base() { reset(); } + + void reset() + { get_current_time(base_time); } + + value_type operator()()const + { return timestamp_to_seconds(get_current_time()-base_time); } + + value_type pop_time() + { + // Grab the old base time + timestamp old_time=base_time; + + // Put the current time into base_time + get_current_time(base_time); + + return timestamp_to_seconds(base_time-old_time); + } + + static void + sleep(const value_type &length) + { + if(!realtime()) + ::sleep((int)(length+0.5)); + else + { + _clock timer; + timer.reset(); + value_type val; + for(val=timer();one_second()