Vcsn  2.1
Be Rational
identities.cc
Go to the documentation of this file.
1 #include <cctype>
2 #include <map>
3 
5 #include <vcsn/misc/builtins.hh>
6 #include <vcsn/misc/getargs.hh>
8 #include <vcsn/misc/map.hh>
9 #include <vcsn/misc/stream.hh>
10 
11 namespace vcsn
12 {
13 
14  namespace rat
15  {
16 
17  std::string to_string(identities i)
18  {
19  switch (i.ids())
20  {
22  return "associative";
23  case identities::linear:
24  return "linear";
26  return "distributive";
28  return "trivial";
29  case identities::none:
30  return "none";
31  }
33  }
34 
35  std::ostream& operator<<(std::ostream& os, identities i)
36  {
37  return os << to_string(i);
38  }
39 
40  static std::istream& operator>>(std::istream& is, identities::ids_t& ids)
41  {
42  static const auto map = std::map<std::string, identities::ids_t>
43  {
44  {"associative", identities::associative},
45  {"auto", identities::deflt},
46  {"binary", identities::trivial},
47  {"default", identities::deflt},
48  {"distributive", identities::distributive},
49  {"linear", identities::linear},
50  {"none", identities::none},
51  {"series", identities::distributive},
52  {"trivial", identities::trivial},
53  };
54 
55  std::string buf;
56  while (is && isalnum(is.peek()))
57  buf += is.get();
58 
59  ids = getargs("identities", map, buf);
60  return is;
61  }
62 
63  std::istream& operator>>(std::istream& is, identities& ids)
64  {
66  is >> id;
67  ids = identities{id};
68  return is;
69  }
70 
72  {
73  return std::max(i1, i2);
74  }
75 
76  } // namespace rat
77 
78 } // namespace vcsn
Strictly obey to the syntax.
Definition: identities.hh:29
std::istream & operator>>(std::istream &is, identities &i)
Read from string form.
Definition: identities.cc:63
ids_t ids() const
Definition: identities.hh:52
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::string to_string(identities i)
Wrapper around operator<<.
Definition: identities.cc:17
std::ostream & operator<<(std::ostream &o, type_t t)
Definition: printer.hxx:13
Traditional plus distribution. Used for series identities.
Definition: identities.hh:42
Associative plus commutativity, and "idempotence" for sum.
Definition: identities.hh:39
static identities ids(const driver &d)
Get the identities of the driver.
Definition: parse.cc:87
The default value.
Definition: identities.hh:45
std::ostringstream os
The output stream: the corresponding C++ snippet to compile.
Definition: translate.cc:374
An expressionset can implement several different sets of identities on expressions.
Definition: identities.hh:21
identities meet(identities i1, identities i2)
Definition: identities.cc:71
Trivial identities only.
Definition: identities.hh:32
#define BUILTIN_UNREACHABLE()
Definition: builtins.hh:13
Trivial, plus associativity of sum and product.
Definition: identities.hh:35