VLink  2.3.0
A high-performance communication middleware
vlink::CachedTimestamp类 参考final

Mutable cached generator for short formatted timestamps. 更多...

#include <cached_timestamp.h>

vlink::CachedTimestamp 的协作图:

Public 成员函数

 CachedTimestamp ()
 Constructs the generator 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 view of the current formatted timestamp. 更多...
 
std::string_view get_at (std::chrono::system_clock::time_point now, const char *format="%02d-%02d %02d:%02d:%02d.%03d", bool use_utc=false)
 Formats an explicit wall-clock time using the same cache and format contract as get. 更多...
 

详细描述

Mutable cached generator for short formatted timestamps.

Holds a 32-byte buffer and last-second counter protected by a mutex. With the default format, same-second calls patch only the millisecond suffix. Custom formats are rendered in full. Returned views require external synchronization when the instance is shared.

构造及析构函数说明

◆ 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.

成员函数说明

◆ 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 or get_at on any thread sharing this instance. Copying the view while another thread updates the cache requires external synchronization. Output must fit within 31 characters. Only the default format patches its millisecond suffix; custom formats are rendered in full. Format and timezone changes take effect immediately.

参数
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.
返回
std::string_view over the rendered timestamp.

◆ get_at()

std::string_view vlink::CachedTimestamp::get_at ( std::chrono::system_clock::time_point  now,
const char *  format = "%02d-%02d %02d:%02d:%02d.%03d",
bool  use_utc = false 
)

Formats an explicit wall-clock time using the same cache and format contract as get.

参数
nowWall-clock time to render.
formatFormat consuming month, day, hour, minute, second and milliseconds as integers.
use_utcWhether to use UTC instead of local time.
返回
View valid until the next cache update; empty if conversion or formatting fails.

该类的文档由以下文件生成: