Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

datetime.h

Go to the documentation of this file.
00001 #ifndef MYSQLPP_DATETIME_H
00002 #define MYSQLPP_DATETIME_H
00003 
00007 
00008 #include "defs.h"
00009 
00010 #include "coldata.h"
00011 #include "stream2string.h"
00012 #include "tiny_int.h"
00013 
00014 #include <string>
00015 #include <sstream>
00016 #include <iostream>
00017 
00018 namespace mysqlpp {
00019 
00021 struct mysql_dt_base {
00022   virtual std::ostream& out_stream(std::ostream&) const = 0;
00023 
00024   operator std::string ();
00025 };
00026 
00028 // Doxygen will not generate documentation for this section.
00029 
00030 template <class T>
00031 struct DTbase {
00032   virtual short int compare(const T &other) const = 0;
00033 
00034   bool operator == (const T &other) const {return !compare(other);}
00035   bool operator != (const T &other) const {return compare(other);}
00036   bool operator <  (const T &other) const {return compare(other) < 0;}
00037   bool operator <= (const T &other) const {return compare(other) <= 0;}
00038   bool operator >  (const T &other) const {return compare(other) > 0;}
00039   bool operator >= (const T &other) const {return compare(other) >= 0;}
00040 };
00041 
00043 
00044 
00046 struct mysql_date : virtual public mysql_dt_base {
00047   short int year;
00048   tiny_int  month;
00049   tiny_int  day;
00050 
00057   std::ostream& out_stream(std::ostream& os) const;
00058 
00060   cchar* convert (cchar*);
00061 protected:
00062   short int compare(const mysql_date *other) const;
00063 };
00064 
00065 
00070 struct Date : public mysql_date, public DTbase<Date>
00071 {
00072   Date () {};
00073   Date (cchar* str) {convert(str);}
00074   Date (const ColData &str);
00075   Date (const std::string &str);
00076 
00077   short int compare(const Date& other) const 
00078   {
00079         return mysql_date::compare(&other);
00080   }
00081 };
00082 
00083 inline std::ostream& operator << (std::ostream& s, const Date& d)
00084 {
00085         return d.out_stream(s);
00086 }
00087 
00088 
00090 struct mysql_time : virtual public mysql_dt_base {
00091   tiny_int hour;
00092   tiny_int minute;  
00093   tiny_int second;
00094 
00101   std::ostream& out_stream(std::ostream& os) const;
00102 
00104   cchar* convert (cchar*);
00105 protected:
00106   short int compare(const mysql_time *other) const;
00107 };  
00108 
00109 
00114 struct Time : public mysql_time, public DTbase<Time>
00115 {
00116   Time () {};
00117   Time (cchar* str) {convert(str);}
00118   Time (const ColData &str);
00119   Time (const std::string &str);
00120 
00121   short int compare(const Time& other) const 
00122     {return mysql_time::compare(&other);}
00123 };
00124 
00125 inline std::ostream& operator << (std::ostream& s, const Time& d)
00126 {
00127         return d.out_stream(s);
00128 }
00129 
00130 
00136 struct DateTime : public mysql_date, public mysql_time,
00137                        public DTbase<DateTime>
00138 {
00139   DateTime () {}
00140   DateTime (cchar* str) {convert(str);}
00141   DateTime (const ColData &str);
00142   DateTime (const std::string &str);
00143 
00144   short int compare(const DateTime& other) const;
00145 
00152   std::ostream& out_stream(std::ostream& os) const;
00153 
00155   cchar* convert (cchar*);
00156 };
00157 
00158 inline std::ostream& operator << (std::ostream& s, const DateTime& d)
00159 {
00160         return d.out_stream(s);
00161 }
00162 
00163 inline mysql_dt_base::operator std::string()
00164 {
00165   return stream2string<std::string>(*this);
00166 }
00167 
00168 inline Date::Date(const ColData &str)
00169 {
00170         convert(str.c_str());
00171 }
00172 
00173 inline Date::Date(const std::string &str)
00174 {
00175         convert(str.c_str());
00176 }
00177 
00178 inline Time::Time(const ColData &str)
00179 {
00180         convert(str.c_str());
00181 }
00182 
00183 inline Time::Time(const std::string &str)
00184 {
00185         convert(str.c_str());
00186 }
00187 
00188 inline DateTime::DateTime(const ColData &str)
00189 {
00190         convert(str.c_str());
00191 }
00192 
00193 inline DateTime::DateTime(const std::string &str)
00194 {
00195         convert(str.c_str());
00196 }
00197 
00198 } // end namespace mysqlpp
00199 
00200 #endif // !defined(MYSQLPP_DATETIME_H)
00201 

Generated on Thu May 5 05:30:43 2005 for MySQL++ by doxygen1.2.18