MySQL++ Reference Manual

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

vallist.h
Go to the documentation of this file.
1
4 /***********************************************************************
5 Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
6 MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
7 Others may also hold copyrights on code in this file. See the CREDITS
8 file in the top directory of the distribution for details.
9
10 This file is part of MySQL++.
11
12 MySQL++ is free software; you can redistribute it and/or modify it
13 under the terms of the GNU Lesser General Public License as published
14 by the Free Software Foundation; either version 2.1 of the License, or
15 (at your option) any later version.
16
17 MySQL++ is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20 License for more details.
21
22 You should have received a copy of the GNU Lesser General Public
23 License along with MySQL++; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25 USA
26 ***********************************************************************/
27
28 #if !defined(MYSQLPP_VALLIST_H)
29 #define MYSQLPP_VALLIST_H
30
31 #include "manip.h"
32
33 #include <string>
34 #include <vector>
35
36 namespace mysqlpp {
37
38
58
59 template <class Seq1, class Seq2, class Manip>
60 struct equal_list_ba
61 {
64 const Seq1* list1;
65
68 const Seq2* list2;
69
71 const char* delim;
72
75 const char* equl;
76
79 Manip manip;
80
91 equal_list_ba(const Seq1& s1, const Seq2& s2, const char* d,
92 const char* e, Manip m) :
93 list1(&s1),
94 list2(&s2),
95 delim(d),
96 equl(e),
97 manip(m)
98 {
99 }
100 };
101
102
113
114 template <class Seq1, class Seq2, class Manip>
115 struct equal_list_b
116 {
119 const Seq1* list1;
120
123 const Seq2* list2;
124
127 const std::vector<bool> fields;
128
130 const char* delim;
131
134 const char* equl;
135
138 Manip manip;
139
152 equal_list_b(const Seq1& s1, const Seq2& s2,
153 const std::vector<bool>& f, const char* d,
154 const char* e, Manip m) :
155 list1(&s1),
156 list2(&s2),
157 fields(f),
158 delim(d),
159 equl(e),
160 manip(m)
161 {
162 }
163 };
164
165
184
185 template <class Seq, class Manip>
186 struct value_list_ba
187 {
189 const Seq* list;
190
193 const char* delim;
194
197 Manip manip;
198
206 value_list_ba(const Seq& s, const char* d, Manip m) :
207 list(&s),
208 delim(d),
209 manip(m)
210 {
211 }
212 };
213
214
224
225 template <class Seq, class Manip>
226 struct value_list_b
227 {
229 const Seq* list;
230
233 const std::vector<bool> fields;
234
237 const char* delim;
238
241 Manip manip;
242
252 value_list_b(const Seq& s, const std::vector<bool>& f,
253 const char* d, Manip m) :
254 list(&s),
255 fields(f),
256 delim(d),
257 manip(m)
258 {
259 }
260 };
261
262
271
272 template <class Seq1, class Seq2, class Manip>
273 std::ostream& operator <<(std::ostream& o,
274 const equal_list_ba<Seq1, Seq2, Manip>& el)
275 {
276 typename Seq1::const_iterator i = el.list1->begin();
277 typename Seq2::const_iterator j = el.list2->begin();
278
279 while (1) {
280 o << *i << el.equl << el.manip << *j;
281 if ((++i == el.list1->end()) || (++j == el.list2->end())) {
282 break;
283 }
284 o << el.delim;
285 }
286
287 return o;
288 }
289
290
295
296 template <class Seq1, class Seq2, class Manip>
297 std::ostream& operator <<(std::ostream& o,
298 const equal_list_b <Seq1, Seq2, Manip>& el)
299 {
300 typename Seq1::const_iterator i = el.list1->begin();
301 typename Seq2::const_iterator j = el.list2->begin();
302
303 int k = 0;
304 while (1) {
305 if (el.fields[k++]) {
306 o << *i << el.equl << el.manip << *j;
307 }
308 if ((++i == el.list1->end()) || (++j == el.list2->end())) {
309 break;
310 }
311 if (el.fields[k]) {
312 o << el.delim;
313 }
314 }
315
316 return o;
317 }
318
319
328
329 template <class Seq, class Manip>
330 std::ostream& operator <<(std::ostream& o,
331 const value_list_ba<Seq, Manip>& cl)
332 {
333 typename Seq::const_iterator i = cl.list->begin();
334
335 while (1) {
336 o << cl.manip << *i;
337 if (++i == cl.list->end()) {
338 break;
339 }
340 o << cl.delim;
341 }
342
343 return o;
344 }
345
346
351
352 template <class Seq, class Manip>
353 std::ostream& operator <<(std::ostream& o,
354 const value_list_b<Seq, Manip>& cl)
355 {
356 typename Seq::const_iterator i = cl.list->begin();
357
358 int k = 0;
359 while (1) {
360 if (cl.fields[k++]) {
361 o << cl.manip << *i;
362 }
363 if (++i == cl.list->end()) {
364 break;
365 }
366 if (cl.fields[k]) {
367 o << cl.delim;
368 }
369 }
370
371 return o;
372 }
373
374
384
385 void create_vector(size_t size, std::vector<bool>& v, bool t0,
386 bool t1 = false, bool t2 = false, bool t3 = false,
387 bool t4 = false, bool t5 = false, bool t6 = false,
388 bool t7 = false, bool t8 = false, bool t9 = false,
389 bool ta = false, bool tb = false, bool tc = false);
390
391
403
404 template <class Container>
405 void create_vector(const Container& c, std::vector<bool>& v,
406 std::string s0, std::string s1, std::string s2,
407 std::string s3, std::string s4, std::string s5,
408 std::string s6, std::string s7, std::string s8,
409 std::string s9, std::string sa, std::string sb,
410 std::string sc);
411
412
413
423
424 template <class Seq>
425 value_list_ba<Seq, do_nothing_type0>
426 value_list(const Seq& s, const char* d = ",")
427 {
428 return value_list_ba<Seq, do_nothing_type0>(s, d, do_nothing);
429 }
430
431
437
438 template <class Seq, class Manip>
439 value_list_ba<Seq, Manip>
440 value_list(const Seq& s, const char* d, Manip m)
441 {
442 return value_list_ba<Seq, Manip>(s, d, m);
443 }
444
445
454
455 template <class Seq, class Manip>
456 inline value_list_b<Seq, Manip>
457 value_list(const Seq& s, const char* d, Manip m,
458 const std::vector<bool>& vb)
459 {
460 return value_list_b<Seq, Manip>(s, vb, d, m);
461 }
462
463
469
470 template <class Seq, class Manip>
471 value_list_b<Seq, Manip>
472 value_list(const Seq& s, const char* d, Manip m, bool t0,
473 bool t1 = false, bool t2 = false, bool t3 = false,
474 bool t4 = false, bool t5 = false, bool t6 = false,
475 bool t7 = false, bool t8 = false, bool t9 = false,
476 bool ta = false, bool tb = false, bool tc = false)
477 {
478 std::vector<bool> vb;
479 create_vector(s.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9,
480 ta, tb, tc);
481 return value_list_b<Seq, Manip>(s, vb, d, m);
482 }
483
490
491 template <class Seq>
492 value_list_b<Seq, do_nothing_type0>
493 value_list(const Seq& s, const char* d, bool t0,
494 bool t1 = false, bool t2 = false, bool t3 = false,
495 bool t4 = false, bool t5 = false, bool t6 = false,
496 bool t7 = false, bool t8 = false, bool t9 = false,
497 bool ta = false, bool tb = false, bool tc = false)
498 {
499 std::vector<bool> vb;
500 create_vector(s.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9,
501 ta, tb, tc);
502 return value_list_b<Seq, do_nothing_type0>(s, vb, d, do_nothing);
503 }
504
505
514
515 template <class Seq>
516 value_list_b<Seq, do_nothing_type0>
517 value_list(const Seq& s, bool t0,
518 bool t1 = false, bool t2 = false, bool t3 = false,
519 bool t4 = false, bool t5 = false, bool t6 = false,
520 bool t7 = false, bool t8 = false, bool t9 = false,
521 bool ta = false, bool tb = false, bool tc = false)
522 {
523 std::vector<bool> vb;
524 create_vector(s.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9,
525 ta, tb, tc);
526 return value_list_b<Seq, do_nothing_type0>(s, vb, ",", do_nothing);
527 }
528
529
550
551 template <class Seq1, class Seq2>
552 equal_list_ba<Seq1, Seq2, do_nothing_type0>
553 equal_list(const Seq1& s1, const Seq2& s2, const char *d = ",",
554 const char *e = " = ")
555 {
556 return equal_list_ba<Seq1, Seq2, do_nothing_type0>(s1, s2, d,
557 e, do_nothing);
558 }
559
560
566
567 template <class Seq1, class Seq2, class Manip>
568 equal_list_ba<Seq1, Seq2, Manip>
569 equal_list(const Seq1& s1, const Seq2& s2, const char* d,
570 const char* e, Manip m)
571 {
572 return equal_list_ba<Seq1, Seq2, Manip>(s1, s2, d, e, m);
573 }
574
575
583
584 template <class Seq1, class Seq2, class Manip>
585 equal_list_b<Seq1, Seq2, Manip>
586 equal_list(const Seq1& s1, const Seq2& s2, const char* d,
587 const char *e, Manip m, const std::vector<bool>& vb)
588 {
589 return equal_list_b<Seq1, Seq2, Manip>(s1, s2, vb, d, e, m);
590 }
591
592
598
599 template <class Seq1, class Seq2, class Manip>
600 equal_list_b<Seq1, Seq2, Manip>
601 equal_list(const Seq1& s1, const Seq2& s2, const char* d,
602 const char* e, Manip m, bool t0, bool t1 = false,
603 bool t2 = false, bool t3 = false, bool t4 = false,
604 bool t5 = false, bool t6 = false, bool t7 = false,
605 bool t8 = false, bool t9 = false, bool ta = false,
606 bool tb = false, bool tc = false)
607 {
608 std::vector<bool> vb;
609 create_vector(s1.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8,
610 t9, ta, tb, tc);
611 return equal_list_b<Seq1, Seq2, Manip>(s1, s2, vb, d, e, m);
612 }
613
614
621
622 template <class Seq1, class Seq2>
623 equal_list_b<Seq1, Seq2, do_nothing_type0>
624 equal_list(const Seq1& s1, const Seq2& s2, const char* d,
625 const char* e, bool t0, bool t1 = false, bool t2 = false,
626 bool t3 = false, bool t4 = false, bool t5 = false,
627 bool t6 = false, bool t7 = false, bool t8 = false,
628 bool t9 = false, bool ta = false, bool tb = false,
629 bool tc = false)
630 {
631 std::vector<bool> vb;
632 create_vector(s1.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8,
633 t9, ta, tb, tc);
634 return equal_list_b<Seq1, Seq2, do_nothing_type0>(s1, s2, vb,
635 d, e, do_nothing);
636 }
637
638
644
645 template <class Seq1, class Seq2>
646 equal_list_b<Seq1, Seq2, do_nothing_type0>
647 equal_list(const Seq1& s1, const Seq2& s2, const char* d, bool t0,
648 bool t1 = false, bool t2 = false, bool t3 = false,
649 bool t4 = false, bool t5 = false, bool t6 = false,
650 bool t7 = false, bool t8 = false, bool t9 = false,
651 bool ta = false, bool tb = false, bool tc = false)
652 {
653 std::vector<bool> vb;
654 create_vector(s1.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8,
655 t9, ta, tb, tc);
656 return equal_list_b<Seq1, Seq2, do_nothing_type0>(s1, s2, vb,
657 d, " = ", do_nothing);
658 }
659
660
668
669 template <class Seq1, class Seq2>
670 equal_list_b<Seq1, Seq2, do_nothing_type0>
671 equal_list(const Seq1& s1, const Seq2& s2, bool t0, bool t1 = false,
672 bool t2 = false, bool t3 = false, bool t4 = false,
673 bool t5 = false, bool t6 = false, bool t7 = false,
674 bool t8 = false, bool t9 = false, bool ta = false,
675 bool tb = false, bool tc = false)
676 {
677 std::vector<bool> vb;
678 create_vector(s1.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8,
679 t9, ta, tb, tc);
680 return equal_list_b<Seq1, Seq2, do_nothing_type0>(s1, s2, vb,
681 ",", " = ", do_nothing);
682 }
683
684 } // end namespace mysqlpp
685
686 #endif // !defined(MYSQLPP_VALLIST_H)
mysqlpp::equal_list_b::delim
const char * delim
delimiter to use between each pair of elements
Definition: vallist.h:130
mysqlpp::value_list_b::value_list_b
value_list_b(const Seq &s, const std::vector< bool > &f, const char *d, Manip m)
Create object.
Definition: vallist.h:252
mysqlpp::value_list_ba
Holds a list of items, typically used to construct a SQL &quot;value list&quot;.
Definition: vallist.h:186
mysqlpp::value_list_ba::list
const Seq * list
set of objects in the value list
Definition: vallist.h:189
mysqlpp::equal_list_ba::equal_list_ba
equal_list_ba(const Seq1 &s1, const Seq2 &s2, const char *d, const char *e, Manip m)
Create object.
Definition: vallist.h:91
mysqlpp::value_list_b::manip
Manip manip
manipulator to use when inserting the list into a C++ stream
Definition: vallist.h:241
mysqlpp::equal_list_b::list2
const Seq2 * list2
the list of objects on the right-hand side of the equals sign
Definition: vallist.h:123
mysqlpp::equal_list_ba::manip
Manip manip
manipulator to use when inserting the equal_list into a C++ stream
Definition: vallist.h:79
mysqlpp::value_list_b::list
const Seq * list
set of objects in the value list
Definition: vallist.h:229
mysqlpp::equal_list_ba::delim
const char * delim
delimiter to use between each pair of elements
Definition: vallist.h:71
manip.h
Declares the Query stream manipulators and operators.
mysqlpp::equal_list_b::equal_list_b
equal_list_b(const Seq1 &s1, const Seq2 &s2, const std::vector< bool > &f, const char *d, const char *e, Manip m)
Create object.
Definition: vallist.h:152
mysqlpp::equal_list_b::list1
const Seq1 * list1
the list of objects on the left-hand side of the equals sign
Definition: vallist.h:119
mysqlpp::value_list_ba::delim
const char * delim
delimiter to use between each value in the list when inserting it into a C++ stream ...
Definition: vallist.h:193
mysqlpp::value_list_ba::manip
Manip manip
manipulator to use when inserting the list into a C++ stream
Definition: vallist.h:197
mysqlpp::equal_list_ba::list2
const Seq2 * list2
the list of objects on the right-hand side of the equals sign
Definition: vallist.h:68
mysqlpp::value_list_b
Same as value_list_ba, plus the option to have some elements of the list suppressed.
Definition: vallist.h:226
mysqlpp::equal_list_b::fields
const std::vector< bool > fields
for each true item in the list, the pair in that position will be inserted into a C++ stream ...
Definition: vallist.h:127
mysqlpp::value_list_b::fields
const std::vector< bool > fields
delimiter to use between each value in the list when inserting it into a C++ stream ...
Definition: vallist.h:233
mysqlpp::equal_list_ba::equl
const char * equl
&quot;equal&quot; sign to use between each item in each equal pair; doesn&#39;t have to actually be &quot; = &quot; ...
Definition: vallist.h:75
mysqlpp::equal_list_b::manip
Manip manip
manipulator to use when inserting the equal_list into a C++ stream
Definition: vallist.h:138
mysqlpp::equal_list_b
Same as equal_list_ba, plus the option to have some elements of the equals clause suppressed...
Definition: vallist.h:115
mysqlpp::equal_list_ba
Holds two lists of items, typically used to construct a SQL &quot;equals clause&quot;.
Definition: vallist.h:60
mysqlpp::equal_list_ba::list1
const Seq1 * list1
the list of objects on the left-hand side of the equals sign
Definition: vallist.h:64
mysqlpp::equal_list_b::equl
const char * equl
&quot;equal&quot; sign to use between each item in each equal pair; doesn&#39;t have to actually be &quot; = &quot; ...
Definition: vallist.h:134
mysqlpp::value_list_b::delim
const char * delim
delimiter to use between each value in the list when inserting it into a C++ stream ...
Definition: vallist.h:237
mysqlpp::value_list_ba::value_list_ba
value_list_ba(const Seq &s, const char *d, Manip m)
Create object.
Definition: vallist.h:206