|
VLink 2.0.0
A high-performance communication middleware
|
Cached, thread-safe formatted timestamp generator. 更多...
#include <cached_timestamp.h>
Public 成员函数 | |
| CachedTimestamp () | |
Constructs a CachedTimestamp with an empty internal cache. | |
| ~CachedTimestamp () | |
| Destructor. | |
| std::string_view | get (const char *format="%02d-%02d %02d:%02d:%02d.%03d", bool use_utc=false) |
Returns a std::string_view of the current formatted timestamp. | |
Cached, thread-safe formatted timestamp generator.
Reformats only the seconds portion of the timestamp once per second, patching the milliseconds in-place for all other calls. Used internally by the Logger to stamp each log line.
| vlink::CachedTimestamp::CachedTimestamp | ( | ) |
Constructs a CachedTimestamp with an empty internal cache.
The cache is populated on the first call to get().
| vlink::CachedTimestamp::~CachedTimestamp | ( | ) |
Destructor.
|
nodiscard |
Returns a std::string_view of the current formatted timestamp.
The view points into the internal 32-byte buffer. It is valid until the next call to get() from any thread that shares this instance. Copy the string if a persistent value is needed.
The default format produces strings of the form "MM-DD HH:MM:SS.mmm".
| format | A snprintf-compatible format string. Must include exactly one %03d placeholder for milliseconds. The resulting string must fit within 31 characters. Default: "%02d-%02d %02d:%02d:%02d.%03d" |
| use_utc | If true, formats in UTC; if false (default), in local time. |
std::string_view into the internal buffer with the current timestamp.CachedTimestamp instance.