diff --git a/container/src/root/common/type.hh b/container/src/root/common/type.hh new file mode 100644 index 0000000..a9be988 --- /dev/null +++ b/container/src/root/common/type.hh @@ -0,0 +1,130 @@ +// docker-finance | modern accounting for the power-user +// +// Copyright (C) 2021-2025 Aaron Fiore (Founder, Evergreen Crypto LLC) +// +// 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 3 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, see . + +//! \file +//! \author Aaron Fiore (Founder, Evergreen Crypto LLC) +//! \note File intended to be loaded into ROOT.cern framework / Cling interpreter +//! \since docker-finance 1.1.0 + +#ifndef CONTAINER_SRC_ROOT_COMMON_TYPE_HH_ +#define CONTAINER_SRC_ROOT_COMMON_TYPE_HH_ + +#include +#include + +//! \brief Conditional throw handler +//! \ingroup cpp_type_exceptions +#define THROW_IF(condition, exception, message) \ + if (condition) \ + THROW(exception, message); + +//! \brief Throw handler +//! \ingroup cpp_type_exceptions +#define THROW(exception, message) \ + THROW_IMPL(exception, \ + \n\tFILE = __FILE__ \ + \n\tLINE = __LINE__ \ + \n\tWHAT = message); + +//! \brief Throw handler implementation +//! \warning Should not be called directly, use THROW handlers +//! \ingroup cpp_type_exceptions +#define THROW_IMPL(exception, message) \ + throw exception(THROW_IMPL_EXPAND(message)); + +//! \brief Throw handler implementation (message) +//! \warning Should not be called directly, use THROW handlers +//! \ingroup cpp_type_exceptions +#define THROW_IMPL_EXPAND(message) #message + +//! \namespace dfi +//! \since docker-finance 1.0.0 +namespace dfi +{ +//! \namespace dfi::common +//! \brief Shared common functionality +//! \since docker-finance 1.1.0 +namespace common +{ +//! \namespace dfi::common::type +//! \brief docker-finance defined common types +//! \since docker-finance 1.1.0 +namespace type +{ +//! \brief Base exception class +//! \ingroup cpp_type_exceptions +class Exception : virtual public std::exception +{ + public: + //! \brief Exception type + enum struct kType : uint8_t + { + RuntimeError, + InvalidArgument, + }; + + //! \brief Construct by type with given message + Exception(const kType type, const std::string_view what) + : m_type(type), m_what(what) + { + } + virtual ~Exception() = default; + + Exception(const Exception&) = default; + Exception& operator=(const Exception&) = default; + + Exception(Exception&&) = default; + Exception& operator=(Exception&&) = default; + + public: + //! \return Exeption type + kType type() const noexcept { return m_type; } + + //! \return Exception message + const char* what() const noexcept { return m_what.data(); } + + private: + kType m_type; + std::string_view m_what; +}; + +//! \brief Exception class for runtime errors +//! \ingroup cpp_type_exceptions +struct RuntimeError final : public Exception +{ + explicit RuntimeError(const std::string_view what = {}) + : Exception(Exception::kType::RuntimeError, what) + { + } +}; + +//! \brief Exception class for invalid arguments (logic error) +//! \ingroup cpp_type_exceptions +struct InvalidArgument final : public Exception +{ + explicit InvalidArgument(const std::string_view what = {}) + : Exception(Exception::kType::InvalidArgument, what) + { + } +}; +} // namespace type +} // namespace common +} // namespace dfi + +#endif // CONTAINER_SRC_ROOT_COMMON_TYPE_HH_ + +// # vim: sw=2 sts=2 si ai et diff --git a/container/src/root/src/internal/type.hh b/container/src/root/src/internal/type.hh index abb38d6..7238f34 100644 --- a/container/src/root/src/internal/type.hh +++ b/container/src/root/src/internal/type.hh @@ -30,30 +30,7 @@ #include #include -//! \brief Conditional throw handler -//! \ingroup cpp_type_exceptions -#define THROW_IF(condition, exception, message) \ - if (condition) \ - THROW(exception, message); - -//! \brief Throw handler -//! \ingroup cpp_type_exceptions -#define THROW(exception, message) \ - THROW_IMPL(exception, \ - \n\tFILE = __FILE__ \ - \n\tLINE = __LINE__ \ - \n\tWHAT = message); - -//! \brief Throw handler implementation -//! \warning Should not be called directly, use THROW handlers -//! \ingroup cpp_type_exceptions -#define THROW_IMPL(exception, message) \ - throw exception(THROW_IMPL_EXPAND(message)); - -//! \brief Throw handler implementation (message) -//! \warning Should not be called directly, use THROW handlers -//! \ingroup cpp_type_exceptions -#define THROW_IMPL_EXPAND(message) #message +#include "../../common/type.hh" //! \namespace dfi //! \since docker-finance 1.0.0 @@ -70,62 +47,20 @@ namespace internal //! \todo *_v for all the booleans namespace type { -//! \brief Base exception class -//! \ingroup cpp_type_exceptions -class Exception : virtual public std::exception -{ - public: - //! \brief Exception type - enum struct kType : uint8_t - { - RuntimeError, - InvalidArgument, - }; +//! \deprecated This will be removed in the v2 API; use `dfi::common::type` namespace instead +//! \todo Remove in 2.0.0 +//! \since docker-finance 1.1.0 +using Exception = ::dfi::common::type::Exception; - //! \brief Construct by type with given message - Exception(const kType type, const std::string_view what) - : m_type(type), m_what(what) - { - } - virtual ~Exception() = default; +//! \deprecated This will be removed in the v2 API; use `dfi::common::type` namespace instead +//! \todo Remove in 2.0.0 +//! \since docker-finance 1.1.0 +using RuntimeError = ::dfi::common::type::RuntimeError; - Exception(const Exception&) = default; - Exception& operator=(const Exception&) = default; - - Exception(Exception&&) = default; - Exception& operator=(Exception&&) = default; - - public: - //! \return Exeption type - kType type() const noexcept { return m_type; } - - //! \return Exception message - const char* what() const noexcept { return m_what.data(); } - - private: - kType m_type; - std::string_view m_what; -}; - -//! \brief Exception class for runtime errors -//! \ingroup cpp_type_exceptions -struct RuntimeError final : public Exception -{ - explicit RuntimeError(const std::string_view what = {}) - : Exception(Exception::kType::RuntimeError, what) - { - } -}; - -//! \brief Exception class for invalid arguments (logic error) -//! \ingroup cpp_type_exceptions -struct InvalidArgument final : public Exception -{ - explicit InvalidArgument(const std::string_view what = {}) - : Exception(Exception::kType::InvalidArgument, what) - { - } -}; +//! \deprecated This will be removed in the v2 API; use `dfi::common::type` namespace instead +//! \todo Remove in 2.0.0 +//! \since docker-finance 1.1.0 +using InvalidArgument = ::dfi::common::type::InvalidArgument; //! \ingroup cpp_type_traits template