Vcsn  2.2
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 = getarg<identities::ids_t>
43  {
44  "identities",
45  {
46  {"associative", identities::associative},
47  {"auto", identities::deflt},
48  {"binary", "trivial"},
49  {"default", identities::deflt},
50  {"distributive", identities::distributive},
51  {"linear", identities::linear},
52  {"none", identities::none},
53  {"series", "distributive"},
54  {"trivial", identities::trivial},
55  }
56  };
57  std::string buf;
58  while (is && isalnum(is.peek()))
59  buf += is.get();
60  ids = map[buf];
61  return is;
62  }
63 
64  std::istream& operator>>(std::istream& is, identities& ids)
65  {
67  is >> id;
68  ids = identities{id};
69  return is;
70  }
71 
73  {
74  return std::max(i1, i2);
75  }
76 
77  } // namespace rat
78 
79 } // namespace vcsn
ids_t ids() const
Definition: identities.hh:52
An expressionset can implement several different sets of identities on expressions.
Definition: identities.hh:21
Definition: a-star.hh:8
std::ostringstream os
The output stream: the corresponding C++ snippet to compile.
Definition: translate.cc:382
Traditional plus distribution. Used for series identities.
Definition: identities.hh:42
Trivial, plus associativity of sum and product.
Definition: identities.hh:35
#define BUILTIN_UNREACHABLE()
Definition: builtins.hh:13
A mapping from strings to Values.
Definition: getargs.hh:33
std::ostream & operator<<(std::ostream &o, type_t t)
Definition: printer.hxx:14
identities meet(identities i1, identities i2)
Definition: identities.cc:72
Associative plus commutativity, and "idempotence" for sum.
Definition: identities.hh:39
The default value.
Definition: identities.hh:45
std::istringstream is
The input stream: the specification to translate.
Definition: translate.cc:380
std::istream & operator>>(std::istream &is, identities &i)
Read from string form.
Definition: identities.cc:64
std::string to_string(identities i)
Wrapper around operator<<.
Definition: identities.cc:17
static identities ids(const driver &d)
Get the identities of the driver.
Definition: parse.cc:89
Trivial identities only.
Definition: identities.hh:32
Strictly obey to the syntax.
Definition: identities.hh:29