Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members File Members

# compare.h

Go to the documentation of this file.

    00001
    00002
    00003
    00004
    00005
    00006
    00007
    00008 /***********************************************************************
    00009  Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
    00010  MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
    00011  Others may also hold copyrights on code in this file.  See the CREDITS
    00012  file in the top directory of the distribution for details.
    00013
    00014  This file is part of MySQL++.
    00015
    00016  MySQL++ is free software; you can redistribute it and/or modify it
    00017  under the terms of the GNU Lesser General Public License as published
    00018  by the Free Software Foundation; either version 2.1 of the License, or
    00019  (at your option) any later version.
    00020
    00021  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
    00022  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00023  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00024  License for more details.
    00025
    00026  You should have received a copy of the GNU Lesser General Public
    00027  License along with MySQL++; if not, write to the Free Software
    00028  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00029  USA
    00030 ***********************************************************************/
    00031
    00032 #ifndef MYSQLPP_COMPARE_H
    00033 #define MYSQLPP_COMPARE_H
    00034
    00035 #include "row.h"
    00036
    00037 #include <cstring>
    00038 #include <functional>
    00039
    00040 namespace mysqlpp {
    00041
    00046
    00047 template <class BinaryPred, class CmpType>
    00048 class MysqlCmp : public std::unary_function<const Row&, bool>
    00049 {
    00050 protected:
    00052         unsigned int index;
    00053
    00055         BinaryPred func;
    00056
    00058         CmpType cmp2;
    00059
    00060 public:
    00068         MysqlCmp(uint i, const BinaryPred& f, const CmpType& c) :
    00069         index(i),
    00070         func(f),
    00071         cmp2(c)
    00072         {
    00073         }
    00074
    00079         bool operator ()(const Row& cmp1) const
    00080         {
    00081                 return func(cmp2, cmp1[this->index]);
    00082         }
    00083 };
    00084
    00085
    00089
    00090 template <class BinaryPred>
    00091 class MysqlCmpCStr : public MysqlCmp<BinaryPred, const char*>
    00092 {
    00093 public:
    00101         MysqlCmpCStr(uint i, const BinaryPred& f, const char *c) :
    00102         MysqlCmp<BinaryPred, const char*>(i, f, c)
    00103         {
    00104         }
    00105
    00110         bool operator ()(const Row& cmp1) const
    00111         {
    00112                 return MysqlCmp<BinaryPred, const char*>::func(
    00113                                 MysqlCmp<BinaryPred, const char*>::cmp2,
    00114                                 cmp1[this->index]);
    00115         }
    00116 };
    00117
    00118
    00128 template <class BinaryPred, class CmpType> MysqlCmp<BinaryPred, CmpType>
    00129 mysql_cmp(uint i, const BinaryPred& func, const CmpType& cmp2)
    00130 {
    00131         return MysqlCmp<BinaryPred, CmpType>(i, func, cmp2);
    00132 }
    00133
    00134
    00145 template <class BinaryPred> MysqlCmpCStr<BinaryPred>
    00146 mysql_cmp_cstr(uint i, const BinaryPred& func, const char* cmp2)
    00147 {
    00148         return MysqlCmpCStr<BinaryPred>(i, func, cmp2);
    00149 }
    00150
    00151
    00153
    00154 typedef std::binary_function<const char*, const char*, bool>
    00155                 bin_char_pred;
    00156
    00157
    00160 struct cstr_equal_to : bin_char_pred
    00161 {
    00162 #if !defined(DOXYGEN_IGNORE)
    00163 // Doxygen will not generate documentation for this section.
    00164         bool operator ()(const char* x, const char* y) const
    00165         {
    00166                 return !std::strcmp(x, y);
    00167         }
    00168 #endif // !defined(DOXYGEN_IGNORE)
    00169 };
    00170
    00171
    00174 struct cstr_not_equal_to : bin_char_pred
    00175 {
    00176 #if !defined(DOXYGEN_IGNORE)
    00177 // Doxygen will not generate documentation for this section.
    00178         bool operator ()(const char* x, const char* y) const
    00179         {
    00180                 return std::strcmp(x, y) != 0;
    00181         }
    00182 #endif // !defined(DOXYGEN_IGNORE)
    00183 };
    00184
    00185
    00188 struct cstr_less : bin_char_pred
    00189 {
    00190 #if !defined(DOXYGEN_IGNORE)
    00191 // Doxygen will not generate documentation for this section.
    00192         bool operator ()(const char* x, const char* y) const
    00193         {
    00194                 return std::strcmp(x, y) > 0;
    00195         }
    00196 #endif // !defined(DOXYGEN_IGNORE)
    00197 };
    00198
    00199
    00202 struct cstr_less_equal : bin_char_pred
    00203 {
    00204 #if !defined(DOXYGEN_IGNORE)
    00205 // Doxygen will not generate documentation for this section.
    00206         bool operator ()(const char* x, const char* y) const
    00207         {
    00208                 return std::strcmp(x, y) >= 0;
    00209         }
    00210 #endif // !defined(DOXYGEN_IGNORE)
    00211 };
    00212
    00213
    00216 struct cstr_greater : bin_char_pred
    00217 {
    00218 #if !defined(DOXYGEN_IGNORE)
    00219 // Doxygen will not generate documentation for this section.
    00220         bool operator ()(const char* x, const char* y) const
    00221         {
    00222                 return std::strcmp(x, y) < 0;
    00223         }
    00224 #endif // !defined(DOXYGEN_IGNORE)
    00225 };
    00226
    00227
    00230 struct cstr_greater_equal : bin_char_pred
    00231 {
    00232 #if !defined(DOXYGEN_IGNORE)
    00233 // Doxygen will not generate documentation for this section.
    00234         bool operator ()(const char* x, const char* y) const
    00235         {
    00236                 return std::strcmp(x, y) <= 0;
    00237         }
    00238 #endif // !defined(DOXYGEN_IGNORE)
    00239 };
    00240
    00241
    00242 } // end namespace mysqlpp
    00243
    00244 #endif