tudocomp
– The TU Dortmund Compression Framework
AlgorithmDecl.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 
6 namespace tdc {
8  namespace decl {
9  /*
10  Representation of the declaration in the Registry.
11  It cares about the exact types and signatures of the invokations,
12  and about the documentation for the help printout
13  */
14  class Algorithm;
15  class Arg;
16  class Algorithm {
17  std::string m_name;
18  std::vector<Arg> m_arguments;
19  std::string m_doc;
20  ds::InputRestrictionsAndFlags m_ds_flags;
21 
22  public:
23 
24  inline Algorithm(std::string&& name,
25  std::vector<Arg>&& args,
26  std::string&& doc,
27  ds::InputRestrictionsAndFlags flags):
28  m_name(std::move(name)),
29  m_arguments(std::move(args)),
30  m_doc(std::move(doc)),
31  m_ds_flags(flags) {}
32 
33  inline const std::string& name() const {
34  return m_name;
35  }
36 
37  inline const std::vector<Arg>& arguments() const {
38  return m_arguments;
39  }
40  inline std::vector<Arg>& arguments() {
41  return m_arguments;
42  }
43 
44  inline const std::string& doc() const {
45  return m_doc;
46  }
47 
48  inline ds::InputRestrictionsAndFlags textds_flags() {
49  return m_ds_flags;
50  }
51 
52  inline std::string to_string(bool omit_type = false) const;
53 
54  friend inline bool operator==(const Algorithm &lhs, const Algorithm &rhs);
55  };
56  class Arg {
57  std::string m_name;
58  bool m_is_static;
59  std::string m_type;
60  bool m_has_default;
61  ast::Value m_default;
62 
63  public:
64 
65  inline Arg(std::string&& name,
66  bool is_static,
67  std::string&& type):
68  m_name(std::move(name)),
69  m_is_static(is_static),
70  m_type(std::move(type)),
71  m_has_default(false) {}
72  inline Arg(std::string&& name,
73  bool is_static,
74  std::string&& type,
75  ast::Value&& default_value):
76  m_name(std::move(name)),
77  m_is_static(is_static),
78  m_type(std::move(type)),
79  m_has_default(true),
80  m_default(std::move(default_value)) {}
81 
82  inline const std::string& name() const {
83  return m_name;
84  }
85  inline bool is_static() const {
86  return m_is_static;
87  }
88  inline const std::string& type() const {
89  return m_type;
90  }
91  inline bool has_default() const {
92  return m_has_default;
93  }
94 
95  inline const ast::Value& default_value() const {
96  return m_default;
97  }
98  inline ast::Value& default_value() {
99  return m_default;
100  }
101 
102  inline std::string to_string(bool omit_type = false) const;
103 
104  friend inline bool operator==(const Arg &lhs, const Arg &rhs);
105  };
106 
107  inline std::ostream& operator<<(std::ostream& os,
108  const Algorithm& x) {
109  os << x.to_string();
110  return os;
111  }
112  inline std::ostream& operator<<(std::ostream& os,
113  const Arg& x) {
114  os << x.to_string();
115  return os;
116  }
117 
118  inline std::string Algorithm::to_string(bool omit_type) const {
119  std::stringstream ss;
120  ss << name();
121  if (arguments().size() > 0) {
122  ss << "(";
123  bool first = true;
124  for (auto& a: arguments()) {
125  if (!first) {
126  ss << ", ";
127  }
128  ss << a.to_string(omit_type);
129  first = false;
130  }
131  ss << ")";
132  }
133  return ss.str();
134  }
135 
136  inline bool operator==(const Arg &lhs, const Arg &rhs);
137  inline bool operator==(const Algorithm &lhs, const Algorithm &rhs);
138 
139  inline bool operator!=(const Arg &lhs, const Arg &rhs) {
140  return !(lhs == rhs);
141  }
142  inline bool operator!=(const Algorithm &lhs, const Algorithm &rhs) {
143  return !(lhs == rhs);
144  }
145 
146  inline bool operator==(const Arg &lhs, const Arg &rhs) {
147  if (lhs.m_name != rhs.m_name) return false;
148  if (lhs.m_is_static != rhs.m_is_static) return false;
149  if (lhs.m_type != rhs.m_type) return false;
150  if (lhs.m_has_default != rhs.m_has_default) return false;
151  if (lhs.m_default != rhs.m_default) return false;
152  return true;
153  }
154 
155  inline bool operator==(const Algorithm &lhs, const Algorithm &rhs) {
156  if (lhs.m_name != rhs.m_name) return false;
157  if (lhs.m_arguments != rhs.m_arguments) return false;
158  if (lhs.m_doc != rhs.m_doc) return false;
159  return true;
160  }
161 
162  inline std::string Arg::to_string(bool omit_type) const {
163  std::stringstream ss;
164  ss << name();
165  if (!omit_type) {
166  ss << ": ";
167  if (is_static()) {
168  ss << "static ";
169  }
170  ss << type();
171  }
172  if (has_default()) {
173  ss << " = " << default_value();
174  }
175  return ss.str();
176  }
177  }
179 }
bool operator!=(const ConstGenericView< uliteral_t > &lhs, const ConstGenericView< uliteral_t > &rhs)
Contains the text compression and encoding framework.
Definition: namespaces.hpp:11
std::ostream & operator<<(std::ostream &os, const uint_impl_t< N > &v)
Definition: uint_t.hpp:135
bool operator==(const ConstGenericView< uliteral_t > &lhs, const ConstGenericView< uliteral_t > &rhs)
std::string to_string(tdc::uint_impl_t< N > value)
Definition: uint_t.hpp:241