~drizzle-trunk/drizzle/development

1122.2.2 by Monty Taylor
Added missing copyright headers. Added drizzled/global.h to a few things that
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2009 Sun Microsystems
5
 *
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.
9
 *
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.
14
 *
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
18
 */
324.1.1 by Mats Kindahl
Adding specification of a simple protobuf-based binary log format,
19
1122.2.10 by Monty Taylor
Fixed all of the include guards.
20
#ifndef DRIZZLED_MESSAGE_IOUTIL_H
21
#define DRIZZLED_MESSAGE_IOUTIL_H
22
324.1.1 by Mats Kindahl
Adding specification of a simple protobuf-based binary log format,
23
#include <iosfwd>
24
#include <string>
25
1122.2.2 by Monty Taylor
Added missing copyright headers. Added drizzled/global.h to a few things that
26
namespace drizzled
27
{
28
namespace message
29
{
30
namespace ioutil
31
{
324.1.1 by Mats Kindahl
Adding specification of a simple protobuf-based binary log format,
32
33
  /**
34
     Helper class for join() I/O manipulator.
35
36
     This is a join I/O manipulator with arguments for @c join(). These has to be
37
  */
38
  template <class FwdIter> class joiner {
39
    friend std::ostream& operator<<(std::ostream& out, const joiner& j) {
40
      j.write(out);
41
      return out;
42
    }
43
44
  public:
45
    explicit joiner(const std::string& separator, FwdIter start, FwdIter finish)
46
      : m_sep(separator), m_start(start), m_finish(finish)
47
    { }
48
49
50
  private:
51
    std::string m_sep;
52
    FwdIter m_start, m_finish;
53
54
    void write(std::ostream& out) const {
55
      if (m_start == m_finish)
56
        return;
57
58
      FwdIter fi = m_start;
59
      while (true) {
60
        out << *fi;
61
        if (++fi == m_finish)
62
          break;
63
        out << m_sep;
64
      }
65
    }
66
  };
67
68
69
  /**
70
     Join manipulators for writing delimiter-separated strings to an
71
     ostream object.
72
73
     Use the manipulator as follows:
74
     @code
75
     std::cout << ioutil::join(",", list.begin(), list.end()) << std::endl;
76
     std::cout << ioutil::join(",", list) << std::endl;
77
     @endcode
78
  */
79
  template <class FwdIter>
80
  joiner<FwdIter>
81
  join(const std::string& delim, FwdIter start, FwdIter finish) {
82
    return joiner<FwdIter>(delim, start, finish);
83
  }
84
85
  /** @overload */
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());
91
  }
1122.2.2 by Monty Taylor
Added missing copyright headers. Added drizzled/global.h to a few things that
92
93
} /* namespace ioutil */
94
} /* namespace message */
95
} /* namespace drizzled */
1122.2.10 by Monty Taylor
Fixed all of the include guards.
96
97
#endif /* DRIZZLED_MESSAGE_IOUTIL_H */