diff --git a/src/Add-ons/AddonManager.cxx b/src/Add-ons/AddonManager.cxx index f6d22602a..2ca96d4d1 100644 --- a/src/Add-ons/AddonManager.cxx +++ b/src/Add-ons/AddonManager.cxx @@ -41,6 +41,7 @@ #include "Addon.hxx" #include "AddonManager.hxx" #include "AddonVersion.hxx" +#include "exceptions.hxx" namespace strutils = simgear::strutils; @@ -54,24 +55,6 @@ namespace flightgear static unique_ptr staticInstance; -namespace addon_errors -{ -// *************************************************************************** -// * Base class for custom exceptions * -// *************************************************************************** - -// Prepending a prefix such as "Add-on error: " would be redundant given the -// messages used below. -error::error(const string& message, const string& origin) - : sg_exception(message, origin) -{ } - -error::error(const char* message, const char* origin) - : error(string(message), string(origin)) -{ } - -} // of namespace addon_errors - // *************************************************************************** // * AddonManager * // *************************************************************************** diff --git a/src/Add-ons/AddonManager.hxx b/src/Add-ons/AddonManager.hxx index 36fecaf68..7c9124b38 100644 --- a/src/Add-ons/AddonManager.hxx +++ b/src/Add-ons/AddonManager.hxx @@ -35,37 +35,6 @@ namespace flightgear { -namespace addon_errors -{ -// Custom exception classes -class error : public sg_exception -{ -public: - explicit error(const std::string& message, - const std::string& origin = std::string()); - explicit error(const char* message, const char* origin = nullptr); -}; - -class error_loading_config_file : public error -{ using error::error; /* inherit all constructors */ }; - -class no_metadata_file_found : public error -{ using error::error; }; - -class error_loading_metadata_file : public error -{ using error::error; }; - -class duplicate_registration_attempt : public error -{ using error::error; }; - -class fg_version_too_old : public error -{ using error::error; }; - -class fg_version_too_recent : public error -{ using error::error; }; - -} // of namespace addon_errors - class AddonManager { public: diff --git a/src/Add-ons/CMakeLists.txt b/src/Add-ons/CMakeLists.txt index 6c2ea9396..d0f29cbd4 100644 --- a/src/Add-ons/CMakeLists.txt +++ b/src/Add-ons/CMakeLists.txt @@ -1,7 +1,17 @@ include(FlightGearComponent) -set(SOURCES Addon.cxx AddonManager.cxx AddonVersion.cxx) -set(HEADERS addon_fwd.hxx Addon.hxx AddonManager.hxx AddonVersion.hxx) +set(SOURCES Addon.cxx + AddonManager.cxx + AddonVersion.cxx + exceptions.cxx + ) + +set(HEADERS addon_fwd.hxx + Addon.hxx + AddonManager.hxx + AddonVersion.hxx + exceptions.hxx + ) flightgear_component(AddonManagement "${SOURCES}" "${HEADERS}") diff --git a/src/Add-ons/exceptions.cxx b/src/Add-ons/exceptions.cxx new file mode 100644 index 000000000..b678efa1f --- /dev/null +++ b/src/Add-ons/exceptions.cxx @@ -0,0 +1,49 @@ +// -*- coding: utf-8 -*- +// +// exceptions.cxx --- Exception classes for the FlightGear add-on infrastructure +// Copyright (C) 2017 Florent Rougon +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +#include + +#include + +#include "exceptions.hxx" + +using std::string; + +namespace flightgear +{ + +namespace addon_errors +{ +// *************************************************************************** +// * Base class for custom exceptions * +// *************************************************************************** + +// Prepending a prefix such as "Add-on error: " would be redundant given the +// messages used in, e.g., the Addon class code. +error::error(const string& message, const string& origin) + : sg_exception(message, origin) +{ } + +error::error(const char* message, const char* origin) + : error(string(message), string(origin)) +{ } + +} // of namespace addon_errors + +} // of namespace flightgear diff --git a/src/Add-ons/exceptions.hxx b/src/Add-ons/exceptions.hxx new file mode 100644 index 000000000..8d04aa7dd --- /dev/null +++ b/src/Add-ons/exceptions.hxx @@ -0,0 +1,63 @@ +// -*- coding: utf-8 -*- +// +// exceptions.hxx --- Exception classes for the FlightGear add-on infrastructure +// Copyright (C) 2017 Florent Rougon +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +#ifndef FG_ADDON_EXCEPTIONS_HXX +#define FG_ADDON_EXCEPTIONS_HXX + +#include + +#include + +namespace flightgear +{ + +namespace addon_errors +{ + +class error : public sg_exception +{ +public: + explicit error(const std::string& message, + const std::string& origin = std::string()); + explicit error(const char* message, const char* origin = nullptr); +}; + +class error_loading_config_file : public error +{ using error::error; /* inherit all constructors */ }; + +class no_metadata_file_found : public error +{ using error::error; }; + +class error_loading_metadata_file : public error +{ using error::error; }; + +class duplicate_registration_attempt : public error +{ using error::error; }; + +class fg_version_too_old : public error +{ using error::error; }; + +class fg_version_too_recent : public error +{ using error::error; }; + +} // of namespace addon_errors + +} // of namespace flightgear + +#endif // of FG_ADDON_EXCEPTIONS_HXX diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2a7c337c6..33afc4398 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,6 +10,7 @@ set(sources Add-ons/Addon.cxx Add-ons/AddonManager.cxx Add-ons/AddonVersion.cxx + Add-ons/exceptions.cxx Aircraft/controls.cxx Aircraft/FlightHistory.cxx Aircraft/flightrecorder.cxx