Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members File Members

# vallist.h

Go to the documentation of this file.

    00001
    00002
    00003
    00004 /***********************************************************************
    00005  Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
    00006  MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
    00007  Others may also hold copyrights on code in this file.  See the CREDITS
    00008  file in the top directory of the distribution for details.
    00009
    00010  This file is part of MySQL++.
    00011
    00012  MySQL++ is free software; you can redistribute it and/or modify it
    00013  under the terms of the GNU Lesser General Public License as published
    00014  by the Free Software Foundation; either version 2.1 of the License, or
    00015  (at your option) any later version.
    00016
    00017  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
    00018  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00019  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00020  License for more details.
    00021
    00022  You should have received a copy of the GNU Lesser General Public
    00023  License along with MySQL++; if not, write to the Free Software
    00024  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00025  USA
    00026 ***********************************************************************/
    00027
    00028 #ifndef 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* delem;
    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         delem(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* delem;
    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         delem(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* delem;
    00194
    00197         Manip manip;
    00198
    00206         value_list_ba(const Seq& s, const char* d, Manip m) :
    00207         list(&s),
    00208         delem(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* delem;
    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         delem(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.delem;
    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.delem;
    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.delem;
    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.delem;
    00368                 }
    00369         }
    00370
    00371         return o;
    00372 }
    00373
    00374
    00375 #if !defined(DOXYGEN_IGNORE)
    00376 // Doxygen will not generate documentation for this section.
    00377
    00378 template <class Iter>
    00379 class simp_list_b
    00380 {
    00381 public:
    00382         Iter _begin;
    00383         Iter _end;
    00384
    00385 public:
    00386         typedef Iter const_iterator;
    00387
    00388         simp_list_b(Iter b, Iter e) :
    00389         _begin(b),
    00390         _end(e)
    00391         {
    00392         }
    00393
    00394         Iter begin() const { return _begin; }
    00395         Iter end() const { return _end; }
    00396 };
    00397
    00398 #endif // !defined(DOXYGEN_IGNORE)
    00399
    00400
    00410
    00411 void create_vector(int size, std::vector<bool>& v, bool t0,
    00412                 bool t1 = false, bool t2 = false, bool t3 = false,
    00413                 bool t4 = false, bool t5 = false, bool t6 = false,
    00414                 bool t7 = false, bool t8 = false, bool t9 = false,
    00415                 bool ta = false, bool tb = false, bool tc = false);
    00416
    00417
    00429
    00430 template <class Container>
    00431 void create_vector(const Container& c, std::vector<bool>& v,
    00432                 std::string s0, std::string s1, std::string s2,
    00433                 std::string s3, std::string s4, std::string s5,
    00434                 std::string s6, std::string s7, std::string s8,
    00435                 std::string s9, std::string sa, std::string sb,
    00436                 std::string sc);
    00437
    00438
    00439
    00449
    00450 template <class Seq>
    00451 value_list_ba<Seq, do_nothing_type0>
    00452 value_list(const Seq& s, const char* d = ",")
    00453 {
    00454         return value_list_ba<Seq, do_nothing_type0>(s, d, do_nothing);
    00455 }
    00456
    00457
    00463
    00464 template <class Seq, class Manip>
    00465 value_list_ba<Seq, Manip>
    00466 value_list(const Seq& s, const char* d, Manip m)
    00467 {
    00468         return value_list_ba<Seq, Manip>(s, d, m);
    00469 }
    00470
    00471
    00480
    00481 template <class Seq, class Manip>
    00482 inline value_list_b<Seq, Manip>
    00483 value_list(const Seq& s, const char* d, Manip m,
    00484                 const std::vector<bool>& vb)
    00485 {
    00486         return value_list_b<Seq, Manip>(s, vb, d, m);
    00487 }
    00488
    00489
    00495
    00496 template <class Seq, class Manip>
    00497 value_list_b<Seq, Manip>
    00498 value_list(const Seq& s, const char* d, Manip m, bool t0,
    00499                 bool t1 = false, bool t2 = false, bool t3 = false,
    00500                 bool t4 = false, bool t5 = false, bool t6 = false,
    00501                 bool t7 = false, bool t8 = false, bool t9 = false,
    00502                 bool ta = false, bool tb = false, bool tc = false)
    00503 {
    00504         std::vector<bool> vb;
    00505         create_vector(s.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9,
    00506                                   ta, tb, tc);
    00507         return value_list_b<Seq, Manip>(s, vb, d, m);
    00508 }
    00509
    00516
    00517 template <class Seq>
    00518 value_list_b<Seq, do_nothing_type0>
    00519 value_list(const Seq& s, const char* d, bool t0,
    00520                 bool t1 = false, bool t2 = false, bool t3 = false,
    00521                 bool t4 = false, bool t5 = false, bool t6 = false,
    00522                 bool t7 = false, bool t8 = false, bool t9 = false,
    00523                 bool ta = false, bool tb = false, bool tc = false)
    00524 {
    00525         std::vector<bool> vb;
    00526         create_vector(s.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9,
    00527                                   ta, tb, tc);
    00528         return value_list_b<Seq, do_nothing_type0>(s, vb, d, do_nothing);
    00529 }
    00530
    00531
    00540
    00541 template <class Seq>
    00542 value_list_b<Seq, do_nothing_type0>
    00543 value_list(const Seq& s, bool t0,
    00544                 bool t1 = false, bool t2 = false, bool t3 = false,
    00545                 bool t4 = false, bool t5 = false, bool t6 = false,
    00546                 bool t7 = false, bool t8 = false, bool t9 = false,
    00547                 bool ta = false, bool tb = false, bool tc = false)
    00548 {
    00549         std::vector<bool> vb;
    00550         create_vector(s.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9,
    00551                                   ta, tb, tc);
    00552         return value_list_b<Seq, do_nothing_type0>(s, vb, ",", do_nothing);
    00553 }
    00554
    00555
    00576
    00577 template <class Seq1, class Seq2>
    00578 equal_list_ba<Seq1, Seq2, do_nothing_type0>
    00579 equal_list(const Seq1& s1, const Seq2& s2, const char *d = ",",
    00580                 const char *e = " = ")
    00581 {
    00582         return equal_list_ba<Seq1, Seq2, do_nothing_type0>(s1, s2, d,
    00583                         e, do_nothing);
    00584 }
    00585
    00586
    00592
    00593 template <class Seq1, class Seq2, class Manip>
    00594 equal_list_ba<Seq1, Seq2, Manip>
    00595 equal_list(const Seq1& s1, const Seq2& s2, const char* d,
    00596                 const char* e, Manip m)
    00597 {
    00598         return equal_list_ba<Seq1, Seq2, Manip>(s1, s2, d, e, m);
    00599 }
    00600
    00601
    00609
    00610 template <class Seq1, class Seq2, class Manip>
    00611 equal_list_b<Seq1, Seq2, Manip>
    00612 equal_list(const Seq1& s1, const Seq2& s2, const char* d,
    00613                 const char *e, Manip m, const std::vector<bool>& vb)
    00614 {
    00615         return equal_list_b<Seq1, Seq2, Manip>(s1, s2, vb, d, e, m);
    00616 }
    00617
    00618
    00624
    00625 template <class Seq1, class Seq2, class Manip>
    00626 equal_list_b<Seq1, Seq2, Manip>
    00627 equal_list(const Seq1& s1, const Seq2& s2, const char* d,
    00628                 const char* e, Manip m, bool t0, bool t1 = false,
    00629                 bool t2 = false, bool t3 = false, bool t4 = false,
    00630                 bool t5 = false, bool t6 = false, bool t7 = false,
    00631                 bool t8 = false, bool t9 = false, bool ta = false,
    00632                 bool tb = false, bool tc = false)
    00633 {
    00634         std::vector<bool> vb;
    00635         create_vector(s1.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8,
    00636                                   t9, ta, tb, tc);
    00637         return equal_list_b<Seq1, Seq2, Manip>(s1, s2, vb, d, e, m);
    00638 }
    00639
    00640
    00647
    00648 template <class Seq1, class Seq2>
    00649 equal_list_b<Seq1, Seq2, do_nothing_type0>
    00650 equal_list(const Seq1& s1, const Seq2& s2, const char* d,
    00651                 const char* e, bool t0, bool t1 = false, bool t2 = false,
    00652                 bool t3 = false, bool t4 = false, bool t5 = false,
    00653                 bool t6 = false, bool t7 = false, bool t8 = false,
    00654                 bool t9 = false, bool ta = false, bool tb = false,
    00655                 bool tc = false)
    00656 {
    00657         std::vector<bool> vb;
    00658         create_vector(s1.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8,
    00659                                   t9, ta, tb, tc);
    00660         return equal_list_b<Seq1, Seq2, do_nothing_type0>(s1, s2, vb,
    00661                         d, e, do_nothing);
    00662 }
    00663
    00664
    00670
    00671 template <class Seq1, class Seq2>
    00672 equal_list_b<Seq1, Seq2, do_nothing_type0>
    00673 equal_list(const Seq1& s1, const Seq2& s2, const char* d, bool t0,
    00674                 bool t1 = false, bool t2 = false, bool t3 = false,
    00675                 bool t4 = false, bool t5 = false, bool t6 = false,
    00676                 bool t7 = false, bool t8 = false, bool t9 = false,
    00677                 bool ta = false, bool tb = false, bool tc = false)
    00678 {
    00679         std::vector<bool> vb;
    00680         create_vector(s1.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8,
    00681                                   t9, ta, tb, tc);
    00682         return equal_list_b<Seq1, Seq2, do_nothing_type0>(s1, s2, vb,
    00683                         d, " = ", do_nothing);
    00684 }
    00685
    00686
    00694
    00695 template <class Seq1, class Seq2>
    00696 equal_list_b<Seq1, Seq2, do_nothing_type0>
    00697 equal_list(const Seq1& s1, const Seq2& s2, bool t0, bool t1 = false,
    00698                 bool t2 = false, bool t3 = false, bool t4 = false,
    00699                 bool t5 = false, bool t6 = false, bool t7 = false,
    00700                 bool t8 = false, bool t9 = false, bool ta = false,
    00701                 bool tb = false, bool tc = false)
    00702 {
    00703         std::vector<bool> vb;
    00704         create_vector(s1.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8,
    00705                                   t9, ta, tb, tc);
    00706         return equal_list_b<Seq1, Seq2, do_nothing_type0>(s1, s2, vb,
    00707                         ",", " = ", do_nothing);
    00708 }
    00709
    00710 } // end namespace mysqlpp
    00711
    00712 #endif