crawlserv++  [under development]
Application for crawling and analyzing textual content of websites.
Simple.hpp
Go to the documentation of this file.
1 /*
2  *
3  * ---
4  *
5  * Copyright (C) 2022 Anselm Schmidt (ans[ät]ohai.su)
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version in addition to the terms of any
11  * licences already herein identified.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  *
21  * ---
22  *
23  * Simple.hpp
24  *
25  * Simple timer for getting the time since creation in microseconds.
26  *
27  * Created on: Oct 17, 2018
28  * Author: ans
29  */
30 
31 #ifndef TIMER_SIMPLE_HPP_
32 #define TIMER_SIMPLE_HPP_
33 
34 #include "../Helper/DateTime.hpp"
35 
36 #include <chrono> // std::chrono
37 #include <string> // std::string
38 
40 namespace crawlservpp::Timer {
41 
42  /*
43  * DECLARATION
44  */
45 
47 
53  class Simple {
54  public:
57 
58  Simple();
59 
63 
64  std::uint64_t tick();
65  std::string tickStr();
66 
70 
71  void clear();
72 
74 
75  protected:
78 
80  std::chrono::steady_clock::time_point timePoint;
81 
83  };
84 
85  /*
86  * IMPLEMENTATION
87  */
88 
90  inline Simple::Simple() : timePoint(std::chrono::steady_clock::now()) {}
91 
93 
98  inline std::uint64_t Simple::tick() {
99  const auto result{
100  std::chrono::duration_cast<std::chrono::milliseconds>(
102  ).count()
103  };
104 
106 
107  return result;
108  }
109 
111 
119  inline std::string Simple::tickStr() {
120  const auto result{
121  std::chrono::duration_cast<std::chrono::milliseconds>(
123  ).count()
124  };
125 
127 
129  }
130 
132  inline void Simple::clear() {
133  this->timePoint = std::chrono::steady_clock::time_point{};
134  }
135 
136 } /* namespace crawlservpp::Timer */
137 
138 #endif /* TIMER_SIMPLE_HPP_ */
std::string tickStr()
Timer tick returning the number of milliseconds passed as string.
Definition: Simple.hpp:119
std::string now()
Formats the current date/time as string in the format YYYY-MM-DD HH:MM:SS.
Definition: DateTime.hpp:1045
std::chrono::steady_clock::time_point timePoint
(Time) point of creation or last tick.
Definition: Simple.hpp:80
Namespace for timers.
Definition: Simple.hpp:40
A simple timer.
Definition: Simple.hpp:53
Simple()
Constructor starting the timer.
Definition: Simple.hpp:90
void clear()
Resets the internal state of the timer.
Definition: Simple.hpp:132
std::string millisecondsToString(std::uint64_t milliseconds)
Converts milliseconds into a well-formatted string.
Definition: DateTime.hpp:933
std::uint64_t tick()
Timer tick returning the number of milliseconds passed.
Definition: Simple.hpp:98