}
};
-class XBT_PUBLIC ParseError : public Exception, public std::invalid_argument {
- int line_;
- std::string file_;
- std::string msg_;
- char* rendered_what = nullptr;
-
+/** Exception raised when something is going wrong during the parsing of XML files */
+class ParseError : public Exception {
public:
- ParseError(int line, std::string& file, std::string&& msg)
- : Exception(XBT_THROW_POINT, std::move(msg)), std::invalid_argument(msg), line_(line), file_(file), msg_(msg)
+ ParseError(const std::string& file, int line, const std::string& msg)
+ : Exception(XBT_THROW_POINT, xbt::string_printf("Parse error at %s:%d: %s", file.c_str(), line, msg.c_str()))
{
- rendered_what = bprintf("Parse error at %s:%d: %s", file_.c_str(), line_, msg_.c_str());
}
- ~ParseError() { free(rendered_what); }
-
- const char* what() const noexcept override { return rendered_what; }
};
class XBT_PUBLIC ForcefulKillException {
XBT_PUBLIC void surf_parse_open(const std::string& file);
XBT_PUBLIC void surf_parse_close();
-XBT_PUBLIC void surf_parse_assert(bool cond, std::string&& msg);
-SG_BEGIN_DECL
-XBT_ATTRIB_NORETURN XBT_PUBLIC void surf_parse_error(const char* msg);
-SG_END_DECL
-XBT_ATTRIB_NORETURN XBT_PUBLIC void surf_parse_error(std::string&& msg);
+XBT_PUBLIC void surf_parse_assert(bool cond, const std::string& msg);
+XBT_ATTRIB_NORETURN XBT_PUBLIC void surf_parse_error(const std::string& msg);
XBT_PUBLIC void surf_parse_assert_netpoint(const std::string& hostname, const std::string& pre,
const std::string& post);
/*
* Helping functions
*/
-void surf_parse_assert(bool cond, std::string&& msg)
+void surf_parse_assert(bool cond, const std::string& msg)
{
if (not cond)
- surf_parse_error(std::move(msg));
+ surf_parse_error(msg);
}
-void surf_parse_error(const char* msg) {
- throw simgrid::ParseError(surf_parse_lineno, surf_parsed_filename, std::string(msg));
-}
-
-void surf_parse_error(std::string&& msg)
+void surf_parse_error(const std::string& msg)
{
- throw simgrid::ParseError(surf_parse_lineno, surf_parsed_filename, std::move(msg));
+ throw simgrid::ParseError(surf_parsed_filename, surf_parse_lineno, msg);
}
void surf_parse_assert_netpoint(const std::string& hostname, const std::string& pre, const std::string& post)