00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SBUILD_TYPES_H
00021 #define SBUILD_TYPES_H
00022
00023 #include <ctime>
00024 #include <ios>
00025 #include <locale>
00026 #include <string>
00027 #include <vector>
00028
00029 namespace sbuild
00030 {
00031
00033 typedef std::vector<std::string> string_list;
00034
00036 class date_base
00037 {
00038 public:
00039 typedef std::tm *(*break_time_func)(const time_t *timep, std:: tm *result);
00040
00041 date_base (time_t unix_time,
00042 break_time_func break_time):
00043 unix_time(unix_time),
00044 break_time(break_time)
00045 {}
00046
00047 ~date_base ()
00048 {}
00049
00050 template <class charT, class traits>
00051 friend
00052 std::basic_ostream<charT,traits>&
00053 operator << (std::basic_ostream<charT,traits>& stream,
00054 date_base const& dt)
00055 {
00056 std::ios_base::iostate err = std::ios_base::goodbit;
00057
00058 std::tm dtm;
00059 if ((dt.break_time(&dt.unix_time, &dtm)) == 0)
00060 {
00061 err = std::ios_base::badbit;
00062 }
00063 else
00064 {
00065 try
00066 {
00067 typename std::basic_ostream<charT, traits>::sentry sentry(stream);
00068 if (sentry)
00069 {
00070 const char nfmt[] = "%d %b %Y";
00071 charT wfmt[sizeof(nfmt)/sizeof(nfmt[0])];
00072 std::use_facet<std::ctype<charT> >(stream.getloc())
00073 .widen(nfmt, nfmt + (sizeof(nfmt)/sizeof(nfmt[0])) - 1, wfmt);
00074
00075 typedef std::time_put<charT,std::ostreambuf_iterator<charT,traits> >
00076 time_type;
00077 if (std::use_facet<time_type>(stream.getloc())
00078 .put(stream, stream, stream.fill(),
00079 &dtm, wfmt + 0, wfmt + sizeof(wfmt)/sizeof(wfmt[0]) - 1)
00080 .failed())
00081 {
00082 err = std::ios_base::badbit;
00083 }
00084 stream.width(0);
00085 }
00086 }
00087 catch (...)
00088 {
00089 bool flag = false;
00090 try
00091 {
00092 stream.setstate(std::ios::failbit);
00093 }
00094 catch (std::ios_base::failure)
00095 {
00096 flag = true;
00097 }
00098 if (flag)
00099 throw;
00100 }
00101 }
00102
00103 if (err)
00104 stream.setstate(err);
00105
00106 return stream;
00107 }
00108
00109 private:
00110 time_t unix_time;
00111 break_time_func break_time;
00112 };
00113
00114 class gmdate : public date_base
00115 {
00116 public:
00117 gmdate (time_t unix_time):
00118 date_base(unix_time, gmtime_r)
00119 {}
00120
00121 ~gmdate ()
00122 {}
00123 };
00124
00125 class date : public date_base
00126 {
00127 public:
00128 date (time_t unix_time):
00129 date_base(unix_time, localtime_r)
00130 {}
00131
00132 ~date ()
00133 {}
00134 };
00135
00136 }
00137
00138 #endif
00139
00140
00141
00142
00143
00144