~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
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
1122.2.2 by Monty Taylor
Added missing copyright headers. Added drizzled/global.h to a few things that
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
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
20
#pragma once
1122.2.10 by Monty Taylor
Fixed all of the include guards.
21
324.1.1 by Mats Kindahl
Adding specification of a simple protobuf-based binary log format,
22
#include <iosfwd>
23
#include <string>
24
1122.2.2 by Monty Taylor
Added missing copyright headers. Added drizzled/global.h to a few things that
25
namespace drizzled
26
{
27
namespace message
28
{
29
namespace ioutil
30
{
324.1.1 by Mats Kindahl
Adding specification of a simple protobuf-based binary log format,
31
32
  /**
33
     Helper class for join() I/O manipulator.
34
35
     This is a join I/O manipulator with arguments for @c join(). These has to be
36
  */
37
  template <class FwdIter> class joiner {
38
    friend std::ostream& operator<<(std::ostream& out, const joiner& j) {
39
      j.write(out);
40
      return out;
41
    }
42
43
  public:
44
    explicit joiner(const std::string& separator, FwdIter start, FwdIter finish)
45
      : m_sep(separator), m_start(start), m_finish(finish)
46
    { }
47
48
49
  private:
50
    std::string m_sep;
51
    FwdIter m_start, m_finish;
52
53
    void write(std::ostream& out) const {
54
      if (m_start == m_finish)
55
        return;
56
57
      FwdIter fi = m_start;
58
      while (true) {
59
        out << *fi;
60
        if (++fi == m_finish)
61
          break;
62
        out << m_sep;
63
      }
64
    }
65
  };
66
67
68
  /**
69
     Join manipulators for writing delimiter-separated strings to an
70
     ostream object.
71
72
     Use the manipulator as follows:
73
     @code
74
     std::cout << ioutil::join(",", list.begin(), list.end()) << std::endl;
75
     std::cout << ioutil::join(",", list) << std::endl;
76
     @endcode
77
  */
78
  template <class FwdIter>
79
  joiner<FwdIter>
80
  join(const std::string& delim, FwdIter start, FwdIter finish) {
81
    return joiner<FwdIter>(delim, start, finish);
82
  }
83
84
  /** @overload */
85
  template <class Container>
86
  joiner<typename Container::const_iterator>
87
  join(const std::string& delim, Container seq) {
88
    typedef typename Container::const_iterator FwdIter;
89
    return joiner<FwdIter>(delim, seq.begin(), seq.end());
90
  }
1122.2.2 by Monty Taylor
Added missing copyright headers. Added drizzled/global.h to a few things that
91
92
} /* namespace ioutil */
93
} /* namespace message */
94
} /* namespace drizzled */
1122.2.10 by Monty Taylor
Fixed all of the include guards.
95