Skip to content

Commit

Permalink
Tweak error code domains
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Oct 15, 2023
1 parent 4759c75 commit 135c5e0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
19 changes: 8 additions & 11 deletions modules/core/inc/tactile/core/io/compression/compression_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#pragma once

#include <utility> // to_underlying

#include "tactile/core/api.hpp"
#include "tactile/core/debug/error_code.hpp"
#include "tactile/core/functional/expected.hpp"
Expand All @@ -22,18 +20,20 @@ class CompressionErrorDomain final : public IErrorDomain {
kInvalidMode, ///< An invalid compression mode was used.
};

constexpr CompressionErrorDomain() noexcept = default;

constexpr ~CompressionErrorDomain() noexcept override = default;

TACTILE_DEFAULT_COPY(CompressionErrorDomain);
TACTILE_DEFAULT_MOVE(CompressionErrorDomain);

[[nodiscard]]
TACTILE_CORE_API auto get_message(uint32 error_id) const noexcept
-> StringView override;
};

using CompressionError = CompressionErrorDomain::Error;

/**
* \brief The global compression error domain.
*/
inline constexpr CompressionErrorDomain kCompressionErrorDomain;

/**
* \brief Convenience function for creating a compression error code.
*
Expand All @@ -42,9 +42,6 @@ inline constexpr CompressionErrorDomain kCompressionErrorDomain;
* \return an error code.
*/
[[nodiscard]]
inline auto error(const CompressionError error) noexcept -> Unexpected<ErrorCode>
{
return unexpected(ErrorCode {&kCompressionErrorDomain, std::to_underlying(error)});
}
TACTILE_CORE_API auto error(CompressionError error) noexcept -> Unexpected<ErrorCode>;

} // namespace tactile
19 changes: 8 additions & 11 deletions modules/core/inc/tactile/core/io/save/save_format_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#pragma once

#include <utility> // to_underlying

#include "tactile/core/api.hpp"
#include "tactile/core/debug/error_code.hpp"
#include "tactile/core/functional/expected.hpp"
Expand Down Expand Up @@ -31,16 +29,18 @@ class SaveFormatErrorDomain final : public IErrorDomain {
kBadCompressionMode, ///< An invalid compression mode was detected.
};

constexpr SaveFormatErrorDomain() noexcept = default;

constexpr ~SaveFormatErrorDomain() noexcept override = default;

TACTILE_DEFAULT_COPY(SaveFormatErrorDomain);
TACTILE_DEFAULT_MOVE(SaveFormatErrorDomain);

[[nodiscard]]
TACTILE_CORE_API auto get_message(uint32 error_id) const noexcept
-> StringView override;
};

/**
* \brief The global save format error domain.
*/
inline constexpr SaveFormatErrorDomain kSaveFormatErrorDomain;

using SaveFormatError = SaveFormatErrorDomain::Error;

/**
Expand All @@ -51,9 +51,6 @@ using SaveFormatError = SaveFormatErrorDomain::Error;
* \return an error code.
*/
[[nodiscard]]
inline auto error(const SaveFormatError error) noexcept -> Unexpected<ErrorCode>
{
return unexpected(ErrorCode {&kSaveFormatErrorDomain, std::to_underlying(error)});
}
TACTILE_CORE_API auto error(SaveFormatError error) noexcept -> Unexpected<ErrorCode>;

} // namespace tactile
12 changes: 12 additions & 0 deletions modules/core/src/tactile/core/io/compression/compression_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

#include "tactile/core/io/compression/compression_error.hpp"

#include <utility> // to_underlying

namespace tactile {
namespace {

inline constexpr CompressionErrorDomain kCompressionErrorDomain;

} // namespace

auto CompressionErrorDomain::get_message(const uint32 error_id) const noexcept
-> StringView
Expand All @@ -16,4 +23,9 @@ auto CompressionErrorDomain::get_message(const uint32 error_id) const noexcept
return "";
}

auto error(const CompressionError error) noexcept -> Unexpected<ErrorCode>
{
return unexpected(ErrorCode {&kCompressionErrorDomain, std::to_underlying(error)});
}

} // namespace tactile
12 changes: 12 additions & 0 deletions modules/core/src/tactile/core/io/save/save_format_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

#include "tactile/core/io/save/save_format_error.hpp"

#include <utility> // to_underlying

namespace tactile {
namespace {

inline constexpr SaveFormatErrorDomain kSaveFormatErrorDomain;

} // namespace

auto SaveFormatErrorDomain::get_message(const uint32 error_id) const noexcept
-> StringView
Expand Down Expand Up @@ -40,4 +47,9 @@ auto SaveFormatErrorDomain::get_message(const uint32 error_id) const noexcept
return "";
}

auto error(const SaveFormatError error) noexcept -> Unexpected<ErrorCode>
{
return unexpected(ErrorCode {&kSaveFormatErrorDomain, std::to_underlying(error)});
}

} // namespace tactile

0 comments on commit 135c5e0

Please sign in to comment.