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, 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
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
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
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
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
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
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 }
00243
00244 #endif