1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_MESSAGE_IOUTIL_H
21
#define DRIZZLED_MESSAGE_IOUTIL_H
34
Helper class for join() I/O manipulator.
36
This is a join I/O manipulator with arguments for @c join(). These has to be
38
template <class FwdIter> class joiner {
39
friend std::ostream& operator<<(std::ostream& out, const joiner& j) {
45
explicit joiner(const std::string& separator, FwdIter start, FwdIter finish)
46
: m_sep(separator), m_start(start), m_finish(finish)
52
FwdIter m_start, m_finish;
54
void write(std::ostream& out) const {
55
if (m_start == m_finish)
70
Join manipulators for writing delimiter-separated strings to an
73
Use the manipulator as follows:
75
std::cout << ioutil::join(",", list.begin(), list.end()) << std::endl;
76
std::cout << ioutil::join(",", list) << std::endl;
79
template <class FwdIter>
81
join(const std::string& delim, FwdIter start, FwdIter finish) {
82
return joiner<FwdIter>(delim, start, finish);
86
template <class Container>
87
joiner<typename Container::const_iterator>
88
join(const std::string& delim, Container seq) {
89
typedef typename Container::const_iterator FwdIter;
90
return joiner<FwdIter>(delim, seq.begin(), seq.end());
93
} /* namespace ioutil */
94
} /* namespace message */
95
} /* namespace drizzled */
97
#endif /* DRIZZLED_MESSAGE_IOUTIL_H */