00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef MYSQLPP_DATETIME_H
00030 #define MYSQLPP_DATETIME_H
00031
00032 #include "defs.h"
00033
00034 #include "coldata.h"
00035 #include "stream2string.h"
00036 #include "tiny_int.h"
00037
00038 #include <string>
00039 #include <sstream>
00040 #include <iostream>
00041
00042 namespace mysqlpp {
00043
00045 struct mysql_dt_base
00046 {
00047 #if !defined(DOXYGEN_IGNORE)
00048
00049 virtual std::ostream& out_stream(std::ostream&) const = 0;
00050 operator std::string() const
00051 {
00052 return stream2string<std::string>(*this);
00053 }
00054 #endif // !defined(DOXYGEN_IGNORE)
00055 };
00056
00057
00064 template <class T> struct DTbase
00065 {
00070 virtual short int compare(const T& other) const = 0;
00071
00073 bool operator ==(const T& other) const { return !compare(other); }
00074
00076 bool operator !=(const T& other) const { return compare(other); }
00077
00079 bool operator <(const T& other) const { return compare(other) < 0; }
00080
00082 bool operator <=(const T& other) const { return compare(other) <= 0; }
00083
00085 bool operator >(const T& other) const { return compare(other) > 0; }
00086
00088 bool operator >=(const T& other) const { return compare(other) >= 0; }
00089 };
00090
00091
00093 struct mysql_date : virtual public mysql_dt_base
00094 {
00098 short int year;
00099
00101 tiny_int month;
00102
00104 tiny_int day;
00105
00111 std::ostream& out_stream(std::ostream& os) const;
00112
00114 cchar* convert(cchar*);
00115
00116 protected:
00124 short int compare(const mysql_date* other) const;
00125 };
00126
00127
00132
00133 struct Date : public mysql_date, public DTbase<Date>
00134 {
00136 Date() { };
00137
00142 Date(cchar* str) { convert(str); }
00143
00147 Date(const ColData& str) { convert(str.c_str()); }
00148
00152 Date(const std::string& str) { convert(str.c_str()); }
00153
00157 short int compare(const Date& other) const
00158 {
00159 return mysql_date::compare(&other);
00160 }
00161 };
00162
00163
00166
00167 inline std::ostream& operator <<(std::ostream& s, const Date& d)
00168 {
00169 return d.out_stream(s);
00170 }
00171
00172
00174
00175 struct mysql_time : virtual public mysql_dt_base
00176 {
00178 tiny_int hour;
00179
00181 tiny_int minute;
00182
00184 tiny_int second;
00185
00191 std::ostream& out_stream(std::ostream& os) const;
00192
00194 cchar* convert(cchar*);
00195
00196 protected:
00204 short int compare(const mysql_time* other) const;
00205 };
00206
00207
00212 struct Time : public mysql_time, public DTbase<Time>
00213 {
00215 Time() { };
00216
00221 Time(cchar* str)
00222 {
00223 convert(str);
00224 }
00225
00229 Time(const ColData& str);
00230
00234 Time(const std::string& str);
00235
00239 short int compare(const Time& other) const
00240 {
00241 return mysql_time::compare(&other);
00242 }
00243 };
00244
00245
00248
00249 inline std::ostream& operator <<(std::ostream& s, const Time& d)
00250 {
00251 return d.out_stream(s);
00252 }
00253
00254
00260
00261 struct DateTime : public mysql_date, public mysql_time,
00262 public DTbase<DateTime>
00263 {
00265 DateTime() { }
00266
00271 DateTime(cchar* str)
00272 {
00273 convert(str);
00274 }
00275
00279 DateTime(const ColData& str);
00280
00284 DateTime(const std::string& str);
00285
00293 short int compare(const DateTime& other) const;
00294
00301 std::ostream& out_stream(std::ostream& os) const;
00302
00304 cchar* convert(cchar*);
00305 };
00306
00307
00310 inline std::ostream& operator <<(std::ostream& s, const DateTime& d)
00311 {
00312 return d.out_stream(s);
00313 }
00314
00315
00316 inline Time::Time(const ColData& str)
00317 {
00318 convert(str.c_str());
00319 }
00320
00321
00322 inline Time::Time(const std::string& str)
00323 {
00324 convert(str.c_str());
00325 }
00326
00327
00328 inline DateTime::DateTime(const ColData& str)
00329 {
00330 convert(str.c_str());
00331 }
00332
00333
00334 inline DateTime::DateTime(const std::string& str)
00335 {
00336 convert(str.c_str());
00337 }
00338
00339 }
00340
00341 #endif // !defined(MYSQLPP_DATETIME_H)