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 #if !defined(MYSQLPP_VALLIST_H)
00029 #define MYSQLPP_VALLIST_H
00030
00031 #include "manip.h"
00032
00033 #include <string>
00034 #include <vector>
00035
00036 namespace mysqlpp {
00037
00038
00058
00059 template <class Seq1, class Seq2, class Manip>
00060 struct equal_list_ba
00061 {
00064 const Seq1* list1;
00065
00068 const Seq2* list2;
00069
00071 const char* delim;
00072
00075 const char* equl;
00076
00079 Manip manip;
00080
00091 equal_list_ba(const Seq1& s1, const Seq2& s2, const char* d,
00092 const char* e, Manip m) :
00093 list1(&s1),
00094 list2(&s2),
00095 delim(d),
00096 equl(e),
00097 manip(m)
00098 {
00099 }
00100 };
00101
00102
00113
00114 template <class Seq1, class Seq2, class Manip>
00115 struct equal_list_b
00116 {
00119 const Seq1* list1;
00120
00123 const Seq2* list2;
00124
00127 const std::vector<bool> fields;
00128
00130 const char* delim;
00131
00134 const char* equl;
00135
00138 Manip manip;
00139
00152 equal_list_b(const Seq1& s1, const Seq2& s2,
00153 const std::vector<bool>& f, const char* d,
00154 const char* e, Manip m) :
00155 list1(&s1),
00156 list2(&s2),
00157 fields(f),
00158 delim(d),
00159 equl(e),
00160 manip(m)
00161 {
00162 }
00163 };
00164
00165
00184
00185 template <class Seq, class Manip>
00186 struct value_list_ba
00187 {
00189 const Seq* list;
00190
00193 const char* delim;
00194
00197 Manip manip;
00198
00206 value_list_ba(const Seq& s, const char* d, Manip m) :
00207 list(&s),
00208 delim(d),
00209 manip(m)
00210 {
00211 }
00212 };
00213
00214
00224
00225 template <class Seq, class Manip>
00226 struct value_list_b
00227 {
00229 const Seq* list;
00230
00233 const std::vector<bool> fields;
00234
00237 const char* delim;
00238
00241 Manip manip;
00242
00252 value_list_b(const Seq& s, const std::vector<bool>& f,
00253 const char* d, Manip m) :
00254 list(&s),
00255 fields(f),
00256 delim(d),
00257 manip(m)
00258 {
00259 }
00260 };
00261
00262
00271
00272 template <class Seq1, class Seq2, class Manip>
00273 std::ostream& operator <<(std::ostream& o,
00274 const equal_list_ba<Seq1, Seq2, Manip>& el)
00275 {
00276 typename Seq1::const_iterator i = el.list1->begin();
00277 typename Seq2::const_iterator j = el.list2->begin();
00278
00279 while (1) {
00280 o << *i << el.equl << el.manip << *j;
00281 if ((++i == el.list1->end()) || (++j == el.list2->end())) {
00282 break;
00283 }
00284 o << el.delim;
00285 }
00286
00287 return o;
00288 }
00289
00290
00295
00296 template <class Seq1, class Seq2, class Manip>
00297 std::ostream& operator <<(std::ostream& o,
00298 const equal_list_b <Seq1, Seq2, Manip>& el)
00299 {
00300 typename Seq1::const_iterator i = el.list1->begin();
00301 typename Seq2::const_iterator j = el.list2->begin();
00302
00303 int k = 0;
00304 while (1) {
00305 if (el.fields[k++]) {
00306 o << *i << el.equl << el.manip << *j;
00307 }
00308 if ((++i == el.list1->end()) || (++j == el.list2->end())) {
00309 break;
00310 }
00311 if (el.fields[k]) {
00312 o << el.delim;
00313 }
00314 }
00315
00316 return o;
00317 }
00318
00319
00328
00329 template <class Seq, class Manip>
00330 std::ostream& operator <<(std::ostream& o,
00331 const value_list_ba<Seq, Manip>& cl)
00332 {
00333 typename Seq::const_iterator i = cl.list->begin();
00334
00335 while (1) {
00336 o << cl.manip << *i;
00337 if (++i == cl.list->end()) {
00338 break;
00339 }
00340 o << cl.delim;
00341 }
00342
00343 return o;
00344 }
00345
00346
00351
00352 template <class Seq, class Manip>
00353 std::ostream& operator <<(std::ostream& o,
00354 const value_list_b<Seq, Manip>& cl)
00355 {
00356 typename Seq::const_iterator i = cl.list->begin();
00357
00358 int k = 0;
00359 while (1) {
00360 if (cl.fields[k++]) {
00361 o << cl.manip << *i;
00362 }
00363 if (++i == cl.list->end()) {
00364 break;
00365 }
00366 if (cl.fields[k]) {
00367 o << cl.delim;
00368 }
00369 }
00370
00371 return o;
00372 }
00373
00374
00384
00385 void create_vector(size_t size, std::vector<bool>& v, bool t0,
00386 bool t1 = false, bool t2 = false, bool t3 = false,
00387 bool t4 = false, bool t5 = false, bool t6 = false,
00388 bool t7 = false, bool t8 = false, bool t9 = false,
00389 bool ta = false, bool tb = false, bool tc = false);
00390
00391
00403
00404 template <class Container>
00405 void create_vector(const Container& c, std::vector<bool>& v,
00406 std::string s0, std::string s1, std::string s2,
00407 std::string s3, std::string s4, std::string s5,
00408 std::string s6, std::string s7, std::string s8,
00409 std::string s9, std::string sa, std::string sb,
00410 std::string sc);
00411
00412
00413
00423
00424 template <class Seq>
00425 value_list_ba<Seq, do_nothing_type0>
00426 value_list(const Seq& s, const char* d = ",")
00427 {
00428 return value_list_ba<Seq, do_nothing_type0>(s, d, do_nothing);
00429 }
00430
00431
00437
00438 template <class Seq, class Manip>
00439 value_list_ba<Seq, Manip>
00440 value_list(const Seq& s, const char* d, Manip m)
00441 {
00442 return value_list_ba<Seq, Manip>(s, d, m);
00443 }
00444
00445
00454
00455 template <class Seq, class Manip>
00456 inline value_list_b<Seq, Manip>
00457 value_list(const Seq& s, const char* d, Manip m,
00458 const std::vector<bool>& vb)
00459 {
00460 return value_list_b<Seq, Manip>(s, vb, d, m);
00461 }
00462
00463
00469
00470 template <class Seq, class Manip>
00471 value_list_b<Seq, Manip>
00472 value_list(const Seq& s, const char* d, Manip m, bool t0,
00473 bool t1 = false, bool t2 = false, bool t3 = false,
00474 bool t4 = false, bool t5 = false, bool t6 = false,
00475 bool t7 = false, bool t8 = false, bool t9 = false,
00476 bool ta = false, bool tb = false, bool tc = false)
00477 {
00478 std::vector<bool> vb;
00479 create_vector(s.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9,
00480 ta, tb, tc);
00481 return value_list_b<Seq, Manip>(s, vb, d, m);
00482 }
00483
00490
00491 template <class Seq>
00492 value_list_b<Seq, do_nothing_type0>
00493 value_list(const Seq& s, const char* d, bool t0,
00494 bool t1 = false, bool t2 = false, bool t3 = false,
00495 bool t4 = false, bool t5 = false, bool t6 = false,
00496 bool t7 = false, bool t8 = false, bool t9 = false,
00497 bool ta = false, bool tb = false, bool tc = false)
00498 {
00499 std::vector<bool> vb;
00500 create_vector(s.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9,
00501 ta, tb, tc);
00502 return value_list_b<Seq, do_nothing_type0>(s, vb, d, do_nothing);
00503 }
00504
00505
00514
00515 template <class Seq>
00516 value_list_b<Seq, do_nothing_type0>
00517 value_list(const Seq& s, bool t0,
00518 bool t1 = false, bool t2 = false, bool t3 = false,
00519 bool t4 = false, bool t5 = false, bool t6 = false,
00520 bool t7 = false, bool t8 = false, bool t9 = false,
00521 bool ta = false, bool tb = false, bool tc = false)
00522 {
00523 std::vector<bool> vb;
00524 create_vector(s.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9,
00525 ta, tb, tc);
00526 return value_list_b<Seq, do_nothing_type0>(s, vb, ",", do_nothing);
00527 }
00528
00529
00550
00551 template <class Seq1, class Seq2>
00552 equal_list_ba<Seq1, Seq2, do_nothing_type0>
00553 equal_list(const Seq1& s1, const Seq2& s2, const char *d = ",",
00554 const char *e = " = ")
00555 {
00556 return equal_list_ba<Seq1, Seq2, do_nothing_type0>(s1, s2, d,
00557 e, do_nothing);
00558 }
00559
00560
00566
00567 template <class Seq1, class Seq2, class Manip>
00568 equal_list_ba<Seq1, Seq2, Manip>
00569 equal_list(const Seq1& s1, const Seq2& s2, const char* d,
00570 const char* e, Manip m)
00571 {
00572 return equal_list_ba<Seq1, Seq2, Manip>(s1, s2, d, e, m);
00573 }
00574
00575
00583
00584 template <class Seq1, class Seq2, class Manip>
00585 equal_list_b<Seq1, Seq2, Manip>
00586 equal_list(const Seq1& s1, const Seq2& s2, const char* d,
00587 const char *e, Manip m, const std::vector<bool>& vb)
00588 {
00589 return equal_list_b<Seq1, Seq2, Manip>(s1, s2, vb, d, e, m);
00590 }
00591
00592
00598
00599 template <class Seq1, class Seq2, class Manip>
00600 equal_list_b<Seq1, Seq2, Manip>
00601 equal_list(const Seq1& s1, const Seq2& s2, const char* d,
00602 const char* e, Manip m, bool t0, bool t1 = false,
00603 bool t2 = false, bool t3 = false, bool t4 = false,
00604 bool t5 = false, bool t6 = false, bool t7 = false,
00605 bool t8 = false, bool t9 = false, bool ta = false,
00606 bool tb = false, bool tc = false)
00607 {
00608 std::vector<bool> vb;
00609 create_vector(s1.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8,
00610 t9, ta, tb, tc);
00611 return equal_list_b<Seq1, Seq2, Manip>(s1, s2, vb, d, e, m);
00612 }
00613
00614
00621
00622 template <class Seq1, class Seq2>
00623 equal_list_b<Seq1, Seq2, do_nothing_type0>
00624 equal_list(const Seq1& s1, const Seq2& s2, const char* d,
00625 const char* e, bool t0, bool t1 = false, bool t2 = false,
00626 bool t3 = false, bool t4 = false, bool t5 = false,
00627 bool t6 = false, bool t7 = false, bool t8 = false,
00628 bool t9 = false, bool ta = false, bool tb = false,
00629 bool tc = false)
00630 {
00631 std::vector<bool> vb;
00632 create_vector(s1.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8,
00633 t9, ta, tb, tc);
00634 return equal_list_b<Seq1, Seq2, do_nothing_type0>(s1, s2, vb,
00635 d, e, do_nothing);
00636 }
00637
00638
00644
00645 template <class Seq1, class Seq2>
00646 equal_list_b<Seq1, Seq2, do_nothing_type0>
00647 equal_list(const Seq1& s1, const Seq2& s2, const char* d, bool t0,
00648 bool t1 = false, bool t2 = false, bool t3 = false,
00649 bool t4 = false, bool t5 = false, bool t6 = false,
00650 bool t7 = false, bool t8 = false, bool t9 = false,
00651 bool ta = false, bool tb = false, bool tc = false)
00652 {
00653 std::vector<bool> vb;
00654 create_vector(s1.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8,
00655 t9, ta, tb, tc);
00656 return equal_list_b<Seq1, Seq2, do_nothing_type0>(s1, s2, vb,
00657 d, " = ", do_nothing);
00658 }
00659
00660
00668
00669 template <class Seq1, class Seq2>
00670 equal_list_b<Seq1, Seq2, do_nothing_type0>
00671 equal_list(const Seq1& s1, const Seq2& s2, bool t0, bool t1 = false,
00672 bool t2 = false, bool t3 = false, bool t4 = false,
00673 bool t5 = false, bool t6 = false, bool t7 = false,
00674 bool t8 = false, bool t9 = false, bool ta = false,
00675 bool tb = false, bool tc = false)
00676 {
00677 std::vector<bool> vb;
00678 create_vector(s1.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8,
00679 t9, ta, tb, tc);
00680 return equal_list_b<Seq1, Seq2, do_nothing_type0>(s1, s2, vb,
00681 ",", " = ", do_nothing);
00682 }
00683
00684 }
00685
00686 #endif // !defined(MYSQLPP_VALLIST_H)