Vcsn  2.3
Be Rational
format.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 
5 #include <vcsn/misc/export.hh>
6 
7 namespace vcsn LIBVCSN_API
8 {
9 
13  class format
14  {
15  public:
16  using self_t = format;
17 
19  enum format_t
20  {
24  raw,
33  };
34 
36  : format_{f}
37  {}
38 
39  format(const std::string& f);
40 
43  {
44  auto res = *this;
45  res.label_ = true;
46  return res;
47  }
48 
51  {
52  auto res = *this;
53  res.label_ = false;
54  return res;
55  }
56 
58  bool delimit() const
59  {
60  return delimit_;
61  }
62 
64  format delimit(bool d) const
65  {
66  auto res = *this;
67  res.delimit_ = d;
68  return res;
69  }
70 
72  const char* meta() const
73  {
74  return meta_;
75  }
76 
79  format meta(const char* m) const
80  {
81  auto res = *this;
82  res.meta_ = m;
83  return res;
84  }
85 
87  bool is_for_labels() const
88  {
89  return label_;
90  }
91 
93  bool is_for_weights() const
94  {
95  return !label_;
96  }
97 
98  format_t kind() const
99  {
100  return format_;
101  }
102 
103  bool operator<(self_t that) const
104  {
105  return format_ < that.format_;
106  }
107 
108  bool operator==(self_t that) const
109  {
110  return format_ == that.format_;
111  }
112 
113  bool operator!=(self_t that) const
114  {
115  return !operator==(that);
116  }
117 
118  private:
122  bool label_ = false;
124  bool delimit_ = false;
126  const char* meta_ = nullptr;
127  };
128 
130  std::string to_string(format i);
131 
133  std::istream& operator>>(std::istream& is, format& i);
134 
136  std::ostream& operator<<(std::ostream& os, format i);
137 } // namespace vcsn
format_t
Type of format.
Definition: format.hh:19
format for_labels() const
A copy of this format, but to print labels.
Definition: format.hh:42
bool delimit() const
Whether we should delimit: (1, 2) instead of 1, 2.
Definition: format.hh:58
format delimit(bool d) const
Set whether we should delimit: (1, 2) instead of 1, 2.
Definition: format.hh:64
bool is_for_labels() const
Whether to use the syntax for labels (e.g., "a|x").
Definition: format.hh:87
std::ostream & operator<<(std::ostream &os, direction d)
Pretty-printing.
Definition: direction.cc:19
bool operator!=(self_t that) const
Definition: format.hh:113
bool delimit_
Whether we should delimit. E.g., 1, 2 or (1, 2).
Definition: format.hh:124
const char * meta_
Additional characters to escape.
Definition: format.hh:126
Print as a parsable type string.
Definition: format.hh:26
bool is_for_weights() const
Whether to use the syntax for weights (e.g., "(1, 1/2)").
Definition: format.hh:93
return res
Definition: multiply.hh:398
bool operator<(self_t that) const
Definition: format.hh:103
Definition: a-star.hh:8
format(format_t f=deflt)
Definition: format.hh:35
An input/output format for valuesets.
Definition: format.hh:13
bool operator==(self_t that) const
Definition: format.hh:108
#define LIBVCSN_API
Definition: export.hh:8
By default, print for text.
Definition: format.hh:32
format_t kind() const
Definition: format.hh:98
Print as is. For instance, don't try to escape labels.
Definition: format.hh:24
std::string to_string(direction d)
Conversion to string.
Definition: direction.cc:7
Print as rich UTF-8 text, escaped.
Definition: format.hh:30
std::istream & operator>>(std::istream &is, direction &d)
Parsing.
Definition: direction.cc:24
const char * meta() const
Characters that need to be escaped.
Definition: format.hh:72
Print for LaTeX.
Definition: format.hh:22
format_t format_
Definition: format.hh:119
std::ostringstream os
The output stream: the corresponding C++ snippet to compile.
Definition: translate.cc:375
Print as plain (ASCII) text, escaped.
Definition: format.hh:28
format for_weights() const
A copy of this format, but to print weights.
Definition: format.hh:50
bool label_
Whether printed as a label (e.g., a|x), or as a weight (e.g., (1, 1/2)).
Definition: format.hh:122
format meta(const char *m) const
Set the list of additional meta characters that need to be escaped.
Definition: format.hh:79