Skip to content

Commit

Permalink
refactor: remove noexcept from code base
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Feb 28, 2024
1 parent cacc933 commit 65d0671
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 46 deletions.
2 changes: 1 addition & 1 deletion include/bedrock/command/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ class Command {
CommandRegistry *registry_ = nullptr; // +16
CommandRegistry::Symbol symbol_; // +24
CommandPermissionLevel permission_level_ = CommandPermissionLevel::Internal; // +28
CommandFlag command_flag_{0}; // +30
CommandFlag flag_{0}; // +30
};
static_assert(sizeof(Command) == 32);
17 changes: 11 additions & 6 deletions include/endstone/command/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace endstone {
class Command {
public:
explicit Command(CommandMap &command_map) : command_map_(command_map) {}
virtual ~Command() noexcept = default;
virtual ~Command() = default;

public:
/**
Expand All @@ -39,29 +39,34 @@ class Command {
* @param args Arguments passed to the command
* @return true if the execution was successful, otherwise false
*/
[[nodiscard]] virtual bool execute(CommandSender &sender,
const std::map<std::string, std::string> &args) const noexcept = 0;
[[nodiscard]] virtual bool execute(CommandSender &sender, const std::map<std::string, std::string> &args) const = 0;

/**
* Returns the name of this command
*
* @return Name of this command
*/
[[nodiscard]] virtual std::string getName() const noexcept = 0;
[[nodiscard]] virtual std::string getName() const = 0;

/**
* Gets a brief description of this command
*
* @return Description of this command
*/
[[nodiscard]] virtual std::string getDescription() const noexcept = 0;
[[nodiscard]] virtual std::string getDescription() const
{
return "";
}

/**
* Returns a list of aliases of this command
*
* @return List of aliases
*/
[[nodiscard]] virtual std::vector<std::string> getAliases() const noexcept = 0;
[[nodiscard]] virtual std::vector<std::string> getAliases() const
{
return {};
}

private:
CommandMap &command_map_;
Expand Down
2 changes: 1 addition & 1 deletion include/endstone/command/command_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace endstone {
*/
class CommandExecutor {
public:
virtual ~CommandExecutor() noexcept = default;
virtual ~CommandExecutor() = default;

/**
* Executes the given command, returning its success.
Expand Down
15 changes: 8 additions & 7 deletions include/endstone/command/command_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,34 @@ class Command;
namespace endstone {
class CommandMap {
public:
virtual ~CommandMap() noexcept = default;
virtual ~CommandMap() = default;

/**
* Registers a command. Returns true on success; false if name is already
* taken and fallback had to be used.
*
* @param label the label of the command, without the '/'-prefix.
* @param fallback_prefix a prefix which is prepended to the command with a ':' one or more times to make the command unique
* @param fallback_prefix a prefix which is prepended to the command with a ':' one or more times to make the
* command unique
* @param command the command to register
* @return true if command was registered with the passed in label, false otherwise, which indicates the fallbackPrefix was used one or more times
* @return true if command was registered with the passed in label, false otherwise, which indicates the
* fallbackPrefix was used one or more times
*/
virtual bool registerCommand(std::string label, std::string fallback_prefix,
std::shared_ptr<Command> command) noexcept = 0;
virtual bool registerCommand(std::string label, std::string fallback_prefix, std::shared_ptr<Command> command) = 0;

// TODO: dispatch functions

/**
* Clears all registered commands.
*/
[[maybe_unused]] virtual void clearCommands() noexcept = 0;
[[maybe_unused]] virtual void clearCommands() = 0;

/**
* Gets the command registered to the specified name
*
* @param name Name of the command to retrieve
* @return Command with the specified name or nullptr if a command with that label doesn't exist
*/
[[nodiscard]] virtual Command *getCommand(std::string name) const noexcept = 0;
[[nodiscard]] virtual Command *getCommand(std::string name) const = 0;
};
} // namespace endstone
14 changes: 7 additions & 7 deletions include/endstone/command/command_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@

class Server;

class CommandSender {
class CommandSender {
public:
CommandSender() noexcept = default;
CommandSender() = default;

/**
* Sends this sender a message
*
* @param message Message to be displayed
*/
virtual void sendMessage(const std::string &message) const noexcept = 0;
virtual void sendMessage(const std::string &message) const = 0;

template <typename... Args>
void sendMessage(const fmt::format_string<Args...> format, Args &&...args) const noexcept
void sendMessage(const fmt::format_string<Args...> format, Args &&...args) const
{
sendMessage(fmt::format(format, std::forward<Args>(args)...));
}
Expand All @@ -42,12 +42,12 @@ class CommandSender {
*
* @return Server instance
*/
[[nodiscard]] virtual Server &getServer() const noexcept = 0;
[[nodiscard]] virtual Server &getServer() const = 0;

/**
* Gets the name of this command sender
*
* @return Name of the sender
*/
[[nodiscard]] virtual std::string getName() const noexcept = 0;
};
[[nodiscard]] virtual std::string getName() const = 0;
};
10 changes: 5 additions & 5 deletions include/endstone/command/plugin_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
namespace endstone {
class PluginCommand : public Command {
public:
PluginCommand(CommandMap &command_map, Plugin &owner) noexcept : Command(command_map), owner_(owner) {}
PluginCommand(CommandMap &command_map, Plugin &owner) : Command(command_map), owner_(owner) {}

bool execute(CommandSender &sender, const std::map<std::string, std::string> &args) const noexcept override
bool execute(CommandSender &sender, const std::map<std::string, std::string> &args) const override
{
if (!owner_.isEnabled()) {
sender.sendMessage("Cannot execute command '{}' in plugin {} - plugin is disabled.", getName(),
Expand All @@ -51,7 +51,7 @@ class PluginCommand : public Command {
*
* @param executor New executor to run
*/
void setExecutor(std::shared_ptr<CommandExecutor> executor) noexcept
void setExecutor(std::shared_ptr<CommandExecutor> executor)
{
executor_ = std::move(executor);
}
Expand All @@ -61,7 +61,7 @@ class PluginCommand : public Command {
*
* @return CommandExecutor object linked to this command
*/
[[nodiscard]] CommandExecutor &getExecutor() const noexcept
[[nodiscard]] CommandExecutor &getExecutor() const
{
if (executor_) {
return *executor_;
Expand All @@ -74,7 +74,7 @@ class PluginCommand : public Command {
*
* @return Plugin that owns this command
*/
[[maybe_unused]] [[nodiscard]] Plugin &getPlugin() const noexcept
[[maybe_unused]] [[nodiscard]] Plugin &getPlugin() const
{
return owner_;
}
Expand Down
2 changes: 1 addition & 1 deletion include/endstone/detail/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace endstone::detail::hook {
void install();
const std::error_category &hook_error_category() noexcept;
const std::error_category &hook_error_category();
} // namespace endstone::detail::hook

namespace endstone::detail::hook {
Expand Down
4 changes: 2 additions & 2 deletions include/endstone/detail/plugin/cpp_plugin_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class CppPluginLoader : public PluginLoader {
public:
using PluginLoader::PluginLoader;

[[nodiscard]] std::vector<Plugin *> loadPlugins(const std::string &directory) noexcept override;
[[nodiscard]] std::unique_ptr<Plugin> loadPlugin(const std::string &file) noexcept;
[[nodiscard]] std::vector<Plugin *> loadPlugins(const std::string &directory) override;
[[nodiscard]] std::unique_ptr<Plugin> loadPlugin(const std::string &file);
[[nodiscard]] std::vector<std::string> getPluginFileFilters() const;

private:
Expand Down
2 changes: 1 addition & 1 deletion include/endstone/detail/plugin/python_plugin_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PythonPluginLoader : public PluginLoader {
public:
explicit PythonPluginLoader(Server &server);

[[nodiscard]] std::vector<Plugin *> loadPlugins(const std::string &directory) noexcept override;
[[nodiscard]] std::vector<Plugin *> loadPlugins(const std::string &directory) override;
void enablePlugin(Plugin &plugin) const override;
void disablePlugin(Plugin &plugin) const override;

Expand Down
4 changes: 2 additions & 2 deletions include/endstone/plugin/plugin_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ namespace endstone {

class PluginLoader {
public:
explicit PluginLoader(Server &server) noexcept : server_(server) {}
explicit PluginLoader(Server &server) : server_(server) {}
PluginLoader(const PluginLoader &) = delete;
PluginLoader &operator=(const PluginLoader &) = delete;

virtual ~PluginLoader() = default;
[[nodiscard]] virtual std::vector<Plugin *> loadPlugins(const std::string &directory) noexcept = 0;
[[nodiscard]] virtual std::vector<Plugin *> loadPlugins(const std::string &directory) = 0;

virtual void enablePlugin(Plugin &plugin) const
{
Expand Down
6 changes: 3 additions & 3 deletions src/endstone_core/plugin/cpp_plugin_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace fs = std::filesystem;

namespace endstone::detail {

std::vector<Plugin *> CppPluginLoader::loadPlugins(const std::string &directory) noexcept
std::vector<Plugin *> CppPluginLoader::loadPlugins(const std::string &directory)
{
auto &logger = getServer().getLogger();

Expand Down Expand Up @@ -74,7 +74,7 @@ std::vector<Plugin *> CppPluginLoader::loadPlugins(const std::string &directory)

#ifdef _WIN32

std::unique_ptr<Plugin> CppPluginLoader::loadPlugin(const std::string &file) noexcept
std::unique_ptr<Plugin> CppPluginLoader::loadPlugin(const std::string &file)
{
auto &logger = getServer().getLogger();
auto path = fs::path(file);
Expand Down Expand Up @@ -115,7 +115,7 @@ std::vector<std::string> CppPluginLoader::getPluginFileFilters() const

#elif __linux__

std::unique_ptr<Plugin> CppPluginLoader::loadPlugin(const std::string &file) noexcept
std::unique_ptr<Plugin> CppPluginLoader::loadPlugin(const std::string &file)
{
auto &logger = getServer().getLogger();
auto path = fs::path(file);
Expand Down
8 changes: 4 additions & 4 deletions src/endstone_python/plugin/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PyPlugin : public Plugin {
public:
using Plugin::Plugin;

[[nodiscard]] const PluginDescription &getDescription() const noexcept override
[[nodiscard]] const PluginDescription &getDescription() const override
{
try {
PYBIND11_OVERRIDE_PURE_NAME(const PluginDescription &, Plugin, "_get_description", getDescription);
Expand All @@ -40,7 +40,7 @@ class PyPlugin : public Plugin {
}
}

void onLoad() noexcept override
void onLoad() override
{
try {
PYBIND11_OVERRIDE_NAME(void, Plugin, "on_load", onLoad);
Expand All @@ -51,7 +51,7 @@ class PyPlugin : public Plugin {
}
}

void onEnable() noexcept override
void onEnable() override
{
try {
PYBIND11_OVERRIDE_NAME(void, Plugin, "on_enable", onEnable);
Expand All @@ -62,7 +62,7 @@ class PyPlugin : public Plugin {
}
}

void onDisable() noexcept override
void onDisable() override
{
try {
PYBIND11_OVERRIDE_NAME(void, Plugin, "on_disable", onDisable);
Expand Down
2 changes: 1 addition & 1 deletion src/endstone_python/plugin/plugin_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PyPluginLoader : public PluginLoader {
public:
using PluginLoader::PluginLoader;

std::vector<Plugin *> loadPlugins(const std::string &directory) noexcept override
std::vector<Plugin *> loadPlugins(const std::string &directory) override
{
try {
PYBIND11_OVERRIDE_PURE_NAME(std::vector<Plugin *>, PluginLoader, "load_plugins", loadPlugins,
Expand Down
4 changes: 2 additions & 2 deletions src/endstone_runtime/linux/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ void install()
}
}

const std::error_category &hook_error_category() noexcept
const std::error_category &hook_error_category()
{
static const class HookErrorCategory : public std::error_category {
public:
[[nodiscard]] const char *name() const noexcept override
[[nodiscard]] const char *name() const override
{
return "HookError";
}
Expand Down
2 changes: 1 addition & 1 deletion src/endstone_runtime/plugin/python_plugin_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ PythonPluginLoader::PythonPluginLoader(Server &server) : PluginLoader(server)
}
}

std::vector<Plugin *> PythonPluginLoader::loadPlugins(const std::string &directory) noexcept
std::vector<Plugin *> PythonPluginLoader::loadPlugins(const std::string &directory)
{
auto plugins = pimpl()->loadPlugins(directory);
for (const auto &plugin : plugins) {
Expand Down
4 changes: 2 additions & 2 deletions src/endstone_runtime/windows/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ void install()
}
}

const std::error_category &hook_error_category() noexcept
const std::error_category &hook_error_category()
{
static const class HookErrorCategory : public std::error_category {
public:
[[nodiscard]] const char *name() const noexcept override
[[nodiscard]] const char *name() const override
{
return "HookError";
}
Expand Down

0 comments on commit 65d0671

Please sign in to comment.