sbuild  1.7.2
parse-error.h
1 /* Copyright © 2005-2013 Roger Leigh <rleigh@debian.org>
2  *
3  * schroot is free software: you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * schroot is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  *********************************************************************/
18 
19 #ifndef SBUILD_PARSE_ERROR_H
20 #define SBUILD_PARSE_ERROR_H
21 
22 #include <sbuild/custom-error.h>
23 
24 #include <map>
25 #include <string>
26 
27 namespace sbuild
28 {
29 
33  template<typename T>
34  class parse_error : public error<T>
35  {
36  public:
37  typedef typename error<T>::error_type error_type;
38 
45  template<typename C>
46  parse_error (C const& context,
47  error_type error):
48  sbuild::error<T>(this->format_error(context, nullptr, nullptr, error, nullptr, nullptr, nullptr),
49  this->format_reason(context, nullptr, nullptr, error, nullptr, nullptr, nullptr))
50  {
51  }
52 
59  template<typename D>
60  parse_error (error_type error,
61  D const& detail):
62  sbuild::error<T>(this->format_error(nullptr, nullptr, nullptr, error, detail, nullptr, nullptr),
63  this->format_reason(nullptr, nullptr, nullptr, error, detail, nullptr, nullptr))
64  {
65  }
66 
74  template<typename D>
75  parse_error (size_t line,
76  error_type error,
77  D const& detail):
78  sbuild::error<T>(this->format_error(line, nullptr, nullptr, error, detail, nullptr, nullptr),
79  this->format_reason(line, nullptr, nullptr, error, detail, nullptr, nullptr))
80  {
81  }
82 
91  template<typename D>
92  parse_error (size_t line,
93  const std::string& group,
94  error_type error,
95  D const& detail):
96  sbuild::error<T>(this->format_error(line, group, nullptr, error, detail, nullptr, nullptr),
97  this->format_reason(line, group, nullptr, error, detail, nullptr, nullptr))
98  {
99  }
100 
110  template<typename D>
111  parse_error (size_t line,
112  const std::string& group,
113  const std::string& key,
114  error_type error,
115  D const& detail):
116  sbuild::error<T>(this->format_error(line, group, key, error, detail, nullptr, nullptr),
117  this->format_reason(line, group, key, error, detail, nullptr, nullptr))
118  {
119  }
120 
128  template<typename D>
129  parse_error (const std::string& group,
130  error_type error,
131  D const& detail):
132  sbuild::error<T>(this->format_error(group, nullptr, nullptr, error, detail, nullptr, nullptr),
133  this->format_reason(group, nullptr, nullptr, error, detail, nullptr, nullptr))
134  {
135  }
136 
145  template<typename D>
146  parse_error (const std::string& group,
147  const std::string& key,
148  error_type error,
149  D const& detail):
150  sbuild::error<T>(this->format_error(group, key, nullptr, error, detail, nullptr, nullptr),
151  this->format_reason(group, key, nullptr, error, detail, nullptr, nullptr))
152  {
153  }
154 
161  template<typename C>
162  parse_error (C const& context,
163  const std::runtime_error& error):
164  sbuild::error<T>(sbuild::error<T>::format_error(context, nullptr, nullptr, error, nullptr, nullptr, nullptr),
165  sbuild::error<T>::format_reason(context, nullptr, nullptr, error, nullptr, nullptr, nullptr))
166  {
167  }
168 
175  parse_error (size_t line,
176  const std::runtime_error& error):
177  sbuild::error<T>(sbuild::error<T>::format_error(line, nullptr, nullptr, error, nullptr, nullptr, nullptr),
178  sbuild::error<T>::format_reason(line, nullptr, nullptr, error, nullptr, nullptr, nullptr))
179  {
180  }
181 
189  parse_error (size_t line,
190  const std::string& group,
191  const std::runtime_error& error):
192  sbuild::error<T>(sbuild::error<T>::format_error(line, group, nullptr, error, nullptr, nullptr, nullptr),
193  sbuild::error<T>::format_reason(line, group, nullptr, error, nullptr, nullptr, nullptr))
194  {
195  }
196 
205  parse_error (size_t line,
206  const std::string& group,
207  const std::string& key,
208  const std::runtime_error& error):
209  sbuild::error<T>(sbuild::error<T>::format_error(line, group, key, error, nullptr, nullptr, nullptr),
210  sbuild::error<T>::format_reason(line, group, key, error, nullptr, nullptr, nullptr))
211  {
212  }
213 
220  parse_error (const std::string& group,
221  const std::runtime_error& error):
222  sbuild::error<T>(sbuild::error<T>::format_error(group, nullptr, nullptr, error, nullptr, nullptr, nullptr),
223  sbuild::error<T>::format_reason(group, nullptr, nullptr, error, nullptr, nullptr, nullptr))
224  {
225  }
226 
234  parse_error (const std::string& group,
235  const std::string& key,
236  const std::runtime_error& error):
237  sbuild::error<T>(sbuild::error<T>::format_error(group, key, nullptr, error, nullptr, nullptr, nullptr),
238  sbuild::error<T>::format_reason(group, key, nullptr, error, nullptr, nullptr, nullptr))
239  {
240  }
241 
242  };
243 
244 }
245 
246 #endif /* SBUILD_PARSE_ERROR_H */
247 
248 /*
249  * Local Variables:
250  * mode:C++
251  * End:
252  */
Debian source builder components.
Definition: ctty.cc:31
parse_error(error_type error, D const &detail)
The constructor.
Definition: parse-error.h:60
T error_type
The enum type providing the error codes for this type.
Definition: error.h:114
parse_error(size_t line, const std::string &group, const std::string &key, const std::runtime_error &error)
The constructor.
Definition: parse-error.h:205
parse_error(size_t line, const std::runtime_error &error)
The constructor.
Definition: parse-error.h:175
parse_error(size_t line, const std::string &group, error_type error, D const &detail)
The constructor.
Definition: parse-error.h:92
parse_error(size_t line, error_type error, D const &detail)
The constructor.
Definition: parse-error.h:75
parse_error(C const &context, const std::runtime_error &error)
The constructor.
Definition: parse-error.h:162
parse_error(size_t line, const std::string &group, const std::runtime_error &error)
The constructor.
Definition: parse-error.h:189
Error exception class.
Definition: error.h:110
parse_error(const std::string &group, const std::string &key, error_type error, D const &detail)
The constructor.
Definition: parse-error.h:146
Parse error.
Definition: parse-error.h:34
System group database entry.
Definition: util.h:824
static std::string format_error(A const &context1, B const &context2, C const &context3, error_type error, D const &detail1, E const &detail2, F const &detail3)
Format an error message.
parse_error(const std::string &group, const std::runtime_error &error)
The constructor.
Definition: parse-error.h:220
parse_error(C const &context, error_type error)
The constructor.
Definition: parse-error.h:46
parse_error(const std::string &group, const std::string &key, const std::runtime_error &error)
The constructor.
Definition: parse-error.h:234
parse_error(const std::string &group, error_type error, D const &detail)
The constructor.
Definition: parse-error.h:129
parse_error(size_t line, const std::string &group, const std::string &key, error_type error, D const &detail)
The constructor.
Definition: parse-error.h:111
static std::string format_reason(A const &context1, B const &context2, C const &context3, R const &error, D const &detail1, E const &detail2, F const &detail3)
Format an reason string.