Vcsn  2.3
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  identities::identities(const std::string& s)
18  {
19  static const auto map = getarg<identities::ids_t>
20  {
21  "identities",
22  {
23  {"associative", identities::associative},
24  {"auto", identities::deflt},
25  {"binary", "trivial"},
26  {"default", identities::deflt},
27  {"distributive", identities::distributive},
28  {"linear", identities::linear},
29  {"none", identities::none},
30  {"series", "distributive"},
31  {"trivial", identities::trivial},
32  }
33  };
34  ids_ = map[s];
35  }
36 
37  identities::identities(const char* cp)
38  : identities(std::string{cp})
39  {}
40 
41  std::string to_string(identities i)
42  {
43  switch (i.ids())
44  {
46  return "associative";
47  case identities::linear:
48  return "linear";
50  return "distributive";
52  return "trivial";
53  case identities::none:
54  return "none";
55  }
57  }
58 
59  std::ostream& operator<<(std::ostream& os, identities i)
60  {
61  return os << to_string(i);
62  }
63 
64  std::istream& operator>>(std::istream& is, identities& ids)
65  {
66  std::string buf;
67  while (is && isalnum(is.peek()))
68  buf += is.get();
69  ids = identities{buf};
70  return is;
71  }
72 
74  {
75  return std::max(i1, i2);
76  }
77  } // namespace rat
78 } // namespace vcsn
Strictly obey to the syntax.
Definition: identities.hh:29
#define BUILTIN_UNREACHABLE()
Definition: builtins.hh:13
std::ostream & operator<<(std::ostream &o, type_t t)
Print a expression type.
Definition: printer.hxx:13
STL namespace.
identities(ids_t id=deflt)
Definition: identities.hh:48
Trivial, plus associativity of add and product.
Definition: identities.hh:35
ids_t ids() const
Definition: identities.hh:58
Associative plus commutativity, and "idempotence" for add.
Definition: identities.hh:39
Traditional plus distribution. Used for series identities.
Definition: identities.hh:42
Definition: a-star.hh:8
An expressionset can implement several different sets of identities on expressions.
Definition: identities.hh:21
std::istream & operator>>(std::istream &is, identities &i)
Read from string form.
Definition: identities.cc:64
The default value.
Definition: identities.hh:45
std::string to_string(identities i)
Wrapper around operator<<.
Definition: identities.cc:41
identities meet(identities i1, identities i2)
Definition: identities.cc:73
Trivial identities only.
Definition: identities.hh:32
A mapping from strings to Values.
Definition: getargs.hh:33
static identities ids(const driver &d)
Get the identities of the driver.
Definition: parse.cc:89
std::ostringstream os
The output stream: the corresponding C++ snippet to compile.
Definition: translate.cc:375