#include <datepattern.h>
Public Methods | |
DatePattern () | |
DatePattern (const DatePattern &p, unsigned int l) | |
Construct DatePattern containing first l components of p. | |
bool | parse (const string &date_string) |
Parses 1999-03-12 10:00, 1999-3-12, 1999-3, 1999. | |
void | set (unsigned int year, unsigned int month, unsigned int day, unsigned int hours) |
Set components explicitly. | |
const unsigned int | operator[] (unsigned int i) const |
unsigned int | size () const |
bool | operator== (const DatePattern &p) const |
bool | operator< (const DatePattern &p) const |
Private Attributes | |
vector<unsigned int> | date_ |
Friends | |
ostream& | operator<< (ostream &,const DatePattern &) |
Definition at line 10 of file datepattern.h.
|
Definition at line 12 of file datepattern.h. 00012 {} |
|
Construct DatePattern containing first l components of p.
Definition at line 7 of file datepattern.C. 00007 { 00008 unsigned int m(min(p.size(),n)); 00009 date_.resize(m); 00010 for (unsigned int i=0; i<n; ++i) 00011 date_[i] = p[i]; 00012 } |
|
Parses 1999-03-12 10:00, 1999-3-12, 1999-3, 1999.
Definition at line 17 of file datepattern.C. 00017 { 00018 date_.clear(); 00019 /* We use a simple brute-force procedure: copy the string 00020 to a C-string where we replace all non-digit chars with 00021 spaces. The repeatedly call strtol to parse this C string 00022 into a number of integers. See ``man strtol'' for details. 00023 */ 00024 char cs[s.size()+1]; 00025 00026 for (unsigned int i=0; i<s.size(); ++i) 00027 if (isdigit(s[i])) 00028 cs[i] = s[i]; 00029 else 00030 cs[i] = ' '; 00031 cs[s.size()] = '\0'; 00032 00033 const char* start(cs); 00034 char* end(cs); 00035 unsigned int n(0); 00036 00037 do { 00038 start = end; 00039 long l(strtol(start,&end,10)); 00040 if (end!=start) { 00041 ++n; 00042 if (l<0 || n>5) { // no negative stuff and no more than 5 numbers expected 00043 date_.clear(); 00044 return false; 00045 } 00046 if (n<5) // only 4 numbers stored. 00047 date_.push_back(static_cast<unsigned int>(l)); 00048 } 00049 } 00050 while (end!=start); 00051 return true; 00052 } |
|
Set components explicitly.
Definition at line 55 of file datepattern.C. Referenced by LogRecord::parse_date().
00056 { 00057 date_.resize(4); 00058 date_[0] = year; 00059 date_[1] = month; 00060 date_[2] = day; 00061 date_[3] = hours; 00062 } |
|
Definition at line 22 of file datepattern.h. 00022 { return date_[i]; } |
|
Definition at line 23 of file datepattern.h. Referenced by DatePattern(), and operator<<().
00023 { return date_.size(); } |
|
Definition at line 25 of file datepattern.h. 00025 { return date_ == p.date_; } |
|
Definition at line 26 of file datepattern.h. 00026 { return date_ < p.date_; } |
|
Definition at line 65 of file datepattern.C. 00065 { 00066 unsigned int sz(date.size()); 00067 // Print in format year-month-day hours:00. 00068 if (sz>0) { 00069 os << date[0] ; 00070 if (sz>1) { 00071 os << "-" << date[1]; 00072 if (sz>2) { 00073 os << "-" << date[2]; 00074 if (sz>3) 00075 os << " " << date[3] << ":00"; 00076 } 00077 } 00078 } 00079 return os; 00080 } |
|
Definition at line 30 of file datepattern.h. |