File indexing completed on 2025-01-05 04:37:31

0001 /*
0002     SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "timer.h"
0008 #include "functions.h"
0009 
0010 namespace bt
0011 {
0012 Timer::Timer()
0013     : elapsed(0)
0014 {
0015     last = Now();
0016 }
0017 
0018 Timer::Timer(const Timer &t)
0019     : last(t.last)
0020     , elapsed(t.elapsed)
0021 {
0022 }
0023 
0024 Timer::~Timer()
0025 {
0026 }
0027 
0028 TimeStamp Timer::update()
0029 {
0030     TimeStamp now = Now();
0031     TimeStamp d = (now > last) ? now - last : 0;
0032     elapsed = d;
0033     last = now;
0034     return last;
0035 }
0036 
0037 TimeStamp Timer::getElapsedSinceUpdate() const
0038 {
0039     TimeStamp now = Now();
0040     return (now > last) ? now - last : 0;
0041 }
0042 
0043 Timer &Timer::operator=(const Timer &t)
0044 {
0045     last = t.last;
0046     elapsed = t.elapsed;
0047     return *this;
0048 }
0049 }