VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::CachedTimestamp Class Referencefinal

Cached, thread-safe formatted timestamp generator. More...

#include <cached_timestamp.h>

Collaboration diagram for vlink::CachedTimestamp:

Public Member Functions

 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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ CachedTimestamp()

vlink::CachedTimestamp::CachedTimestamp ( )

Constructs a CachedTimestamp with an empty internal cache.

The cache is populated on the first call to get().

◆ ~CachedTimestamp()

vlink::CachedTimestamp::~CachedTimestamp ( )

Destructor.

Member Function Documentation

◆ get()

std::string_view vlink::CachedTimestamp::get ( const char * format = "%02d-%02d %02d:%02d:%02d.%03d",
bool use_utc = false )
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".

Parameters
formatA 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_utcIf true, formats in UTC; if false (default), in local time.
Returns
A std::string_view into the internal buffer with the current timestamp.
Note
The returned view is invalidated on the next call from any thread that holds a reference to this CachedTimestamp instance.

The documentation for this class was generated from the following file: