Vcsn  2.2a
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,
31  };
32 
34  : format_{f}
35  {}
36 
37  format(const std::string& f);
38 
41  {
42  auto res = *this;
43  res.label_ = true;
44  return res;
45  }
46 
49  {
50  auto res = *this;
51  res.label_ = false;
52  return res;
53  }
54 
56  bool delimit() const
57  {
58  return delimit_;
59  }
60 
62  format delimit(bool d) const
63  {
64  auto res = *this;
65  res.delimit_ = d;
66  return res;
67  }
68 
70  bool is_for_labels() const
71  {
72  return label_;
73  }
74 
76  bool is_for_weights() const
77  {
78  return !label_;
79  }
80 
81  format_t kind() const
82  {
83  return format_;
84  }
85 
86  bool operator<(self_t that) const
87  {
88  return format_ < that.format_;
89  }
90 
91  bool operator==(self_t that) const
92  {
93  return format_ == that.format_;
94  }
95 
96  bool operator!=(self_t that) const
97  {
98  return !operator==(that);
99  }
100 
101  private:
105  bool label_ = false;
107  bool delimit_ = false;
108  };
109 
111  std::string to_string(format i);
112 
114  std::istream& operator>>(std::istream& is, format& i);
115 
117  std::ostream& operator<<(std::ostream& os, format i);
118 } // namespace vcsn
std::istringstream is
The input stream: the specification to translate.
Definition: translate.cc:380
#define LIBVCSN_API
Definition: export.hh:8
bool operator<(self_t that) const
Definition: format.hh:86
format_t format_
Definition: format.hh:102
Print as plain (ASCII) text, escaped.
Definition: format.hh:26
format(format_t f=deflt)
Definition: format.hh:33
bool delimit() const
Whether we should delimit: (1, 2) instead of 1, 2.
Definition: format.hh:56
format_t
Type of format.
Definition: format.hh:17
std::ostringstream os
The output stream: the corresponding C++ snippet to compile.
Definition: translate.cc:382
format for_labels() const
A copy of this format, but to print labels.
Definition: format.hh:40
std::istream & operator>>(std::istream &is, direction &d)
Parsing.
Definition: direction.cc:24
bool operator!=(self_t that) const
Definition: format.hh:96
Print as a parsable type string.
Definition: format.hh:24
By default, print for text.
Definition: format.hh:30
Print for LaTeX.
Definition: format.hh:20
bool operator==(self_t that) const
Definition: format.hh:91
format_t kind() const
Definition: format.hh:81
Print as is. For instance, don't try to escape labels.
Definition: format.hh:22
format for_weights() const
A copy of this format, but to print weights.
Definition: format.hh:48
bool delimit_
Whether we should delimit. E.g., 1, 2 or (1, 2).
Definition: format.hh:107
std::ostream & operator<<(std::ostream &os, direction d)
Pretty-printing.
Definition: direction.cc:19
bool is_for_weights() const
Whether to use the syntax for weights (e.g., "(1, 1/2)").
Definition: format.hh:76
format delimit(bool d) const
Set whether we should delimit: (1, 2) instead of 1, 2.
Definition: format.hh:62
std::string to_string(direction d)
Conversion to string.
Definition: direction.cc:7
bool is_for_labels() const
Whether to use the syntax for labels (e.g., "a|x").
Definition: format.hh:70
Print as rich UTF-8 text, escaped.
Definition: format.hh:28
bool label_
Whether printed as a label (e.g., a|x), or as a weight (e.g., (1, 1/2)).
Definition: format.hh:105
An input/output format for valuesets.
Definition: format.hh:11
Definition: a-star.hh:8