Opts: Solve OptionsParser::Exception diamond inheritance problem
This commit is contained in:
@@ -29,9 +29,13 @@ public:
|
||||
class Exception : public std::exception
|
||||
{
|
||||
public:
|
||||
Exception() = default;
|
||||
explicit Exception(std::string message_);
|
||||
~Exception() override = default;
|
||||
const char* what() const noexcept override = 0;
|
||||
|
||||
const char* what() const noexcept override;
|
||||
|
||||
protected:
|
||||
std::string message;
|
||||
};
|
||||
|
||||
std::string argv0;
|
||||
@@ -45,13 +49,11 @@ public:
|
||||
};
|
||||
|
||||
class OptionsParserError
|
||||
: public std::invalid_argument, public OptionParser::Exception
|
||||
: public OptionParser::Exception
|
||||
{
|
||||
public:
|
||||
OptionsParserError(
|
||||
const std::string& errorMessage, const OptionParser& parser);
|
||||
|
||||
const char* what() const noexcept override;
|
||||
};
|
||||
|
||||
class JustPrintUsageNoError
|
||||
@@ -59,10 +61,6 @@ class JustPrintUsageNoError
|
||||
{
|
||||
public:
|
||||
explicit JustPrintUsageNoError(const OptionParser& parser);
|
||||
const char* what() const noexcept override;
|
||||
|
||||
private:
|
||||
std::string message;
|
||||
};
|
||||
|
||||
#endif // OPTS_H
|
||||
|
||||
+12
-12
@@ -10,28 +10,28 @@
|
||||
#include <spinscale/callableTracer.h>
|
||||
|
||||
|
||||
OptionParser::Exception::Exception(std::string message_)
|
||||
: message(std::move(message_))
|
||||
{
|
||||
}
|
||||
|
||||
const char* OptionParser::Exception::what() const noexcept
|
||||
{
|
||||
return message.c_str();
|
||||
}
|
||||
|
||||
OptionsParserError::OptionsParserError(
|
||||
const std::string& errorMessage, const OptionParser& parser
|
||||
)
|
||||
: std::invalid_argument(errorMessage + "\n" + parser.getUsage())
|
||||
: OptionParser::Exception(errorMessage + "\n" + parser.getUsage())
|
||||
{
|
||||
}
|
||||
|
||||
const char* OptionsParserError::what() const noexcept
|
||||
{
|
||||
return std::invalid_argument::what();
|
||||
}
|
||||
|
||||
JustPrintUsageNoError::JustPrintUsageNoError(const OptionParser& parser)
|
||||
: message(parser.getUsage())
|
||||
: OptionParser::Exception(parser.getUsage())
|
||||
{
|
||||
}
|
||||
|
||||
const char* JustPrintUsageNoError::what() const noexcept
|
||||
{
|
||||
return message.c_str();
|
||||
}
|
||||
|
||||
struct option OptionParser::longOptions[] = {
|
||||
{"dapspec", required_argument, 0, 's'},
|
||||
{"spec", required_argument, 0, 's'},
|
||||
|
||||
Reference in New Issue
Block a user