Vcsn  2.1
Be Rational
format.cc
Go to the documentation of this file.
1 #include <cctype>
2 #include <map>
3 
4 #include <vcsn/misc/builtins.hh>
5 #include <vcsn/misc/format.hh>
6 #include <vcsn/misc/getargs.hh>
7 #include <vcsn/misc/map.hh>
8 #include <vcsn/misc/stream.hh>
9 
10 namespace vcsn
11 {
12 
13  format::format(const std::string& f)
14  {
15  static const auto map = std::map<std::string, format_t>
16  {
17  {"auto", deflt},
18  {"default", deflt},
19  {"latex", latex},
20  {"raw", raw},
21  {"text", text},
22  };
23  format_ = getargs("format", map, f);
24  }
25 
26  std::string to_string(format f)
27  {
28  switch (f.kind())
29  {
30  case format::latex:
31  return "latex";
32  case format::raw:
33  return "raw";
34  case format::text:
35  return "text";
36  }
38  }
39 
40  std::ostream& operator<<(std::ostream& os, format i)
41  {
42  return os << to_string(i);
43  }
44 
45  std::istream& operator>>(std::istream& is, format& fmt)
46  {
47  std::string buf;
48  while (is && isalnum(is.peek()))
49  buf += is.get();
50  fmt = format(buf);
51  return is;
52  }
53 
54 } // namespace vcsn
format_t format_
Definition: format.hh:82
C::mapped_type getargs(const std::string &kind, const C &map, const std::string &key)
Find a correspondance in a map.
Definition: getargs.hh:21
std::istringstream is
The input stream: the specification to translate.
Definition: translate.cc:372
std::ostream & operator<<(std::ostream &os, direction d)
Pretty-printing.
Definition: direction.cc:19
format(format_t f=deflt)
Definition: format.hh:27
Print as is. For instance, don't try to escape labels.
Definition: format.hh:22
std::istream & operator>>(std::istream &is, direction &d)
Parsing.
Definition: direction.cc:24
An input/output format.
Definition: format.hh:11
By default, print for text.
Definition: format.hh:24
format_t kind() const
Definition: format.hh:61
std::ostringstream os
The output stream: the corresponding C++ snippet to compile.
Definition: translate.cc:374
std::string to_string(direction d)
Conversion to string.
Definition: direction.cc:7
#define BUILTIN_UNREACHABLE()
Definition: builtins.hh:13