susumu.yata
null+****@clear*****
Thu Feb 28 15:08:33 JST 2013
susumu.yata 2013-02-28 15:08:33 +0900 (Thu, 28 Feb 2013) New Revision: 7938158a2717aef8475699e6b0778c765452bb7b https://github.com/groonga/grnxx/commit/7938158a2717aef8475699e6b0778c765452bb7b Log: Move the implementations of grnxx::Stopwatch to stopwatch.cpp. Added files: lib/stopwatch.cpp Modified files: lib/Makefile.am lib/stopwatch.hpp Modified: lib/Makefile.am (+1 -0) =================================================================== --- lib/Makefile.am 2013-02-28 14:32:59 +0900 (82a743c) +++ lib/Makefile.am 2013-02-28 15:08:33 +0900 (106394c) @@ -23,6 +23,7 @@ libgrnxx_la_SOURCES = \ recycler.cpp \ slice.cpp \ steady_clock.cpp \ + stopwatch.cpp \ string.cpp \ string_builder.cpp \ system_clock.cpp \ Added: lib/stopwatch.cpp (+62 -0) 100644 =================================================================== --- /dev/null +++ lib/stopwatch.cpp 2013-02-28 15:08:33 +0900 (e66ad57) @@ -0,0 +1,62 @@ +/* + Copyright (C) 2012-2013 Brazil, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include "stopwatch.hpp" + +#include "steady_clock.hpp" + +namespace grnxx { + +Stopwatch::Stopwatch(bool is_running) + : elapsed_(0), + start_time_(), + is_running_(is_running) { + if (is_running) { + start_time_ = SteadyClock::now(); + } +} + +void Stopwatch::start() { + if (!is_running_) { + start_time_ = SteadyClock::now(); + is_running_ = true; + } +} + +void Stopwatch::stop() { + if (is_running_) { + elapsed_ += SteadyClock::now() - start_time_; + is_running_ = false; + } +} + +void Stopwatch::reset() { + if (is_running_) { + start_time_ = SteadyClock::now(); + } + elapsed_ = Duration(0); +} + +Duration Stopwatch::elapsed() const { + if (is_running_) { + return elapsed_ + (SteadyClock::now() - start_time_); + } else { + return elapsed_; + } +} + +} // namespace grnxx Modified: lib/stopwatch.hpp (+6 -38) =================================================================== --- lib/stopwatch.hpp 2013-02-28 14:32:59 +0900 (bbb57ac) +++ lib/stopwatch.hpp 2013-02-28 15:08:33 +0900 (a97d2b3) @@ -19,14 +19,10 @@ #define GRNXX_STOPWATCH_HPP #include "basic.hpp" -#include "steady_clock.hpp" +#include "time.hpp" namespace grnxx { -enum { - STOPWATCH_RUNNING -}; - // To measure the amount of time elapsed. class Stopwatch { public: @@ -35,14 +31,7 @@ class Stopwatch { Stopwatch() = delete; // Construct a stopwatch, which is started if is_running == true. - explicit Stopwatch(bool is_running) - : elapsed_(0), - start_time_(), - is_running_(is_running) { - if (is_running) { - start_time_ = SteadyClock::now(); - } - } + explicit Stopwatch(bool is_running); // Return true iff the stopwatch is running. bool is_running() const { @@ -50,36 +39,15 @@ class Stopwatch { } // Start measurement. - void start() { - if (!is_running_) { - start_time_ = SteadyClock::now(); - is_running_ = true; - } - } + void start(); // Stop measurement. - void stop() { - if (is_running_) { - elapsed_ += SteadyClock::now() - start_time_; - is_running_ = false; - } - } + void stop(); // Clear the elapsed time. - void reset() { - if (is_running_) { - start_time_ = SteadyClock::now(); - } - elapsed_ = Duration(0); - } + void reset(); // Get the current elapsed time. - Duration elapsed() const { - if (is_running_) { - return elapsed_ + (SteadyClock::now() - start_time_); - } else { - return elapsed_; - } - } + Duration elapsed() const; private: Duration elapsed_; -------------- next part -------------- HTML����������������������������...Download