PhoenixClock  2.2.0
Library wrapping the usage of system's clock, allowing to use clock mock-ups
Loading...
Searching...
No Matches
PClockNs.h
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#ifndef __PCLOCKNS_H__
8#define __PCLOCKNS_H__
9
10#include "ellapsedTime.h"
11#include <time.h>
12#include <chrono>
13#include <ctime>
14#include <string>
15#include <thread>
16
19 public:
20 typedef std::chrono::steady_clock SteadyClock;
21 typedef std::chrono::nanoseconds Nanosecond;
22 typedef std::chrono::time_point<SteadyClock> TimeNs;
23
24 PClockNs();
25 virtual ~PClockNs();
26
27 void setOffsetTimeNs(std::time_t offsetTimeNs);
28 std::time_t getOffsetTimeNs() const;
29
30 std::time_t getFullTimeNs() const;
31 std::string getDateNs() const;
32 std::string getDateCompactNs() const;
33 std::time_t now() const;
34 void sleep(EllapsedTime ellapsedTime) const;
35 private:
37
43 std::time_t p_offsetTimeNs;
44};
45
46std::string phoenix_dateNs(std::time_t currentDateNs, const char* format);
47std::string phoenix_dateNs(std::time_t currentDateNs);
48std::string phoenix_dateCompactNs(std::time_t currentDateNs);
49
50#endif
51
std::string phoenix_dateNs(std::time_t currentDateNs, const char *format)
Convert a given date in nanosecond into a text date.
Definition PClockNs.cpp:15
std::string phoenix_dateCompactNs(std::time_t currentDateNs)
Convert a given date in nanosecond into a text date in a more compact way.
Definition PClockNs.cpp:38
std::string getDateCompactNs() const
Get the date at nanosecond precision (even if it is not precise at the nanosecond scale,...
Definition PClockNs.cpp:87
std::time_t now() const
Get the full time in nanoseconds.
Definition PClockNs.cpp:94
void initialisationPClockNs()
Initialisation function of the class PClockNs.
Definition PClockNs.cpp:106
void sleep(EllapsedTime ellapsedTime) const
Sleep for the given ellapsed time.
Definition PClockNs.cpp:101
std::time_t getOffsetTimeNs() const
Get the offset in nanoseconds of the current clock.
Definition PClockNs.cpp:62
std::time_t getFullTimeNs() const
Get the full time in nanoseconds.
Definition PClockNs.cpp:69
virtual ~PClockNs()
Destructor of PClockNs.
Definition PClockNs.cpp:48
void setOffsetTimeNs(std::time_t offsetTimeNs)
Set the offset in nanoseconds of the current clock.
Definition PClockNs.cpp:55
std::string getDateNs() const
Get the date at nanosecond precision (even if it is not precise at the nanosecond scale,...
Definition PClockNs.cpp:80
PClockNs()
Default constructor of PClockNs.
Definition PClockNs.cpp:43
std::chrono::nanoseconds Nanosecond
Definition PClockNs.h:21
std::chrono::steady_clock SteadyClock
Definition PClockNs.h:20
std::chrono::time_point< SteadyClock > TimeNs
Definition PClockNs.h:22
std::time_t p_baseSystemClockSecond
Base of the system clock in second.
Definition PClockNs.h:39
std::time_t p_offsetTimeNs
Offset of time with date and nanoseconds.
Definition PClockNs.h:43
TimeNs p_baseSteadyClockNs
Base clock time with a nanosecond precision but since the starting of the CPU.
Definition PClockNs.h:41
time_t EllapsedTime