Vcsn  2.6
Be Rational
format.cc
Go to the documentation of this file.
1 #include <cctype>
2 
3 #include <vcsn/misc/builtins.hh>
4 #include <vcsn/misc/format.hh>
5 #include <vcsn/misc/getargs.hh>
6 
7 namespace vcsn
8 {
9 
10  format::format(const std::string& f)
11  {
12  static const auto map = getarg<format_t>
13  {
14  "format",
15  {
16  {"auto", "default"},
17  {"default", deflt},
18  {"latex", latex},
19  {"raw", raw},
20  {"sname", sname},
21  {"text", text},
22  {"utf8", utf8},
23  }
24  };
25  format_ = map[f];
26  }
27 
28  std::string to_string(format f)
29  {
30  switch (f.kind())
31  {
32  case format::latex:
33  return "latex";
34  case format::raw:
35  return "raw";
36  case format::sname:
37  return "sname";
38  case format::text:
39  return "text";
40  case format::utf8:
41  return "utf8";
42  }
44  }
45 
46  std::ostream& operator<<(std::ostream& os, format i)
47  {
48  return os << to_string(i);
49  }
50 
51  std::istream& operator>>(std::istream& is, format& fmt)
52  {
53  std::string buf;
54  while (is && isalnum(is.peek()))
55  buf += is.get();
56  fmt = format(buf);
57  return is;
58  }
59 
60 } // namespace vcsn
std::ostream & operator<<(std::ostream &os, direction d)
Pretty-printing.
Definition: direction.cc:19
std::string to_string(direction d)
Conversion to string.
Definition: direction.cc:7
Request the map implementation.
Print as rich UTF-8 text, escaped.
Definition: format.hh:30
An input/output format for valuesets.
Definition: format.hh:13
std::ostringstream os
The output stream: the corresponding C++ snippet to compile.
Definition: translate.cc:399
By default, print for text.
Definition: format.hh:32
A mapping from strings to Values.
Definition: getargs.hh:33
Print for LaTeX.
Definition: format.hh:22
Definition: a-star.hh:8
format_t format_
Definition: format.hh:119
Print as plain (ASCII) text, escaped.
Definition: format.hh:28
format_t kind() const
Definition: format.hh:98
std::istream & operator>>(std::istream &is, direction &d)
Parsing.
Definition: direction.cc:24
format(format_t f=deflt)
Definition: format.hh:35
#define BUILTIN_UNREACHABLE()
Definition: builtins.hh:13
Print as is. For instance, don&#39;t try to escape labels.
Definition: format.hh:24
Print as a parsable type string.
Definition: format.hh:26