Vcsn  2.1
Be Rational
format.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vcsn/misc/export.hh>
4 
5 namespace vcsn LIBVCSN_API
6 {
7 
11  class format
12  {
13  public:
14  using self_t = format;
15 
17  enum format_t
18  {
22  raw,
25  };
26 
28  : format_{f}
29  {}
30 
31  format(const std::string& f);
32 
35  {
36  format res = *this;
37  res.label_ = true;
38  return res;
39  }
40 
43  {
44  format res = *this;
45  res.label_ = false;
46  return res;
47  }
48 
50  bool is_for_labels() const
51  {
52  return label_;
53  }
54 
56  bool is_for_weights() const
57  {
58  return !label_;
59  }
60 
61  format_t kind() const
62  {
63  return format_;
64  }
65 
66  bool operator<(self_t that) const
67  {
68  return format_ < that.format_;
69  }
70 
71  bool operator==(self_t that) const
72  {
73  return format_ == that.format_;
74  }
75 
76  bool operator!=(self_t that) const
77  {
78  return !operator==(that);
79  }
80 
81  private:
85  bool label_ = false;
86  };
87 
89  std::string to_string(format i);
90 
92  std::istream& operator>>(std::istream& is, format& i);
93 
95  std::ostream& operator<<(std::ostream& os, format i);
96 } // namespace vcsn
format for_labels() const
A copy of this format, but to print labels.
Definition: format.hh:34
format_t
Type of format.
Definition: format.hh:17
format_t format_
Definition: format.hh:82
std::istringstream is
The input stream: the specification to translate.
Definition: translate.cc:372
std::ostream & operator<<(std::ostream &os, direction d)
Pretty-printing.
Definition: direction.cc:19
bool operator!=(self_t that) const
Definition: format.hh:76
format(format_t f=deflt)
Definition: format.hh:27
Print as is. For instance, don't try to escape labels.
Definition: format.hh:22
std::istream & operator>>(std::istream &is, direction &d)
Parsing.
Definition: direction.cc:24
bool is_for_weights() const
Whether to use the syntax for weights (e.g., "(1, 1/2)").
Definition: format.hh:56
An input/output format.
Definition: format.hh:11
By default, print for text.
Definition: format.hh:24
format_t kind() const
Definition: format.hh:61
bool operator<(self_t that) const
Definition: format.hh:66
std::ostringstream os
The output stream: the corresponding C++ snippet to compile.
Definition: translate.cc:374
bool label_
Whether printed as a label (e.g., "a|x"), or as a weight (e.g., "(1, 1/2)").
Definition: format.hh:85
std::string to_string(direction d)
Conversion to string.
Definition: direction.cc:7
#define LIBVCSN_API
Definition: export.hh:8
format for_weights() const
A copy of this format, but to print weights.
Definition: format.hh:42
bool operator==(self_t that) const
Definition: format.hh:71
bool is_for_labels() const
Whether to use the syntax for labels (e.g., "a|x").
Definition: format.hh:50