00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
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
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
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
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
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
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 }
00245
00246 #endif