-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeshaftFile.cpp
More file actions
105 lines (79 loc) · 1.51 KB
/
TimeshaftFile.cpp
File metadata and controls
105 lines (79 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "StdAfx.h"
#include "TimeshaftFile.h"
#include <string>
#include <assert.h>
const std::string CTimeshaftFile::m_strOut = "time.dat";
CTimeshaftFile::CTimeshaftFile(void)
{
if (!m_ios.is_open())
{
m_ios.open(m_strOut, std::ios::binary | std::ios::out | std::ios::in);
}
m_ios.seekp(0);
}
CTimeshaftFile::~CTimeshaftFile(void)
{
if (m_ios.is_open())
{
m_ios.close();
}
}
void CTimeshaftFile::Write(const char* pBuff, int nLen)
{
assert(pBuff != nullptr);
m_ios.write(pBuff, nLen);
}
void CTimeshaftFile::Read(char* pBuff, int nLen)
{
assert(pBuff != nullptr);
m_ios.read(pBuff, nLen);
}
//////////////////////////////////////////////////////////////////////////
CFmtTime::CFmtTime()
{
Init();
}
CFmtTime::CFmtTime(int64_t uSecs)
{
Init();
m_uSec = uSecs;
}
void CFmtTime::Init()
{
m_nHour = 0;
m_nMin = 0;
m_nSec = 0;
m_uSec = 0;
}
//ʱ·ÖÃë
std::string CFmtTime::AsString()
{
int nSecs = m_uSec / (1000 * 1000);
int nHours = 0;
int nMins = 0;
do
{
nMins += nSecs / 60;
nHours += nMins / 60;
nSecs %= 60;
} while (nSecs < 60);
m_nHour = nHours;
m_nMin = nMins;
m_nSec = nSecs;
char szBuff[13] = {0};
sscanf(szBuff, "%d%d%d", &nHours, &nMins, &nSecs);
std::string strTemp = szBuff;
return strTemp;
}
int CFmtTime::Hour()
{
return m_nHour;
}
int CFmtTime::nMin()
{
return m_nMin;
}
int CFmtTime::nSec()
{
return m_nSec;
}