Vcsn  2.2
Be Rational
iostream.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 
5 #include <boost/iostreams/filtering_stream.hpp>
6 #include <boost/iostreams/char_traits.hpp> // EOF, WOULD_BLOCK
7 #include <boost/iostreams/concepts.hpp> // multichar_output_filter
8 #include <boost/iostreams/operations.hpp> // get
9 
10 namespace vcsn
11 {
12  namespace detail
13  {
14  namespace io = boost::iostreams;
15 
18  : public io::multichar_output_filter
19  {
20  public:
22  {}
23 
24  void enable()
25  {
26  enabled_ = true;
27  }
28 
29  void disable()
30  {
31  enabled_ = false;
32  }
33 
34  template <typename Sink>
35  std::streamsize
36  write(Sink& dest, const char* s, std::streamsize n)
37  {
38  std::streamsize z;
39  for (z = 0; z < n; ++z)
40  {
41  char c = s[z];
42  if (enabled_
43  && (c == '\\' || c == '"'))
44  if (!io::put(dest, '\\'))
45  // FIXME: probably lost a char here.
46  break;
47  if (!io::put(dest, c))
48  break;
49  }
50  return z;
51  }
52 
53  bool enabled_ = false;
54  };
55  }
56 }
Definition: a-star.hh:8
weightset_mixin< detail::z_impl > z
Definition: fwd.hh:56
std::streamsize write(Sink &dest, const char *s, std::streamsize n)
Definition: iostream.hh:36