vallist.h
Go to the documentation of this file.
/***********************************************************************
Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
Others may also hold copyrights on code in this file. See the CREDITS
file in the top directory of the distribution for details.
This file is part of MySQL++.
MySQL++ is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
MySQL++ is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with MySQL++; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
***********************************************************************/
#if !defined(MYSQLPP_VALLIST_H)
#define MYSQLPP_VALLIST_H
#include "manip.h"
#include <string>
#include <vector>
namespace mysqlpp {
template <class Seq1, class Seq2, class Manip>
struct equal_list_ba
{
const Seq1* list1;
const Seq2* list2;
const char* delim;
const char* equl;
Manip manip;
equal_list_ba(const Seq1& s1, const Seq2& s2, const char* d,
const char* e, Manip m) :
list1(&s1),
list2(&s2),
delim(d),
equl(e),
manip(m)
{
}
};
template <class Seq1, class Seq2, class Manip>
struct equal_list_b
{
const Seq1* list1;
const Seq2* list2;
const std::vector<bool> fields;
const char* delim;
const char* equl;
Manip manip;
equal_list_b(const Seq1& s1, const Seq2& s2,
const std::vector<bool>& f, const char* d,
const char* e, Manip m) :
list1(&s1),
list2(&s2),
fields(f),
delim(d),
equl(e),
manip(m)
{
}
};
template <class Seq, class Manip>
struct value_list_ba
{
const Seq* list;
const char* delim;
Manip manip;
value_list_ba(const Seq& s, const char* d, Manip m) :
list(&s),
delim(d),
manip(m)
{
}
};
template <class Seq, class Manip>
struct value_list_b
{
const Seq* list;
const std::vector<bool> fields;
const char* delim;
Manip manip;
value_list_b(const Seq& s, const std::vector<bool>& f,
const char* d, Manip m) :
list(&s),
fields(f),
delim(d),
manip(m)
{
}
};
template <class Seq1, class Seq2, class Manip>
std::ostream& operator <<(std::ostream& o,
const equal_list_ba<Seq1, Seq2, Manip>& el)
{
typename Seq1::const_iterator i = el.list1->begin();
typename Seq2::const_iterator j = el.list2->begin();
while (1) {
o << *i << el.equl << el.manip << *j;
if ((++i == el.list1->end()) || (++j == el.list2->end())) {
break;
}
o << el.delim;
}
return o;
}
template <class Seq1, class Seq2, class Manip>
std::ostream& operator <<(std::ostream& o,
const equal_list_b <Seq1, Seq2, Manip>& el)
{
typename Seq1::const_iterator i = el.list1->begin();
typename Seq2::const_iterator j = el.list2->begin();
int k = 0;
while (1) {
if (el.fields[k++]) {
o << *i << el.equl << el.manip << *j;
}
if ((++i == el.list1->end()) || (++j == el.list2->end())) {
break;
}
if (el.fields[k]) {
o << el.delim;
}
}
return o;
}
template <class Seq, class Manip>
std::ostream& operator <<(std::ostream& o,
const value_list_ba<Seq, Manip>& cl)
{
typename Seq::const_iterator i = cl.list->begin();
while (1) {
o << cl.manip << *i;
if (++i == cl.list->end()) {
break;
}
o << cl.delim;
}
return o;
}
template <class Seq, class Manip>
std::ostream& operator <<(std::ostream& o,
const value_list_b<Seq, Manip>& cl)
{
typename Seq::const_iterator i = cl.list->begin();
int k = 0;
while (1) {
if (cl.fields[k++]) {
o << cl.manip << *i;
}
if (++i == cl.list->end()) {
break;
}
if (cl.fields[k]) {
o << cl.delim;
}
}
return o;
}
void create_vector(size_t size, std::vector<bool>& v, bool t0,
bool t1 = false, bool t2 = false, bool t3 = false,
bool t4 = false, bool t5 = false, bool t6 = false,
bool t7 = false, bool t8 = false, bool t9 = false,
bool ta = false, bool tb = false, bool tc = false);
template <class Container>
void create_vector(const Container& c, std::vector<bool>& v,
std::string s0, std::string s1, std::string s2,
std::string s3, std::string s4, std::string s5,
std::string s6, std::string s7, std::string s8,
std::string s9, std::string sa, std::string sb,
std::string sc);
template <class Seq>
value_list_ba<Seq, do_nothing_type0>
value_list(const Seq& s, const char* d = ",")
{
return value_list_ba<Seq, do_nothing_type0>(s, d, do_nothing);
}
template <class Seq, class Manip>
value_list_ba<Seq, Manip>
value_list(const Seq& s, const char* d, Manip m)
{
return value_list_ba<Seq, Manip>(s, d, m);
}
template <class Seq, class Manip>
inline value_list_b<Seq, Manip>
value_list(const Seq& s, const char* d, Manip m,
const std::vector<bool>& vb)
{
return value_list_b<Seq, Manip>(s, vb, d, m);
}
template <class Seq, class Manip>
value_list_b<Seq, Manip>
value_list(const Seq& s, const char* d, Manip m, bool t0,
bool t1 = false, bool t2 = false, bool t3 = false,
bool t4 = false, bool t5 = false, bool t6 = false,
bool t7 = false, bool t8 = false, bool t9 = false,
bool ta = false, bool tb = false, bool tc = false)
{
std::vector<bool> vb;
create_vector(s.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9,
ta, tb, tc);
return value_list_b<Seq, Manip>(s, vb, d, m);
}
template <class Seq>
value_list_b<Seq, do_nothing_type0>
value_list(const Seq& s, const char* d, bool t0,
bool t1 = false, bool t2 = false, bool t3 = false,
bool t4 = false, bool t5 = false, bool t6 = false,
bool t7 = false, bool t8 = false, bool t9 = false,
bool ta = false, bool tb = false, bool tc = false)
{
std::vector<bool> vb;
create_vector(s.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9,
ta, tb, tc);
return value_list_b<Seq, do_nothing_type0>(s, vb, d, do_nothing);
}
template <class Seq>
value_list_b<Seq, do_nothing_type0>
value_list(const Seq& s, bool t0,
bool t1 = false, bool t2 = false, bool t3 = false,
bool t4 = false, bool t5 = false, bool t6 = false,
bool t7 = false, bool t8 = false, bool t9 = false,
bool ta = false, bool tb = false, bool tc = false)
{
std::vector<bool> vb;
create_vector(s.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9,
ta, tb, tc);
return value_list_b<Seq, do_nothing_type0>(s, vb, ",", do_nothing);
}
template <class Seq1, class Seq2>
equal_list_ba<Seq1, Seq2, do_nothing_type0>
equal_list(const Seq1& s1, const Seq2& s2, const char *d = ",",
const char *e = " = ")
{
return equal_list_ba<Seq1, Seq2, do_nothing_type0>(s1, s2, d,
e, do_nothing);
}
template <class Seq1, class Seq2, class Manip>
equal_list_ba<Seq1, Seq2, Manip>
equal_list(const Seq1& s1, const Seq2& s2, const char* d,
const char* e, Manip m)
{
return equal_list_ba<Seq1, Seq2, Manip>(s1, s2, d, e, m);
}
template <class Seq1, class Seq2, class Manip>
equal_list_b<Seq1, Seq2, Manip>
equal_list(const Seq1& s1, const Seq2& s2, const char* d,
const char *e, Manip m, const std::vector<bool>& vb)
{
return equal_list_b<Seq1, Seq2, Manip>(s1, s2, vb, d, e, m);
}
template <class Seq1, class Seq2, class Manip>
equal_list_b<Seq1, Seq2, Manip>
equal_list(const Seq1& s1, const Seq2& s2, const char* d,
const char* e, Manip m, bool t0, bool t1 = false,
bool t2 = false, bool t3 = false, bool t4 = false,
bool t5 = false, bool t6 = false, bool t7 = false,
bool t8 = false, bool t9 = false, bool ta = false,
bool tb = false, bool tc = false)
{
std::vector<bool> vb;
create_vector(s1.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8,
t9, ta, tb, tc);
return equal_list_b<Seq1, Seq2, Manip>(s1, s2, vb, d, e, m);
}
template <class Seq1, class Seq2>
equal_list_b<Seq1, Seq2, do_nothing_type0>
equal_list(const Seq1& s1, const Seq2& s2, const char* d,
const char* e, bool t0, bool t1 = false, bool t2 = false,
bool t3 = false, bool t4 = false, bool t5 = false,
bool t6 = false, bool t7 = false, bool t8 = false,
bool t9 = false, bool ta = false, bool tb = false,
bool tc = false)
{
std::vector<bool> vb;
create_vector(s1.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8,
t9, ta, tb, tc);
return equal_list_b<Seq1, Seq2, do_nothing_type0>(s1, s2, vb,
d, e, do_nothing);
}
template <class Seq1, class Seq2>
equal_list_b<Seq1, Seq2, do_nothing_type0>
equal_list(const Seq1& s1, const Seq2& s2, const char* d, bool t0,
bool t1 = false, bool t2 = false, bool t3 = false,
bool t4 = false, bool t5 = false, bool t6 = false,
bool t7 = false, bool t8 = false, bool t9 = false,
bool ta = false, bool tb = false, bool tc = false)
{
std::vector<bool> vb;
create_vector(s1.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8,
t9, ta, tb, tc);
return equal_list_b<Seq1, Seq2, do_nothing_type0>(s1, s2, vb,
d, " = ", do_nothing);
}
template <class Seq1, class Seq2>
equal_list_b<Seq1, Seq2, do_nothing_type0>
equal_list(const Seq1& s1, const Seq2& s2, bool t0, bool t1 = false,
bool t2 = false, bool t3 = false, bool t4 = false,
bool t5 = false, bool t6 = false, bool t7 = false,
bool t8 = false, bool t9 = false, bool ta = false,
bool tb = false, bool tc = false)
{
std::vector<bool> vb;
create_vector(s1.size(), vb, t0, t1, t2, t3, t4, t5, t6, t7, t8,
t9, ta, tb, tc);
return equal_list_b<Seq1, Seq2, do_nothing_type0>(s1, s2, vb,
",", " = ", do_nothing);
}
} // end namespace mysqlpp
#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