Author: wyoung
Date: Sat Feb 2 02:37:56 2008
New Revision: 2152
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2152&view=rev
Log:
Renamed DTbase to Comparable and gave it its own header file. The
previous name was confusing: yes, it was the base class for all the date
and time classes, but that's didn't tell you what it *did*. With this
clarified, we may find other places to mix this class in.
Added:
trunk/lib/comparable.h
Modified:
trunk/lib/datetime.h
Added: trunk/lib/comparable.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/comparable.h?rev=2152&view=auto
==============================================================================
--- trunk/lib/comparable.h (added)
+++ trunk/lib/comparable.h Sat Feb 2 02:37:56 2008
@@ -1,0 +1,94 @@
+/// \file comparable.h
+/// \brief Declares the Comparable<T> mixin
+
+/***********************************************************************
+ Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
+ (c) 2004-2008 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++.
+
+ MySQL++ is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ MySQL++ is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with MySQL++; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ USA
+***********************************************************************/
+
+#if !defined(MYSQLPP_COMPARABLE_H)
+#define MYSQLPP_COMPARABLE_H
+
+/// \brief Mix-in that gives its subclass a full set of comparison
+/// operators.
+///
+/// Simply by inheriting publically from this and implementing
+/// compare(), the subclass gains a full set of comparison operators,
+/// because all of the operators are implemented in terms of compare().
+template <class T>
+class Comparable
+{
+public:
+ /// \brief Returns true if "other" is equal to this object
+ bool operator ==(const T& other) const
+ {
+ return !compare(other);
+ }
+
+ /// \brief Returns true if "other" is not equal to this object
+ bool operator !=(const T& other) const
+ {
+ return compare(other);
+ }
+
+ /// \brief Returns true if "other" is less than this object
+ bool operator <(const T& other) const
+ {
+ return compare(other) < 0;
+ }
+
+ /// \brief Returns true if "other" is less than or equal to this object
+ bool operator <=(const T& other) const
+ {
+ return compare(other) <= 0;
+ }
+
+ /// \brief Returns true if "other" is greater than this object
+ bool operator >(const T& other) const
+ {
+ return compare(other) > 0;
+ }
+
+ /// \brief Returns true if "other" is greater than or equal to this
object
+ bool operator >=(const T& other) const
+ {
+ return compare(other) >= 0;
+ }
+
+protected:
+ /// \brief Destroy object
+ ///
+ /// This class has nothing to destroy, but declaring the dtor
+ /// virtual placates some compilers set to high warning levels.
+ /// Protecting it ensures you can't delete subclasses through base
+ /// class pointers, which makes no sense because this class isn't
+ /// made for polymorphism. It's just a mixin.
+ virtual ~Comparable() { }
+
+ /// \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.
+ virtual int compare(const T& other) const = 0;
+};
+
+#endif // !defined(MYSQLPP_COMPARABLE_H)
Modified: trunk/lib/datetime.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/datetime.h?rev=2152&r1=2151&r2=2152&view=diff
==============================================================================
--- trunk/lib/datetime.h (original)
+++ trunk/lib/datetime.h Sat Feb 2 02:37:56 2008
@@ -31,72 +31,12 @@
#include "common.h"
+#include "comparable.h"
+
#include <string>
#include <iostream>
namespace mysqlpp {
-
-/// \brief Base class template for MySQL++ date and time classes.
-///
-/// A subclass mixes this class in to its interface, implements
-/// compare(), and thereby gains a full set of comparison operators.
-template <class T>
-class MYSQLPP_EXPORT DTbase
-{
-public:
- /// \brief Returns true if "other" is equal to this object
- bool operator ==(const T& other) const
- {
- return !compare(other);
- }
-
- /// \brief Returns true if "other" is not equal to this object
- bool operator !=(const T& other) const
- {
- return compare(other);
- }
-
- /// \brief Returns true if "other" is less than this object
- bool operator <(const T& other) const
- {
- return compare(other) < 0;
- }
-
- /// \brief Returns true if "other" is less than or equal to this object
- bool operator <=(const T& other) const
- {
- return compare(other) <= 0;
- }
-
- /// \brief Returns true if "other" is greater than this object
- bool operator >(const T& other) const
- {
- return compare(other) > 0;
- }
-
- /// \brief Returns true if "other" is greater than or equal to this
object
- bool operator >=(const T& other) const
- {
- return compare(other) >= 0;
- }
-
-protected:
- /// \brief Destroy object
- ///
- /// This class has nothing to destroy, but declaring the dtor
- /// virtual placates some compilers set to high warning levels.
- /// Protecting it ensures you can't delete subclasses through base
- /// class pointers, which makes no sense because this class isn't
- /// made for polymorphism. It's just a mixin.
- virtual ~DTbase() { }
-
- /// \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.
- virtual int compare(const T& other) const = 0;
-};
-
/// \brief C++ form of SQL's DATETIME type.
///
@@ -105,12 +45,12 @@
/// to SQL string form, extract the individual y/m/d h:m:s values,
/// convert it to C's time_t, etc.
-class MYSQLPP_EXPORT DateTime : public DTbase<DateTime>
+class MYSQLPP_EXPORT DateTime : public Comparable<DateTime>
{
public:
/// \brief Default constructor
DateTime() :
- DTbase<DateTime>(),
+ Comparable<DateTime>(),
year_(0),
month_(0),
day_(0),
@@ -131,7 +71,7 @@
/// \param s second_
DateTime(unsigned short y, unsigned char mon, unsigned char d,
unsigned char h, unsigned char min, unsigned char s) :
- DTbase<DateTime>(),
+ Comparable<DateTime>(),
year_(y),
month_(mon),
day_(d),
@@ -144,7 +84,7 @@
/// \brief Initialize object as a copy of another Date
DateTime(const DateTime& other) :
- DTbase<DateTime>(),
+ Comparable<DateTime>(),
year_(other.year_),
month_(other.month_),
day_(other.day_),
@@ -276,7 +216,7 @@
///
/// Objects of this class can be inserted into streams, and
/// initialized from SQL DATE strings.
-class MYSQLPP_EXPORT Date : public DTbase<Date>
+class MYSQLPP_EXPORT Date : public Comparable<Date>
{
public:
/// \brief Default constructor
@@ -284,7 +224,7 @@
/// \brief Initialize object
Date(unsigned short y, unsigned char m, unsigned char d) :
- DTbase<Date>(),
+ Comparable<Date>(),
year_(y),
month_(m),
day_(d)
@@ -293,7 +233,7 @@
/// \brief Initialize object as a copy of another Date
Date(const Date& other) :
- DTbase<Date>(),
+ Comparable<Date>(),
year_(other.year_),
month_(other.month_),
day_(other.day_)
@@ -302,7 +242,7 @@
/// \brief Initialize object from date part of date/time object
Date(const DateTime& other) :
- DTbase<Date>(),
+ Comparable<Date>(),
year_(other.year()),
month_(other.month()),
day_(other.day())
@@ -383,7 +323,7 @@
///
/// Objects of this class can be inserted into streams, and
/// initialized from SQL TIME strings.
-class MYSQLPP_EXPORT Time : public DTbase<Time>
+class MYSQLPP_EXPORT Time : public Comparable<Time>
{
public:
/// \brief Default constructor
@@ -399,7 +339,7 @@
/// \brief Initialize object as a copy of another Time
Time(const Time& other) :
- DTbase<Time>(),
+ Comparable<Time>(),
hour_(other.hour_),
minute_(other.minute_),
second_(other.second_)
@@ -408,7 +348,7 @@
/// \brief Initialize object from time part of date/time object
Time(const DateTime& other) :
- DTbase<Time>(),
+ Comparable<Time>(),
hour_(other.hour()),
minute_(other.minute()),
second_(other.second())
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits