Console Library 8.0.0
A header-only library that makes C++ simple
Loading...
Searching...
No Matches
console::Time Class Reference

表示以纳秒为单位的时间量,支持单位转换、算术运算和自动选择合适的输出单位。 More...

#include <time.h>

Public Member Functions

 Time (long long ns=0)
 构造一个 Time 对象。
intmax_t count () const
 获取纳秒数。
 operator intmax_t () const
 允许隐式转换为 intmax_t(返回纳秒数)。
double ns () const
 返回纳秒数。
double us () const
 返回微秒数。
double ms () const
 返回毫秒数。
double s () const
 返回秒数。
double min () const
 返回分钟数。
double hr () const
 返回小时数。
std::string str () const
 将 Time 对象转换为字符串表示。

Private Attributes

intmax_t ns_
 纳秒数

Friends

std::ostream & operator<< (std::ostream &os, const Time t)
 输出 Time 对象到流,自动选择合适单位。
template<class Rep, class Period>
Time operator+ (Time t, std::chrono::duration< Rep, Period > d)
template<class Rep, class Period>
Time operator- (Time t, std::chrono::duration< Rep, Period > d)
比较运算
bool operator== (Time t1, Time t2)
bool operator!= (Time t1, Time t2)
bool operator< (Time t1, Time t2)
bool operator> (Time t1, Time t2)
bool operator<= (Time t1, Time t2)
bool operator>= (Time t1, Time t2)

算术运算

Time operator* (double d) const
Time operator/ (double d) const
Time operator+ (Time t1, Time t2)
Time operator- (Time t1, Time t2)

Detailed Description

表示以纳秒为单位的时间量,支持单位转换、算术运算和自动选择合适的输出单位。

内部使用 intmax_t 存储纳秒数,提供 ns()、us()、ms()、s()、min()、hr() 等转换函数。 输出流会根据时间大小自动选择最合适的单位(hr/min/s/ms/μs/ns)。

Constructor & Destructor Documentation

◆ Time()

console::Time::Time ( long long ns = 0)
inline

构造一个 Time 对象。

Parameters
ns纳秒数,默认为 0。

Member Function Documentation

◆ count()

intmax_t console::Time::count ( ) const
inline

获取纳秒数。

◆ hr()

double console::Time::hr ( ) const
inline

返回小时数。

◆ min()

double console::Time::min ( ) const
inline

返回分钟数。

◆ ms()

double console::Time::ms ( ) const
inline

返回毫秒数。

◆ ns()

double console::Time::ns ( ) const
inline

返回纳秒数。

◆ operator intmax_t()

console::Time::operator intmax_t ( ) const
inline

允许隐式转换为 intmax_t(返回纳秒数)。

◆ operator*()

Time console::Time::operator* ( double d) const
inline

◆ operator/()

Time console::Time::operator/ ( double d) const
inline

◆ s()

double console::Time::s ( ) const
inline

返回秒数。

◆ str()

std::string console::Time::str ( ) const
inline

将 Time 对象转换为字符串表示。

Returns
std::string 字符串表示。

◆ us()

double console::Time::us ( ) const
inline

返回微秒数。

◆ operator!=

bool operator!= ( Time t1,
Time t2 )
friend

◆ operator+ [1/2]

template<class Rep, class Period>
Time operator+ ( Time t,
std::chrono::duration< Rep, Period > d )
friend

◆ operator+ [2/2]

Time operator+ ( Time t1,
Time t2 )
friend

◆ operator- [1/2]

template<class Rep, class Period>
Time operator- ( Time t,
std::chrono::duration< Rep, Period > d )
friend

◆ operator- [2/2]

Time operator- ( Time t1,
Time t2 )
friend

◆ operator<

bool operator< ( Time t1,
Time t2 )
friend

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const Time t )
friend

输出 Time 对象到流,自动选择合适单位。

Parameters
os输出流。
tTime 对象。
Returns
std::ostream& 流引用。

◆ operator<=

bool operator<= ( Time t1,
Time t2 )
friend

◆ operator==

bool operator== ( Time t1,
Time t2 )
friend

◆ operator>

bool operator> ( Time t1,
Time t2 )
friend

◆ operator>=

bool operator>= ( Time t1,
Time t2 )
friend

Member Data Documentation

◆ ns_

intmax_t console::Time::ns_
private

纳秒数


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