求注释 from thinking in C++

来源:百度知道 编辑:UC知道 时间:2024/09/24 22:57:05
//: C09:Cpptime.h
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
// A simple time class
#ifndef CPPTIME_H
#define CPPTIME_H
#include <ctime>
#include <cstring>

class Time {
std::time_t t;
std::tm local;
char asciiRep[26];
unsigned char lflag, aflag;
void updateLocal() {
if(!lflag) {
local = *std::localtime(&t);
lflag++;
}
}
void updateAscii() {
if(!aflag) {
updateLocal();
std::strcpy(asciiRep,std::asctime(&local));
aflag++;
}
}
public:
Time() { mark(); }
void mark() {
lflag = aflag = 0;
std::time(&t);
}
const char* ascii() {
updateAscii();

//: C09:Cpptime.h
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
// A simple time class
#ifndef CPPTIME_H
#define CPPTIME_H
#include <ctime>
#include <cstring>

class Time { //定义时间类
std::time_t t; //记录时间的秒数
std::tm local; //记录时间的结构
char asciiRep[26]; //字串形式的时间
unsigned char lflag, aflag; //两个表示一个是for local,一个for asciirep
void updateLocal() {
if(!lflag) { //若local没有取过时间
local = *std::localtime(&t); //取本地时间
lflag++; //修改标志,下次就不读取了
}
}
void updateAscii() {
if(!aflag) { //若asciirep没有取过时间
updateLocal();//取本地时间
std::strcpy(asciiRep,std::asctime(&local)); //转成字串放在asciirep
aflag++; //修改标志,下次就不读取了
}
}
public:
Time(