00001 #ifndef MYSQLPP_VALLIST_H
00002 #define MYSQLPP_VALLIST_H
00003
00006
00007 #include "manip.h"
00008
00009 #include <string>
00010 #include <vector>
00011
00012 namespace mysqlpp {
00013
00015 template <class Seq, class Manip>
00016 struct value_list_b {
00017 const Seq *list;
00018 const std::vector<bool> fields;
00019 const char *delem;
00020 Manip manip;
00021 value_list_b(const Seq &s, const std::vector<bool> &f, const char *d, Manip m)
00022 : list(&s), fields(f), delem(d), manip(m) {}
00023 };
00024
00026 template <class Seq1, class Seq2, class Manip>
00027 struct equal_list_b {
00028 const Seq1 *list1;
00029 const Seq2 *list2;
00030 const std::vector<bool> fields;
00031 const char *delem;
00032 const char *equl;
00033 Manip manip;
00034 equal_list_b(const Seq1 &s1, const Seq2 &s2, const std::vector<bool> &f,
00035 const char *d, const char *e, Manip m)
00036 : list1(&s1), list2(&s2), fields(f), delem(d), equl(e), manip(m) {}
00037 };
00038
00040
00041 template <class Seq, class Manip>
00042 struct value_list_ba {
00043 const Seq *list;
00044 const char *delem;
00045 Manip manip;
00046 value_list_ba(const Seq &s, const char* d, Manip m)
00047 : list(&s), delem(d), manip(m) {}
00048 };
00049
00051
00052 template <class Seq1, class Seq2, class Manip>
00053 struct equal_list_ba {
00054 const Seq1 *list1;
00055 const Seq2 *list2;
00056 const char *delem;
00057 const char *equl;
00058 Manip manip;
00059 equal_list_ba(const Seq1 &s1, const Seq2 &s2, const char *d, const char *e,
00060 Manip m)
00061 : list1(&s1), list2(&s2), delem(d), equl(e), manip(m) {}
00062 };
00063
00064
00065
00066 template <class Seq, class Manip>
00067 std::ostream& operator << (std::ostream &o, const value_list_b<Seq, Manip> &cl) {
00068 typename Seq::const_iterator i = cl.list->begin();
00069 register int k = 0;
00070 for (;;) {
00071 if (cl.fields[k])
00072 o << cl.manip << *i;
00073 k++;
00074 if (++i == cl.list->end()) break;
00075 if (cl.fields[k])
00076 o << cl.delem;
00077 }
00078 return o;
00079 }
00080
00081 template <class Seq1, class Seq2, class Manip>
00082 std::ostream& operator << (std::ostream &o, const equal_list_b<Seq1, Seq2, Manip> &el) {
00083 typename Seq1::const_iterator i = el.list1->begin();
00084 typename Seq2::const_iterator j = el.list2->begin();
00085 register int k = 0;
00086 for (;;) {
00087 if (el.fields[k])
00088 o << *i << el.equl << el.manip << *j;
00089 k++;
00090 j++;
00091 if (++i == el.list1->end()) break;
00092 if (el.fields[k])
00093 o << el.delem;
00094 }
00095 return o;
00096 }
00097
00098 template <class Seq, class Manip>
00099 std::ostream& operator << (std::ostream &o, const value_list_ba<Seq, Manip> &cl) {
00100 typename Seq::const_iterator i = cl.list->begin();
00101 for (;;) {
00102 o << cl.manip << *i;
00103 if (++i == cl.list->end()) break;
00104 o << cl.delem;
00105 }
00106 return o;
00107 }
00108
00109 template <class Seq1, class Seq2, class Manip>
00110 std::ostream& operator << (std::ostream &o, const equal_list_ba<Seq1, Seq2, Manip> &el) {
00111 typename Seq1::const_iterator i = el.list1->begin();
00112 typename Seq2::const_iterator j = el.list2->begin();
00113 for (;;) {
00114 o << *i << el.equl << el.manip << *j;
00115 j++;
00116 if (++i == el.list1->end()) break;
00117 o << el.delem;
00118 }
00119 return o;
00120 }
00121
00123 template <class Iter>
00124 class simp_list_b {
00125 public:
00126 Iter _begin;
00127 Iter _end;
00128 public:
00129 typedef Iter const_iterator;
00130 simp_list_b(Iter b, Iter e) : _begin(b), _end(e) {}
00131 Iter begin() const {return _begin;}
00132 Iter end() const {return _end;}
00133 };
00134
00135
00136
00137
00138
00139 void create_vector(int size, std::vector<bool>& v, bool t0,
00140 bool t1=false, bool t2=false, bool t3=false, bool t4=false,
00141 bool t5=false, bool t6=false, bool t7=false, bool t8=false,
00142 bool t9=false, bool ta=false, bool tb=false, bool tc=false);
00143
00144 template <class Container>
00145 void create_vector(const Container&c, std::vector<bool>&v, std::string s0, std::string s1,
00146 std::string s2, std::string s3, std::string s4, std::string s5, std::string s6,
00147 std::string s7, std::string s8, std::string s9, std::string sa, std::string sb,
00148 std::string sc);
00149
00150
00151
00152
00153
00154 template <class Seq>
00155 inline
00156 value_list_ba<Seq,do_nothing_type0>
00157 value_list(const Seq &s, const char *d = ",") {
00158 return value_list_ba<Seq ,do_nothing_type0> (s, d, do_nothing);
00159 }
00160
00161 template <class Seq, class Manip>
00162 inline
00163 value_list_ba<Seq,Manip>
00164 value_list(const Seq &s, const char *d, Manip m) {
00165 return value_list_ba<Seq,Manip> (s, d, m);
00166 }
00167
00168 template <class Seq, class Manip>
00169 inline
00170 value_list_b<Seq,Manip>
00171 value_list(const Seq &s, const char *d, Manip m, const std::vector<bool> &vb)
00172 {
00173 return value_list_b<Seq, Manip>(s, vb, d, m);
00174 }
00175
00176 template <class Seq, class Manip>
00177 value_list_b<Seq,Manip>
00178 value_list(const Seq &s, const char *d, Manip m, bool t0,
00179 bool t1=false, bool t2=false, bool t3=false, bool t4=false,
00180 bool t5=false, bool t6=false, bool t7=false, bool t8=false,
00181 bool t9=false, bool ta=false, bool tb=false, bool tc=false)
00182 {
00183 std::vector<bool> vb;
00184 create_vector(s.size(), vb, t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,ta,tb,tc);
00185 return value_list_b<Seq, Manip>(s, vb, d, m);
00186 }
00187
00188 template <class Seq>
00189 value_list_b<Seq,do_nothing_type0>
00190 value_list(const Seq &s, const char *d, bool t0,
00191 bool t1=false, bool t2=false, bool t3=false, bool t4=false,
00192 bool t5=false, bool t6=false, bool t7=false, bool t8=false,
00193 bool t9=false, bool ta=false, bool tb=false, bool tc=false)
00194 {
00195 std::vector<bool> vb;
00196 create_vector(s.size(), vb, t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,ta,tb,tc);
00197 return value_list_b<Seq, do_nothing_type0> (s, vb, d, do_nothing);
00198 }
00199
00200 template <class Seq>
00201 value_list_b<Seq,do_nothing_type0>
00202 value_list(const Seq &s, bool t0,
00203 bool t1=false, bool t2=false, bool t3=false, bool t4=false,
00204 bool t5=false, bool t6=false, bool t7=false, bool t8=false,
00205 bool t9=false, bool ta=false, bool tb=false, bool tc=false)
00206 {
00207 std::vector<bool> vb;
00208 create_vector(s.size(), vb, t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,ta,tb,tc);
00209 return value_list_b<Seq, do_nothing_type0> (s, vb, ",",do_nothing);
00210 }
00211
00212
00213
00214
00215
00216 template <class Seq1, class Seq2>
00217 inline
00218 equal_list_ba<Seq1,Seq2,do_nothing_type0>
00219 equal_list(const Seq1 &s1, const Seq2 &s2, const char *d = ",",
00220 const char *e = " = ") {
00221 return equal_list_ba<Seq1,Seq2,do_nothing_type0> (s1, s2, d, e, do_nothing);
00222 }
00223
00224 template <class Seq1, class Seq2, class Manip>
00225 inline
00226 equal_list_ba<Seq1,Seq2,Manip>
00227 equal_list(const Seq1 &s1, const Seq2 &s2,
00228 const char *d, const char *e, Manip m) {
00229 return equal_list_ba<Seq1,Seq2,Manip> (s1, s2, d, e, m);
00230 }
00231
00232 template <class Seq1, class Seq2, class Manip>
00233 inline
00234 equal_list_b<Seq1, Seq2, Manip>
00235 equal_list(const Seq1 &s1, const Seq2 &s2, const char *d, const char *e,
00236 Manip m, const std::vector<bool> &vb)
00237 {
00238 return equal_list_b<Seq1,Seq2,Manip>(s1, s2, vb, d, e, m);
00239 }
00240
00241
00242 template <class Seq1, class Seq2, class Manip>
00243 equal_list_b<Seq1, Seq2, Manip>
00244 equal_list(const Seq1 &s1, const Seq2 &s2, const char *d, const char *e,
00245 Manip m, bool t0,
00246 bool t1=false, bool t2=false, bool t3=false, bool t4=false,
00247 bool t5=false, bool t6=false, bool t7=false, bool t8=false,
00248 bool t9=false, bool ta=false, bool tb=false, bool tc=false)
00249 {
00250 std::vector<bool> vb;
00251 create_vector(s1.size(), vb, t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,ta,tb,tc);
00252 return equal_list_b<Seq1,Seq2,Manip>(s1, s2, vb, d, e, m);
00253 }
00254
00255
00256 template <class Seq1, class Seq2>
00257 equal_list_b<Seq1, Seq2, do_nothing_type0>
00258 equal_list(const Seq1 &s1, const Seq2 &s2, const char *d, const char *e,
00259 bool t0,
00260 bool t1=false, bool t2=false, bool t3=false, bool t4=false,
00261 bool t5=false, bool t6=false, bool t7=false, bool t8=false,
00262 bool t9=false, bool ta=false, bool tb=false, bool tc=false)
00263 {
00264 std::vector<bool> vb;
00265 create_vector(s1.size(), vb, t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,ta,tb,tc);
00266 return equal_list_b<Seq1,Seq2,do_nothing_type0>
00267 (s1, s2, vb, d, e, do_nothing);
00268 }
00269
00270
00271 template <class Seq1, class Seq2>
00272 equal_list_b<Seq1,Seq2,do_nothing_type0>
00273 equal_list(const Seq1 &s1, const Seq2 &s2, const char *d, bool t0,
00274 bool t1=false, bool t2=false, bool t3=false, bool t4=false,
00275 bool t5=false, bool t6=false, bool t7=false, bool t8=false,
00276 bool t9=false, bool ta=false, bool tb=false, bool tc=false)
00277 {
00278 std::vector<bool> vb;
00279 create_vector(s1.size(), vb, t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,ta,tb,tc);
00280 return equal_list_b<Seq1,Seq2,do_nothing_type0>
00281 (s1, s2, vb, d, " = ", do_nothing);
00282 }
00283
00284
00285 template <class Seq1, class Seq2>
00286 equal_list_b<Seq1,Seq2,do_nothing_type0>
00287 equal_list(const Seq1 &s1, const Seq2 &s2, bool t0,
00288 bool t1=false, bool t2=false, bool t3=false, bool t4=false,
00289 bool t5=false, bool t6=false, bool t7=false, bool t8=false,
00290 bool t9=false, bool ta=false, bool tb=false, bool tc=false)
00291 {
00292 std::vector<bool> vb;
00293 create_vector(s1.size(), vb, t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,ta,tb,tc);
00294 return equal_list_b<Seq1,Seq2,do_nothing_type0>
00295 (s1, s2, vb,"," ," = " ,do_nothing);
00296 }
00297
00298 }
00299
00300 #endif
00301