# comparable.h

Go to the documentation of this file.

    00001
    00002
    00003
    00004 /***********************************************************************
    00005  Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
    00006  (c) 2004-2008 by Educational Technology Resources, Inc.  Others may
    00007  also hold copyrights on code in this file.  See the CREDITS.txt file
    00008  in the top directory of the distribution for details.
    00009
    00010  This file is part of MySQL++.
    00011
    00012  MySQL++ is free software; you can redistribute it and/or modify it
    00013  under the terms of the GNU Lesser General Public License as published
    00014  by the Free Software Foundation; either version 2.1 of the License, or
    00015  (at your option) any later version.
    00016
    00017  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
    00018  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00019  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00020  License for more details.
    00021
    00022  You should have received a copy of the GNU Lesser General Public
    00023  License along with MySQL++; if not, write to the Free Software
    00024  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00025  USA
    00026 ***********************************************************************/
    00027
    00028 #if !defined(MYSQLPP_COMPARABLE_H)
    00029 #define MYSQLPP_COMPARABLE_H
    00030
    00037 template <class T>
    00038 class Comparable
    00039 {
    00040 public:
    00042         bool operator ==(const T& other) const
    00043         {
    00044                 return !compare(other);
    00045         }
    00046
    00048         bool operator !=(const T& other) const
    00049         {
    00050                 return compare(other);
    00051         }
    00052
    00054         bool operator <(const T& other) const
    00055         {
    00056                 return compare(other) < 0;
    00057         }
    00058
    00060         bool operator <=(const T& other) const
    00061         {
    00062                 return compare(other) <= 0;
    00063         }
    00064
    00066         bool operator >(const T& other) const
    00067         {
    00068                 return compare(other) > 0;
    00069         }
    00070
    00072         bool operator >=(const T& other) const
    00073         {
    00074                 return compare(other) >= 0;
    00075         }
    00076
    00077 protected:
    00085         virtual ~Comparable() { }
    00086
    00091         virtual int compare(const T& other) const = 0;
    00092 };
    00093
    00094 #endif // !defined(MYSQLPP_COMPARABLE_H)