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