MySQL++  3.3.0
comparable.h
Go to the documentation of this file.
1 
4 /***********************************************************************
5  Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
6  (c) 2004-2008 by Educational Technology Resources, Inc. Others may
7  also hold copyrights on code in this file. See the CREDITS.txt file
8  in the top directory of the distribution for details.
9 
10  This file is part of MySQL++.
11 
12  MySQL++ is free software; you can redistribute it and/or modify it
13  under the terms of the GNU Lesser General Public License as published
14  by the Free Software Foundation; either version 2.1 of the License, or
15  (at your option) any later version.
16 
17  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
18  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20  License for more details.
21 
22  You should have received a copy of the GNU Lesser General Public
23  License along with MySQL++; if not, write to the Free Software
24  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25  USA
26 ***********************************************************************/
27 
28 #if !defined(MYSQLPP_COMPARABLE_H)
29 #define MYSQLPP_COMPARABLE_H
30 
31 namespace mysqlpp {
32 
39 template <class T>
41 {
42 public:
44  bool operator ==(const T& other) const
45  {
46  return !compare(other);
47  }
48 
50  bool operator !=(const T& other) const
51  {
52  return compare(other);
53  }
54 
56  bool operator <(const T& other) const
57  {
58  return compare(other) < 0;
59  }
60 
62  bool operator <=(const T& other) const
63  {
64  return compare(other) <= 0;
65  }
66 
68  bool operator >(const T& other) const
69  {
70  return compare(other) > 0;
71  }
72 
74  bool operator >=(const T& other) const
75  {
76  return compare(other) >= 0;
77  }
78 
79 protected:
87  virtual ~Comparable() { }
88 
93  virtual int compare(const T& other) const = 0;
94 };
95 
96 }
97 
98 #endif // !defined(MYSQLPP_COMPARABLE_H)
Mix-in that gives its subclass a full set of comparison operators.
Definition: comparable.h:41
virtual ~Comparable()
Destroy object.
Definition: comparable.h:87
bool operator==(const T &other) const
Returns true if "other" is equal to this object.
Definition: comparable.h:44
virtual int compare(const T &other) const =0
Compare this object to another of the same type.
bool operator>(const T &other) const
Returns true if "other" is greater than this object.
Definition: comparable.h:68
bool operator<=(const T &other) const
Returns true if "other" is less than or equal to this object.
Definition: comparable.h:62
bool operator!=(const T &other) const
Returns true if "other" is not equal to this object.
Definition: comparable.h:50
bool operator<(const T &other) const
Returns true if "other" is less than this object.
Definition: comparable.h:56
bool operator>=(const T &other) const
Returns true if "other" is greater than or equal to this object.
Definition: comparable.h:74