VLink  2.0.0
A high-performance communication middleware
vlink::CachedTimestamp Class Referencefinal

Mutable cached generator for short formatted timestamps. More...

#include <cached_timestamp.h>

Collaboration diagram for vlink::CachedTimestamp:

Public Member Functions

 CachedTimestamp ()
 Constructs the generator with an empty internal cache. More...
 
 ~CachedTimestamp ()
 Destructor. More...
 
std::string_view get (const char *format="%02d-%02d %02d:%02d:%02d.%03d", bool use_utc=false)
 Returns a view of the current formatted timestamp. More...
 

Detailed Description

Mutable cached generator for short formatted timestamps.

Holds a 32-byte buffer protected by a mutex plus an atomic last-second counter so concurrent get calls share a single formatted prefix and only the millisecond suffix is rewritten. The first call seeds the cache; subsequent same-second calls patch only the trailing three characters in place.

Constructor & Destructor Documentation

◆ CachedTimestamp()

vlink::CachedTimestamp::CachedTimestamp ( )

Constructs the generator with an empty internal cache.

The cache is populated lazily on the first get call.

◆ ~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 
)

Returns a view of the current formatted timestamp.

The returned view points into the internal 32-byte buffer. It is invalidated by the next call to get on any thread sharing this instance. The format must end with a 3-digit millisecond field because the cache patches the last three bytes in place; the entire formatted string must fit within 31 characters. Switching format or use_utc forces a full reformat on the next second boundary.

Parameters
formatsnprintf format consuming six int arguments in this order: month, day, hour, minute, second, milliseconds. Default: "%02d-%02d @c %02d:%02d:%02d.%03d".
use_utctrue for UTC formatting; false for local time. Default: false.
Returns
std::string_view over the rendered timestamp.

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