Vcsn  2.8
Be Rational
identities.cc
Go to the documentation of this file.
1 #include <cctype>
2 
4 #include <vcsn/misc/builtins.hh>
5 #include <vcsn/misc/getargs.hh>
6 
7 namespace vcsn
8 {
9 
10  namespace rat
11  {
12 
13  identities::identities(const std::string& s)
14  {
15  static const auto map = getarg<identities::ids_t>
16  {
17  "identities",
18  {
19  {"agressive", identities::agressive},
20  {"associative", identities::associative},
21  {"auto", identities::deflt},
22  {"binary", "trivial"},
23  {"default", identities::deflt},
24  {"distributive", identities::distributive},
25  {"linear", identities::linear},
26  {"none", identities::none},
27  {"series", "distributive"},
28  {"trivial", identities::trivial},
29  }
30  };
31  ids_ = map[s];
32  }
33 
34  identities::identities(const char* cp)
35  : identities(std::string{cp})
36  {}
37 
38  std::string to_string(identities i)
39  {
40  switch (i.ids())
41  {
43  return "associative";
45  return "agressive";
46  case identities::linear:
47  return "linear";
49  return "distributive";
51  return "trivial";
52  case identities::none:
53  return "none";
54  }
56  }
57 
58  std::ostream& operator<<(std::ostream& os, identities i)
59  {
60  return os << to_string(i);
61  }
62 
63  std::istream& operator>>(std::istream& is, identities& ids)
64  {
65  std::string buf;
66  while (is && isalnum(is.peek()))
67  buf += is.get();
68  ids = identities{buf};
69  return is;
70  }
71 
73  {
74  return std::max(i1, i2);
75  }
76  } // namespace rat
77 } // namespace vcsn
Associative plus commutativity, and "idempotence" for add.
Definition: identities.hh:38
Linear plus distribution. Used for series identities.
Definition: identities.hh:41
Strictly obey to the syntax.
Definition: identities.hh:28
Trivial identities only.
Definition: identities.hh:31
ids_t ids() const
Definition: identities.hh:60
An expressionset can implement several different sets of identities on expressions.
Definition: identities.hh:20
identities meet(identities i1, identities i2)
More restricted of these identities (min).
Definition: identities.cc:72
Trivial, plus associativity of add and product.
Definition: identities.hh:34
std::ostringstream os
The output stream: the corresponding C++ snippet to compile.
Definition: translate.cc:404
Definition: a-star.hh:8
Distributive plus optimizations.
Definition: identities.hh:44
std::string to_string(identities i)
Wrapper around operator<<.
Definition: identities.cc:38
A mapping from strings to Values.
Definition: getargs.hh:33
std::ostream & operator<<(std::ostream &o, type_t t)
Print a expression type.
Definition: printer.hxx:13
std::istream & operator>>(std::istream &is, identities &i)
Read from string form.
Definition: identities.cc:63
identities(ids_t id=deflt)
Definition: identities.hh:50
STL namespace.
#define BUILTIN_UNREACHABLE()
Definition: builtins.hh:13
The default value.
Definition: identities.hh:47