FBB::*Clock(3bobcat)
Classes wrapping std::*_clock
(libbobcat-dev_6.07.01)
2005-2025
NAME
FBB::*Clock - classes wrapping std::chrono::*_clock facilities
SYNOPSIS
#include <bobcat/fileclock>
#include <bobcat/highresolutionclock>
#include <bobcat/steadyclock>
#include <bobcat/systemclock>
Each of these files also includes the std::chrono header file.
DESCRIPTION
The C++ std::chrono namespace defines clock-types and their
operations. The bobcat *Clock classes define wrappers around the four
standard C++ clock-types offering interfaces which are easier to handle
than the standard std::chrono clocks.
- FileClock wraps std::chrono::file_clock;
- HighResolutionClock wraps std::chrono::high_resolution_clock;
- SteadyClock wraps std::chrono::steady_clock;
- SystemClock wraps std::chrono::system_clock
, and is the
commonly used clock type.
Member names of the bobcat clock-classes don't use underscores. Names
consisting of multiple words are `camel-cased' (like timePoint).
Note:
The type std::chrono::file_clock (and therefore FileClock) is
available since the C++-2a standard: specify the --std=c++2a
(or more recent) compiler option when using FileClock.
NAMESPACE
FBB
All constructors, members, operators and manipulators, mentioned in this
man-page, are defined in the namespace FBB.
INHERITS FROM
FBB::ClockTypes
FBB::ClockBase
FBB::HighSysClock
these are internally used only classes; their facilities are covered
in this man-page.
TYPEDEFS AND ENUMS
- The std::chrono types nanoseconds, microseconds, milliseconds,
seconds, minutes and hours are also available in the namespace
FBB;
Clock Types:
- FBB::FileClock provides the std::chrono::file_clock facilities;
- FBB::HighResolutionClock provides the
std::chrono::high_resolution_clock facilities;
- FBB::SteadyClock provides the std::chrono::steady_clock
facilities;
- FBB::SystemClock provides the std::chrono::system_clock
facilities.
Sub-types:
- Duration: each clock type defines the type Duration as
std::chrono::duration<int64_t, std::nano>;
- Period: the sub-type period of the Duration type. In practice
its subtypes den (DenType) and num (NumType) are used;
- DenType: the denominator type of the ratio type used by the clock
type (see also the static member den);
- NumType: the numerator type of the ratio type used by the clock
type (see also the static member num);
CONSTRUCTORS
The constructors are illustrated for SystemClock but are also
available for the other clock types.
- SystemClock(SystemClock::TimePoint = SystemClock::now()):
each clock-constructor can be initialized with a time point. By default
the clock's time point is initialized by the time point returned by
the clock type's static now member;
- SystemClock(Clock const &otherClock):
each clock type can be initialized with another clock type object
(except for a SteadyClock type object): when constructed they
refer to the same points in time.
Copy and move constructors (and assignment operators) are available.
OVERLOADED OPERATORS
Using DurationType to represent
std::chrono::duration<int64_t, Ratio>, where Ratio is a
std::ratio type (for clocks Ratio equals nano).
FREE FUNCTIONS
- auto toClock<DestClock>(ClockType const &clock):
returns the DestClock::TimePoint corresponding to the TimePoint
of clock. It is not available for conversions from or to the
SteadyClock type. E.g.,
FileClock fc;
cout << toClock<SystemClock>(fc) << '\n';
- double toDouble<Duration>(ClockType const &src):
returns the double value corresponding to ClockType's
std::chrono::duration converted to the Duration
std::chrono::duration. E.g.,
toDouble<hours>(90min); // returns 1.5
- Dest toDuration(Src const &src):
returns src's Duration converted to the (at least as precise)
Dest duration. E.g.,
toDuration<seconds>(1min).count(); // returns 60
ADDITIONAL STEADYCLOCK FREE FUNCTIONS
The SteadyClock type is primarily used for timing purposes. The
following two functions are available for SteadyClock objects:
MEMBER FUNCTIONS
All of the following members are available for each of bobcat's clock
types:
- long int count():
returns timePoint's value. The clock types have members
timePoint(): this member returns the number of nano seconds as an
integral value since the beginning of the clock's era. E.g.,
FileClock{}.clock(); // returns, e.g.,
// -4701673791896351066
- static long int ClockTypes::count(TimePoint const &timePoint):
returns timePoint's value. This function can also be used for
SteadyClock objects. E.g.,
ClockTypes::count(SteadyClock::now()); // returns, e.g.,
// 8310904806233
- static DenType::den():
returns the denominator of the ratio used by the clocks (=
1'000'000'000);
- Duration elapsed() const:
returns the Duration value of the current Clock object (=
number of nano-seconds since the beginning of the clock's era). E.g.,
SystemClock{}.elapsed(); // returns, e.g.,
// 1735989478991599467ns
- static Duration ClockTypes::elapsed(TimePoint const &timePoint):
returns timePoint's Duration. Clock types have members
timePoint() returning the clock's time point;
- static TimePoint max():
returns the TimePoint of the used clock type corresponding to the
clock's maximum (UTC) time. E.g.,
cout << SystemClock::max(); // inserts:
// 2262-04-11 23:47:16...
- static TimePoint min():
returns the TimePoint of the used clock type corresponding to the
clock's minimum (UTC) time;
- static TimePoint now():
returns the TimePoint of the used clock type corresponding to the
current (UTC) time. E.g.,
cout << SystemClock::now() << '\n';
- static NumType::num():
returns the numerator of the ratio used by the clocks (= 1);
- static Period period():
returns the clock's Period (having members den and num);
- TimePoint const &timePoint() const:
returns the object's TimePoint;
- double toDouble<Dest>() const:
returns the double value corresponding to the object's
std::chrono::duration converted to the Dest
std::chrono::duration. E.g.,
SystemClock{}.toDouble<hours>(); // returns, e.g., 482221
- static Duration zero():
returns the clock's Duration representing 0 nanoseconds;
ADDITIONAL SYSTEM / HIGHRESOLUTION CLOCK MEMBERS
Primarily for displaying the clock's time the SystemClock and
HighResolutionClock classes support these members:
EXAMPLE
#include <iostream>
#include <string>
#include <thread>
#include <bobcat/fileclock>
#include <bobcat/highresolutionclock>
#include <bobcat/steadyclock>
#include <bobcat/systemclock>
using namespace std;
using namespace FBB;
int main()
{
SystemClock sysNow{ };
cout << "system clock at " << sysNow << "\n"
"elapsed: " << sysNow.elapsed() << "\n\n";
// same timespec, elapsed ns.
FileClock fileNow{ sysNow }; // is clock-specific
cout << "file clock at " << fileNow << "\n"
"elapsed: " << fileNow.elapsed() << "\n\n";
SystemClock sysNow2{ fileNow };
cout << "system clock at " << sysNow2 << "\n"
"elapsed: " << sysNow2.elapsed() << "\n\n";
cout << sysNow2("%Y %b %d, %H:%M:%S") << "\n"
"\n"
"minimum time: " << sysNow2.min() << "\n"
"maximum time: " << SystemClock::max() << "\n\n";
// conversion to less precise time specification:
cout << "100 minutes is " << toDouble<hours>(100min) << " hours\n\n";
HighResolutionClock hrc{ fileNow };
cout << "high resolution clock at " << hrc << "\n\n";
SteadyClock sc0; // computing 'since' itself takes several
auto passed = since(sc0); // (variable) hundred nano seconds
cout << "sc0 since: " << passed << '\n';
SteadyClock sc;
this_thread::sleep_for(1s);
cout <<
"ELAPSED: " << since(sc) << '\n' <<
"(small delay...)\n"
"as count: " << countSince(sc) << "\n\n";
}
FILES
bobcat/fileclock, - the FileClock class interface
bobcat/highresulutionclock - the HighResolutionClock
class interface
bobcat/steadyclock - the SteadyClock class interface
bobcat/systemclock - the SystemClock class interface
SEE ALSO
bobcat(7), time(3),
BUGS
None Reported.
BOBCAT PROJECT FILES
- https://fbb-git.gitlab.io/bobcat/: gitlab project page;
Debian Bobcat project files:
- libbobcat6: debian package containing the shared library, changelog
and copyright note;
- libbobcat-dev: debian package containing the
static library, headers, manual pages, and developer info;
BOBCAT
Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.
COPYRIGHT
This is free software, distributed under the terms of the
GNU General Public License (GPL).
AUTHOR
Frank B. Brokken (f.b.brokken@rug.nl).