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
    00002
    00003
    00004
    00005 /***********************************************************************
    00006  Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
    00007  MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
    00008  Others may also hold copyrights on code in this file.  See the CREDITS
    00009  file in the top directory of the distribution for details.
    00010
    00011  This file is part of MySQL++.
    00012
    00013  MySQL++ is free software; you can redistribute it and/or modify it
    00014  under the terms of the GNU Lesser General Public License as published
    00015  by the Free Software Foundation; either version 2.1 of the License, or
    00016  (at your option) any later version.
    00017
    00018  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
    00019  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00020  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00021  License for more details.
    00022
    00023  You should have received a copy of the GNU Lesser General Public
    00024  License along with MySQL++; if not, write to the Free Software
    00025  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00026  USA
    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
    00053 template <class T> struct DTbase
    00054 {
    00056         virtual ~DTbase() { }
    00057
    00059         operator std::string() const
    00060         {
    00061                 return stream2string<std::string>(*this);
    00062         }
    00063
    00068         MYSQLPP_EXPORT virtual short compare(const T& other) const = 0;
    00069
    00071         bool operator ==(const T& other) const
    00072         {
    00073                 return !compare(other);
    00074         }
    00075
    00077         bool operator !=(const T& other) const
    00078         {
    00079                 return compare(other);
    00080         }
    00081
    00083         bool operator <(const T& other) const
    00084         {
    00085                 return compare(other) < 0;
    00086         }
    00087
    00089         bool operator <=(const T& other) const
    00090         {
    00091                 return compare(other) <= 0;
    00092         }
    00093
    00095         bool operator >(const T& other) const
    00096         {
    00097                 return compare(other) > 0;
    00098         }
    00099
    00101         bool operator >=(const T& other) const
    00102         {
    00103                 return compare(other) >= 0;
    00104         }
    00105 };
    00106
    00107
    00112 struct DateTime : public DTbase<DateTime>
    00113 {
    00117         short int year;
    00118
    00120         tiny_int month;
    00121
    00123         tiny_int day;
    00124
    00126         tiny_int hour;
    00127
    00129         tiny_int minute;
    00130
    00132         tiny_int second;
    00133
    00135         DateTime() :
    00136         DTbase<DateTime>(),
    00137         year(0),
    00138         month(0),
    00139         day(0),
    00140         hour(0),
    00141         minute(0),
    00142         second(0)
    00143         {
    00144         }
    00145
    00147         DateTime(const DateTime& other) :
    00148         DTbase<DateTime>(),
    00149         year(other.year),
    00150         month(other.month),
    00151         day(other.day),
    00152         hour(other.hour),
    00153         minute(other.minute),
    00154         second(other.second)
    00155         {
    00156         }
    00157
    00162         DateTime(cchar* str) { convert(str); }
    00163
    00167         DateTime(const ColData& str)
    00168         {
    00169                 convert(str.c_str());
    00170         }
    00171
    00175         DateTime(const std::string& str)
    00176         {
    00177                 convert(str.c_str());
    00178         }
    00179
    00187         MYSQLPP_EXPORT short compare(const DateTime& other) const;
    00188
    00190         MYSQLPP_EXPORT cchar* convert(cchar*);
    00191 };
    00192
    00193
    00202 MYSQLPP_EXPORT std::ostream& operator <<(std::ostream& os,
    00203                 const DateTime& dt);
    00204
    00205
    00210 struct Date : public DTbase<Date>
    00211 {
    00215         short int year;
    00216
    00218         tiny_int month;
    00219
    00221         tiny_int day;
    00222
    00224         Date() : year(0), month(0), day(0) { }
    00225
    00227         Date(short int y, tiny_int m, tiny_int d) :
    00228         DTbase<Date>(),
    00229         year(y),
    00230         month(m),
    00231         day(d)
    00232         {
    00233         }
    00234
    00236         Date(const Date& other) :
    00237         DTbase<Date>(),
    00238         year(other.year),
    00239         month(other.month),
    00240         day(other.day)
    00241         {
    00242         }
    00243
    00245         Date(const DateTime& other) :
    00246         DTbase<Date>(),
    00247         year(other.year),
    00248         month(other.month),
    00249         day(other.day)
    00250         {
    00251         }
    00252
    00257         Date(cchar* str) { convert(str); }
    00258
    00262         Date(const ColData& str) { convert(str.c_str()); }
    00263
    00267         Date(const std::string& str)
    00268         {
    00269                 convert(str.c_str());
    00270         }
    00271
    00276         MYSQLPP_EXPORT short int compare(const Date& other) const;
    00277
    00279         MYSQLPP_EXPORT cchar* convert(cchar*);
    00280 };
    00281
    00288 MYSQLPP_EXPORT std::ostream& operator <<(std::ostream& os,
    00289                 const Date& d);
    00290
    00291
    00296 struct Time : public DTbase<Time>
    00297 {
    00299         tiny_int hour;
    00300
    00302         tiny_int minute;
    00303
    00305         tiny_int second;
    00306
    00308         Time() : hour(0), minute(0), second(0) { }
    00309
    00311         Time(tiny_int h, tiny_int m, tiny_int s) :
    00312         hour(h),
    00313         minute(m),
    00314         second(s)
    00315         {
    00316         }
    00317
    00319         Time(const Time& other) :
    00320         DTbase<Time>(),
    00321         hour(other.hour),
    00322         minute(other.minute),
    00323         second(other.second)
    00324         {
    00325         }
    00326
    00328         Time(const DateTime& other) :
    00329         DTbase<Time>(),
    00330         hour(other.hour),
    00331         minute(other.minute),
    00332         second(other.second)
    00333         {
    00334         }
    00335
    00340         Time(cchar* str) { convert(str); }
    00341
    00345         Time(const ColData& str) { convert(str.c_str()); }
    00346
    00350         Time(const std::string& str)
    00351         {
    00352                 convert(str.c_str());
    00353         }
    00354
    00356         MYSQLPP_EXPORT cchar* convert(cchar*);
    00357
    00362         MYSQLPP_EXPORT short int compare(const Time& other) const;
    00363 };
    00364
    00372 MYSQLPP_EXPORT std::ostream& operator <<(std::ostream& os,
    00373                 const Time& t);
    00374
    00375
    00376 } // end namespace mysqlpp
    00377
    00378 #endif // !defined(MYSQLPP_DATETIME_H)