TimeVal类——Live555源码阅读(一)基本组件类

时间:2023-03-08 17:46:54

这是Live555源码阅读的第一部分,包括了时间类,延时队列类,处理程序描述类,哈希表类这四个大类。

这里是时间相关类的第一个部分。

TimeVal类

TimeVal类定义在live555sourcecontrol\BasicUsageEnvironment\include\DelayQueue.hh文件中。其实质上是对struct timeval的封装。

先来看看TimeVal类的组成。

其只有一个数据成员,就是一个timeval的结构体fTv。TimeVal类封装的所有方法都是对其的操作。

TimeVal类的uml图

TimeVal类——Live555源码阅读(一)基本组件类

struct timeval结构体

再来看看这个 struct timeval结构体的定义

struct timeval {
long tv_sec; /* seconds 秒*/
long tv_usec; /* and microseconds 微秒*/
};

下面是TimeVal类的定义。

TimeVal类的定义很简单,就不详述了。TimeVal类还有两个派生类。在另外的文章中来说。

class Timeval {
public:
time_base_seconds seconds() const {
return fTv.tv_sec;
}
time_base_seconds seconds() {
return fTv.tv_sec;
}
time_base_seconds useconds() const {
return fTv.tv_usec;
}
time_base_seconds useconds() {
return fTv.tv_usec;
} int operator>=(Timeval const& arg2) const;
int operator<=(Timeval const& arg2) const {
return arg2 >= *this;
}
int operator<(Timeval const& arg2) const {
return !(*this >= arg2);
}
int operator>(Timeval const& arg2) const {
return arg2 < *this;
}
int operator==(Timeval const& arg2) const {
return *this >= arg2 && arg2 >= *this;
}
int operator!=(Timeval const& arg2) const {
return !(*this == arg2);
} void operator+=(class DelayInterval const& arg2);
void operator-=(class DelayInterval const& arg2);
// returns ZERO iff arg2 >= arg1 protected:
Timeval(time_base_seconds seconds, time_base_seconds useconds) {
fTv.tv_sec = seconds; fTv.tv_usec = useconds;
} private:
time_base_seconds& secs() {
return (time_base_seconds&)fTv.tv_sec;
}
time_base_seconds& usecs() {
return (time_base_seconds&)fTv.tv_usec;
} struct timeval fTv;
};