www.mooseframework.org
InfixIterator.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 // infix_iterator.h
15 
16 // Lifted from Jerry Coffin's 's prefix_ostream_iterator, no copyright or license
17 #ifndef INFIXITERATOR_H
18 #define INFIXITERATOR_H
19 
20 #include <ostream>
21 #include <iterator>
22 
23 template <class T, class charT = char, class traits = std::char_traits<charT>>
25  : public std::iterator<std::output_iterator_tag, void, void, void, void>
26 {
27  std::basic_ostream<charT, traits> * os;
28  charT const * delimiter;
29  bool first_elem;
30 
31 public:
32  typedef charT char_type;
33  typedef traits traits_type;
34  typedef std::basic_ostream<charT, traits> ostream_type;
35  infix_ostream_iterator(ostream_type & s) : os(&s), delimiter(0), first_elem(true) {}
36  infix_ostream_iterator(ostream_type & s, charT const * d, bool first = true)
37  : os(&s), delimiter(d), first_elem(first)
38  {
39  }
41  {
42  // Here's the only real change from ostream_iterator:
43  // Normally, the '*os << item;' would come before the 'if'.
44  if (!first_elem && delimiter != 0)
45  *os << delimiter;
46  *os << item;
47  first_elem = false;
48  return *this;
49  }
53 };
54 
55 #endif
charT const * delimiter
Definition: InfixIterator.h:28
infix_ostream_iterator(ostream_type &s, charT const *d, bool first=true)
Definition: InfixIterator.h:36
infix_ostream_iterator< T, charT, traits > & operator=(T const &item)
Definition: InfixIterator.h:40
infix_ostream_iterator(ostream_type &s)
Definition: InfixIterator.h:35
infix_ostream_iterator< T, charT, traits > & operator*()
Definition: InfixIterator.h:50
std::basic_ostream< charT, traits > ostream_type
Definition: InfixIterator.h:34
std::basic_ostream< charT, traits > * os
Definition: InfixIterator.h:27
infix_ostream_iterator< T, charT, traits > & operator++(int)
Definition: InfixIterator.h:52
infix_ostream_iterator< T, charT, traits > & operator++()
Definition: InfixIterator.h:51