Author: wyoung
Date: Thu Nov  8 02:48:33 2007
New Revision: 1830

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1830&view=rev
Log:
Reduced dependencies of lib/datetime.h on other headers: moved one
function defn into the .cpp file, and using native C++ types where not
necessary to use other MySQL++ types.

Modified:
    trunk/lib/datetime.cpp
    trunk/lib/datetime.h

Modified: trunk/lib/datetime.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/datetime.cpp?rev=1830&r1=1829&r2=1830&view=diff
==============================================================================
--- trunk/lib/datetime.cpp (original)
+++ trunk/lib/datetime.cpp Thu Nov  8 02:48:33 2007
@@ -2,10 +2,10 @@
  datetime.cpp - Implements date and time classes compatible with MySQL's
        various date and time column types.
 
- Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
- Others may also hold copyrights on code in this file.  See the CREDITS
- file in the top directory of the distribution for details.
+ Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
+ (c) 2004-2007 by Educational Technology Resources, Inc.  Others may
+ also hold copyrights on code in this file.  See the CREDITS file in
+ the top directory of the distribution for details.
 
  This file is part of MySQL++.
 
@@ -29,6 +29,7 @@
 #include "common.h"
 
 #include "datetime.h"
+#include "stream2string.h"
 
 #include <iomanip>
 
@@ -37,6 +38,13 @@
 using namespace std;
 
 namespace mysqlpp {
+
+template <class T>
+DTbase<T>::operator std::string() const
+{
+       return stream2string(*this);
+}
+
 
 std::ostream& operator <<(std::ostream& os, const Date& d)
 {
@@ -81,19 +89,19 @@
        num[2] = *str++;
        num[3] = *str++;
        num[4] = 0;
-       year = short(strtol(num, 0, 10));
+       year = static_cast<unsigned short>(strtol(num, 0, 10));
        if (*str == '-') str++;
 
        num[0] = *str++;
        num[1] = *str++;
        num[2] = 0;
-       month = short(strtol(num, 0, 10));
+       month = static_cast<unsigned char>(strtol(num, 0, 10));
        if (*str == '-') str++;
 
        num[0] = *str++;
        num[1] = *str++;
        num[2] = 0;
-       day = short(strtol(num, 0, 10));
+       day = static_cast<unsigned char>(strtol(num, 0, 10));
 
        return str;
 }
@@ -106,19 +114,19 @@
        num[0] = *str++;
        num[1] = *str++;
        num[2] = 0;
-       hour = short(strtol(num,0,10));
+       hour = static_cast<unsigned char>(strtol(num,0,10));
        if (*str == ':') str++;
 
        num[0] = *str++;
        num[1] = *str++;
        num[2] = 0;
-       minute = short(strtol(num,0,10));
+       minute = static_cast<unsigned char>(strtol(num,0,10));
        if (*str == ':') str++;
 
        num[0] = *str++;
        num[1] = *str++;
        num[2] = 0;
-       second = short(strtol(num,0,10));
+       second = static_cast<unsigned char>(strtol(num,0,10));
 
        return str;
 }
@@ -144,7 +152,7 @@
 }
 
 
-short int Date::compare(const Date& other) const
+int Date::compare(const Date& other) const
 {
        if (year != other.year) return year - other.year;
        if (month != other.month) return month - other.month;
@@ -152,7 +160,7 @@
 }
 
 
-short int Time::compare(const Time& other) const
+int Time::compare(const Time& other) const
 {
        if (hour != other.hour) return hour - other.hour;
        if (minute != other.minute) return minute - other.minute;
@@ -160,7 +168,7 @@
 }
 
 
-short int DateTime::compare(const DateTime& other) const
+int DateTime::compare(const DateTime& other) const
 {
        Date d(*this), od(other);
        Time t(*this), ot(other);
@@ -180,7 +188,7 @@
        tm.tm_min = minute;
        tm.tm_hour = hour;
        tm.tm_mday = day;
-       tm.tm_mon = month - (tiny_int)1;
+       tm.tm_mon = month - 1;
        tm.tm_year = year - 1900;
        tm.tm_isdst = -1;
 

Modified: trunk/lib/datetime.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/datetime.h?rev=1830&r1=1829&r2=1830&view=diff
==============================================================================
--- trunk/lib/datetime.h (original)
+++ trunk/lib/datetime.h Thu Nov  8 02:48:33 2007
@@ -31,9 +31,6 @@
 
 #include "common.h"
 
-#include "stream2string.h"
-#include "tiny_int.h"
-
 #include <string>
 #include <iostream>
 
@@ -48,22 +45,20 @@
 ///
 /// This template also defines interfaces for converting the object to
 /// a string form, which a subclass must define.
-template <class T> struct DTbase
+template <class T>
+struct DTbase
 {
        /// \brief Destroy object
        virtual ~DTbase() { }
 
        /// \brief Return a copy of the item in C++ string form
-       operator std::string() const
-       {
-               return stream2string(*this);
-       }
+       MYSQLPP_EXPORT operator std::string() const;
 
        /// \brief Compare this object to another of the same type
        ///
        /// Returns < 0 if this object is "before" the other, 0 of they are
        /// equal, and > 0 if this object is "after" the other.
-       MYSQLPP_EXPORT virtual short compare(const T& other) const = 0;
+       MYSQLPP_EXPORT virtual int compare(const T& other) const = 0;
 
        /// \brief Returns true if "other" is equal to this object
        bool operator ==(const T& other) const
@@ -109,25 +104,12 @@
 /// initialized from MySQL DATETIME strings.
 struct DateTime : public DTbase<DateTime>
 {
-       /// \brief the year
-       ///
-       /// No surprises; the year 2005 is stored as the integer 2005.
-       short int year;
-
-       /// \brief the month, 1-12
-       tiny_int month;
-
-       /// \brief the day, 1-31
-       tiny_int day;
-
-       /// \brief hour, 0-23
-       tiny_int hour;
-
-       /// \brief minute, 0-59
-       tiny_int minute;
-       
-       /// \brief second, 0-59
-       tiny_int second;
+       unsigned short year;    ///< the year, as a simple integer
+       unsigned char month;    ///< the month, 1-12
+       unsigned char day;              ///< the day, 1-31
+       unsigned char hour;             ///< the hour, 0-23
+       unsigned char minute;   ///< the minute, 0-59
+       unsigned char second;   ///< the second, 0-59
 
        /// \brief Default constructor
        DateTime() :
@@ -180,7 +162,7 @@
        ///
        /// This method is protected because it is merely the engine used
        /// by the various operators in DTbase.
-       MYSQLPP_EXPORT short compare(const DateTime& other) const;
+       MYSQLPP_EXPORT int compare(const DateTime& other) const;
 
        /// \brief Parse a MySQL date and time string into this object.
        MYSQLPP_EXPORT cchar* convert(cchar*);
@@ -208,22 +190,15 @@
 /// initialized from MySQL DATE strings.
 struct Date : public DTbase<Date>
 {
-       /// \brief the year
-       ///
-       /// No surprises; the year 2005 is stored as the integer 2005.
-       short int year;
-
-       /// \brief the month, 1-12
-       tiny_int month;
-
-       /// \brief the day, 1-31
-       tiny_int day;
+       unsigned short year;    ///< the year, as a simple integer
+       unsigned char month;    ///< the month, 1-12
+       unsigned char day;              ///< the day, 1-31
 
        /// \brief Default constructor
        Date() : year(0), month(0), day(0) { }
 
        /// \brief Initialize object
-       Date(short int y, tiny_int m, tiny_int d) :
+       Date(unsigned short y, unsigned char m, unsigned char d) :
        DTbase<Date>(),
        year(y),
        month(m),
@@ -265,7 +240,7 @@
        ///
        /// Returns < 0 if this date is before the other, 0 of they are
        /// equal, and > 0 if this date is after the other.
-       MYSQLPP_EXPORT short int compare(const Date& other) const;
+       MYSQLPP_EXPORT int compare(const Date& other) const;
 
        /// \brief Parse a MySQL date string into this object.
        MYSQLPP_EXPORT cchar* convert(cchar*);
@@ -287,20 +262,15 @@
 /// initialized from MySQL TIME strings.
 struct Time : public DTbase<Time>
 {
-       /// \brief hour, 0-23
-       tiny_int hour;
-
-       /// \brief minute, 0-59
-       tiny_int minute;
-       
-       /// \brief second, 0-59
-       tiny_int second;
+       unsigned char hour;             ///< the hour, 0-23
+       unsigned char minute;   ///< the minute, 0-59
+       unsigned char second;   ///< the second, 0-59
 
        /// \brief Default constructor
        Time() : hour(0), minute(0), second(0) { }
 
        /// \brief Initialize object
-       Time(tiny_int h, tiny_int m, tiny_int s) :
+       Time(unsigned char h, unsigned char m, unsigned char s) :
        hour(h),
        minute(m),
        second(s)
@@ -346,7 +316,7 @@
        ///
        /// Returns < 0 if this time is before the other, 0 of they are
        /// equal, and > 0 if this time is after the other.
-       MYSQLPP_EXPORT short int compare(const Time& other) const;
+       MYSQLPP_EXPORT int compare(const Time& other) const;
 };
 
 /// \brief Inserts a Time object into a C++ stream in a MySQL-compatible


_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits

Reply via email to