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
|
class CLine
{
public:
CLine() :
m_Time(time_t()),
m_Valid(false)
{
}
CLine(const std::string &str) :
m_Time(time_t()),
m_Valid(false)
{
Extract(str);
}
public:
bool operator==(const CLine &line) const
{
return (line.m_Part == m_Part);
}
bool operator<(const CLine &line) const
{
return (m_Time < line.m_Time);
}
bool IsValid() const
{
return m_Valid;
}
const std::string &GetContent() const
{
return m_Content;
}
void Extract(const std::string &str);
private:
void get_time(const std::string &str);
private:
std::string m_Content;
std::string m_Part;
time_t m_Time;
bool m_Valid;
};
void CLine::get_time(const std::string& s)
{
m_Valid = (s.size() > 15);
if(m_Valid)
{
tm date;
memset(&date, 0, sizeof(date));
date.tm_mday = atoi(s.substr(0, 2).c_str());
date.tm_mon = atoi(s.substr(3, 2).c_str()) - 1;
date.tm_year = atoi(s.substr(6, 4).c_str()) - 1900;
date.tm_hour = atoi(s.substr(11, 2).c_str());
date.tm_min = atoi(s.substr(14, 2).c_str());
date.tm_sec = atoi(s.substr(17, 2).c_str());
m_Time = mktime(&date);
}
}
void CLine::Extract(const std::string &str)
{
m_Content = str;
const std::string::size_type pos1 = str.find(",");
m_Valid = (pos1 != std::string::npos);
if(m_Valid)
{
const std::string::size_type pos2 = str.find(",", pos1 + 1);
m_Valid = (pos2 != std::string::npos);
if(m_Valid)
get_time(str.substr(pos1 + 1, pos2 - (pos1 + 1)));
if(m_Valid)
m_Part = str.substr(0, pos1 + 1) + str.substr(pos2);
}
}
|