~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/ioutil.h

  • Committer: Brian Aker
  • Date: 2009-10-15 00:22:33 UTC
  • mto: (1183.1.11 merge)
  • mto: This revision was merged to the branch mainline in revision 1198.
  • Revision ID: brian@gaz-20091015002233-fa4ao2mbc67wls91
First pass of information engine. OMG, ponies... is it so much easier to
deal with creating and engine.

The list table iterator though... its ass, needs to go. We should also
abstract out share. Very few engines need a custom one. Just say'in

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 */
19
 
 
20
 
#ifndef DRIZZLED_MESSAGE_IOUTIL_H
21
 
#define DRIZZLED_MESSAGE_IOUTIL_H
22
 
 
23
 
#include <iosfwd>
24
 
#include <string>
25
 
 
26
 
namespace drizzled
27
 
{
28
 
namespace message
29
 
{
30
 
namespace ioutil
31
 
{
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
 
  }
92
 
 
93
 
} /* namespace ioutil */
94
 
} /* namespace message */
95
 
} /* namespace drizzled */
96
 
 
97
 
#endif /* DRIZZLED_MESSAGE_IOUTIL_H */