Vcsn  2.4
Be Rational
direction.cc
Go to the documentation of this file.
1 #include <vcsn/misc/builtins.hh>
2 #include <vcsn/misc/direction.hh>
3 #include <vcsn/misc/stream.hh>
4 
5 namespace vcsn
6 {
7  std::string to_string(direction d)
8  {
9  switch (d)
10  {
11  case direction::forward:
12  return "forward";
14  return "backward";
15  }
17  }
18 
19  std::ostream& operator<<(std::ostream& os, direction d)
20  {
21  return os << to_string(d);
22  }
23 
24  std::istream& operator>>(std::istream& is, direction& d)
25  {
26  switch (is.peek())
27  {
28  case 'b':
29  eat(is, "backward");
31  break;
32  case 'f':
33  eat(is, "forward");
35  break;
36  default:
37  fail_reading(is, "invalid direction");
38  }
39  return is;
40  }
41 } // namespace vcsn
char eat(std::istream &is, char c)
Check lookahead character and advance.
Definition: stream.cc:90
std::istream & operator>>(std::istream &is, direction &d)
Parsing.
Definition: direction.cc:24
Looking upstream.
std::ostream & operator<<(std::ostream &os, direction d)
Pretty-printing.
Definition: direction.cc:19
std::ostringstream os
The output stream: the corresponding C++ snippet to compile.
Definition: translate.cc:375
Definition: a-star.hh:8
#define BUILTIN_UNREACHABLE()
Definition: builtins.hh:13
ATTRIBUTE_NORETURN void fail_reading(std::istream &is, Args &&...args)
Throw an exception after failing to read from is.
Definition: stream.hh:68
direction
Orientation.
Definition: direction.hh:11
std::string to_string(direction d)
Conversion to string.
Definition: direction.cc:7
Looking downstream.