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,
    00069                         const CmpType& c) :
    00070         index(i),
    00071         func(f),
    00072         cmp2(c)
    00073         {
    00074         }
    00075
    00080         bool operator ()(const Row& cmp1) const
    00081         {
    00082                 return func(cmp2, cmp1[this->index]);
    00083         }
    00084 };
    00085
    00086
    00090
    00091 template <class BinaryPred>
    00092 class MysqlCmpCStr : public MysqlCmp<BinaryPred, const char*>
    00093 {
    00094 public:
    00102         MysqlCmpCStr(uint i, const BinaryPred& f,
    00103                         const char *c) :
    00104         MysqlCmp<BinaryPred, const char*>(i, f, c)
    00105         {
    00106         }
    00107
    00112         bool operator ()(const Row& cmp1) const
    00113         {
    00114                 return MysqlCmp<BinaryPred, const char*>::func(
    00115                                 MysqlCmp<BinaryPred, const char*>::cmp2,
    00116                                 cmp1[this->index]);
    00117         }
    00118 };
    00119
    00120
    00130 template <class BinaryPred, class CmpType> MysqlCmp<BinaryPred, CmpType>
    00131 mysql_cmp(uint i, const BinaryPred& func, const CmpType& cmp2)
    00132 {
    00133         return MysqlCmp<BinaryPred, CmpType>(i, func, cmp2);
    00134 }
    00135
    00136
    00147 template <class BinaryPred> MysqlCmpCStr<BinaryPred>
    00148 mysql_cmp_cstr(uint i, const BinaryPred& func, const char* cmp2)
    00149 {
    00150         return MysqlCmpCStr<BinaryPred>(i, func, cmp2);
    00151 }
    00152
    00153
    00155
    00156 typedef std::binary_function<const char*, const char*, bool>
    00157                 bin_char_pred;
    00158
    00159
    00162 struct cstr_equal_to : bin_char_pred
    00163 {
    00164 #if !defined(DOXYGEN_IGNORE)
    00165 // Doxygen will not generate documentation for this section.
    00166         bool operator ()(const char* x, const char* y) const
    00167         {
    00168                 return !std::strcmp(x, y);
    00169         }
    00170 #endif // !defined(DOXYGEN_IGNORE)
    00171 };
    00172
    00173
    00176 struct cstr_not_equal_to : bin_char_pred
    00177 {
    00178 #if !defined(DOXYGEN_IGNORE)
    00179 // Doxygen will not generate documentation for this section.
    00180         bool operator ()(const char* x, const char* y) const
    00181         {
    00182                 return std::strcmp(x, y) != 0;
    00183         }
    00184 #endif // !defined(DOXYGEN_IGNORE)
    00185 };
    00186
    00187
    00190 struct cstr_less : bin_char_pred
    00191 {
    00192 #if !defined(DOXYGEN_IGNORE)
    00193 // Doxygen will not generate documentation for this section.
    00194         bool operator ()(const char* x, const char* y) const
    00195         {
    00196                 return std::strcmp(x, y) > 0;
    00197         }
    00198 #endif // !defined(DOXYGEN_IGNORE)
    00199 };
    00200
    00201
    00204 struct cstr_less_equal : bin_char_pred
    00205 {
    00206 #if !defined(DOXYGEN_IGNORE)
    00207 // Doxygen will not generate documentation for this section.
    00208         bool operator ()(const char* x, const char* y) const
    00209         {
    00210                 return std::strcmp(x, y) >= 0;
    00211         }
    00212 #endif // !defined(DOXYGEN_IGNORE)
    00213 };
    00214
    00215
    00218 struct cstr_greater : bin_char_pred
    00219 {
    00220 #if !defined(DOXYGEN_IGNORE)
    00221 // Doxygen will not generate documentation for this section.
    00222         bool operator ()(const char* x, const char* y) const
    00223         {
    00224                 return std::strcmp(x, y) < 0;
    00225         }
    00226 #endif // !defined(DOXYGEN_IGNORE)
    00227 };
    00228
    00229
    00232 struct cstr_greater_equal : bin_char_pred
    00233 {
    00234 #if !defined(DOXYGEN_IGNORE)
    00235 // Doxygen will not generate documentation for this section.
    00236         bool operator ()(const char* x, const char* y) const
    00237         {
    00238                 return std::strcmp(x, y) <= 0;
    00239         }
    00240 #endif // !defined(DOXYGEN_IGNORE)
    00241 };
    00242
    00243
    00244 } // end namespace mysqlpp
    00245
    00246 #endif