Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
identities.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 
4 #include <vcsn/misc/builtins.hh>
5 #include <vcsn/misc/stream.hh>
6 
7 namespace vcsn
8 {
9 
10  namespace rat
11  {
12 
13  std::string to_string(identities i)
14  {
15  switch (i)
16  {
18  return "trivial";
19  case identities::series:
20  return "series";
21  }
23  }
24 
25  std::ostream& operator<<(std::ostream& os, identities i)
26  {
27  return os << to_string(i);
28  }
29 
30  std::istream& operator>>(std::istream& is, identities& i)
31  {
32  switch (is.peek())
33  {
34  case 't':
35  eat(is, "trivial");
37  break;
38  case 's':
39  eat(is, "series");
41  break;
42  default:
43  fail_reading(is, "ill-formed identities");
44  }
45  return is;
46  }
47 
49  {
50  if (i1 == identities::trivial || i2 == identities::trivial)
51  return identities::trivial;
52  else
53  return identities::series;
54  }
55 
56  } // namespace rat
57 
58 } // namespace vcsn
std::istream & operator>>(std::istream &is, identities &i)
Definition: identities.cc:30
std::ostream & operator<<(std::ostream &o, type_t t)
Definition: printer.hxx:16
std::string to_string(identities i)
Definition: identities.cc:13
Trivial identities only.
identities meet(identities i1, identities i2)
Definition: identities.cc:48
Trivial identities plus series identities.
std::istringstream is
The input stream: the specification to translate.
Definition: translate.cc:329
std::ostringstream os
The output stream: the corresponding C++ snippet to compile.
Definition: translate.cc:331
char eat(std::istream &is, char c)
Check lookahead character and advance.
Definition: stream.cc:37
ATTRIBUTE_NORETURN void fail_reading(std::istream &is, std::string explanation)
Throw an exception after failing to read from is.
Definition: stream.cc:107
identities
A ratexpset can implement several different sets of identities on expressions.
Definition: identities.hh:17
#define BUILTIN_UNREACHABLE()
Definition: builtins.hh:14