rad 6.2.0
Loading...
Searching...
No Matches
helper.hpp
Go to the documentation of this file.
1
9#ifndef RAD_HELPER_HPP
10#define RAD_HELPER_HPP
11
12//#include <cstring>
13#include <stdio.h>
14#include <sys/time.h>
15#include <sstream>
16#include <string>
17
18namespace rad {
19
23class Helper {
24 public:
25 static constexpr const char* INTROOT = "INTROOT";
26 static constexpr const char* CFGPATH = "CFGPATH";
27
28 static std::string GetHostname(const bool with_domain = false);
29
30 static std::string FindFile(const std::string& filename);
31 static bool FileExists(const std::string& filename);
32 static std::string GetEnvVar(const std::string& key);
33 static std::string CreateIdentity();
34 static void SplitAddrPort(const std::string& addr_port, std::string& addr, int& port);
35 static std::string GetVersion();
36
37 Helper() = delete;
38 Helper(const Helper&) = delete;
39 Helper& operator=(const Helper&) = delete;
40};
41
45inline static double GetTime() {
46 struct timeval tp;
47 gettimeofday(&tp, nullptr);
48 return (tp.tv_sec + (tp.tv_usec / 1e6));
49}
50
57inline static std::string ConvertToIsoTime(const double timestamp) {
58 char tmp_iso_time[80];
59 long seconds = timestamp;
60 strftime(tmp_iso_time, 80, "%Y-%m-%dT%H:%M:%S", localtime(&seconds));
61 char tmp_mus[80];
62 snprintf(tmp_mus, sizeof(tmp_mus), "%.6f", (timestamp - seconds));
63 char iso_time[87];
64 snprintf(iso_time, sizeof(iso_time), "%s.%s", tmp_iso_time,
65 std::string(tmp_mus).substr(2).c_str());
66 return iso_time;
67}
68
72inline static std::string GetTimestamp() { return rad::ConvertToIsoTime(rad::GetTime()); }
73
74} // namespace rad
75
76#endif // RAD_HELPER_HPP
Definition helper.hpp:23
static std::string GetVersion()
Definition helper.cpp:184
static constexpr const char * CFGPATH
Definition helper.hpp:26
static bool FileExists(const std::string &filename)
Definition helper.cpp:118
static std::string GetHostname(const bool with_domain=false)
Definition helper.cpp:30
Helper & operator=(const Helper &)=delete
static void SplitAddrPort(const std::string &addr_port, std::string &addr, int &port)
Definition helper.cpp:169
Helper(const Helper &)=delete
static constexpr const char * INTROOT
Definition helper.hpp:25
static std::string CreateIdentity()
Definition helper.cpp:152
static std::string FindFile(const std::string &filename)
Definition helper.cpp:55
static std::string GetEnvVar(const std::string &key)
Definition helper.cpp:138
Helper()=delete
Definition actionsApp.cpp:23