Skip to content

Commit

Permalink
Use new error code enum
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Oct 8, 2024
1 parent 55e01e6 commit 411c99c
Show file tree
Hide file tree
Showing 144 changed files with 732 additions and 1,280 deletions.
3 changes: 0 additions & 3 deletions source/base/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ add_library(tactile::base ALIAS tactile-base)

target_sources(tactile-base
INTERFACE FILE_SET "HEADERS" BASE_DIRS "inc" FILES
"inc/tactile/base/container/result.hpp"
"inc/tactile/base/container/string_map.hpp"
"inc/tactile/base/document/component_view.hpp"
"inc/tactile/base/document/document.hpp"
Expand All @@ -22,8 +21,6 @@ target_sources(tactile-base
"inc/tactile/base/io/save/ir.hpp"
"inc/tactile/base/io/save/save_format.hpp"
"inc/tactile/base/io/save/save_format_id.hpp"
"inc/tactile/base/io/save/save_format_parse_error.hpp"
"inc/tactile/base/io/save/save_format_parse_result.hpp"
"inc/tactile/base/io/byte_stream.hpp"
"inc/tactile/base/io/color_parser.hpp"
"inc/tactile/base/io/file_io.hpp"
Expand Down
16 changes: 0 additions & 16 deletions source/base/lib/inc/tactile/base/container/result.hpp

This file was deleted.

6 changes: 3 additions & 3 deletions source/base/lib/inc/tactile/base/debug/error_code.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ enum class ErrorCode : int
/** An invalid image was detected. */
kBadImage,

/** An invalid save file was detected. */
kBadSaveFile,
/** A file could not be parsed. */
kParseError,

/** A compression operation failed. */
kCouldNotCompress,
Expand All @@ -77,7 +77,7 @@ constexpr auto to_string(const ErrorCode errc) noexcept -> std::string_view
case ErrorCode::kBadFileStream: return "file stream error";
case ErrorCode::kBadFileCopy: return "file copy error";
case ErrorCode::kBadImage: return "invalid image";
case ErrorCode::kBadSaveFile: return "invalid save file";
case ErrorCode::kParseError: return "parse error";
case ErrorCode::kCouldNotCompress: return "could not compress";
case ErrorCode::kCouldNotDecompress: return "could not decompress";
}
Expand Down
15 changes: 7 additions & 8 deletions source/base/lib/inc/tactile/base/document/component_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

#pragma once

#include <cstddef> // size_t
#include <expected> // expected
#include <string> // string
#include <string_view> // string_view
#include <system_error> // error_code
#include <utility> // pair
#include <cstddef> // size_t
#include <expected> // expected
#include <string> // string
#include <string_view> // string_view
#include <utility> // pair

#include "tactile/base/debug/error_code.hpp"
#include "tactile/base/prelude.hpp"

namespace tactile {
Expand All @@ -33,8 +33,7 @@ class IComponentView
* Nothing if successful; an error code otherwise.
*/
[[nodiscard]]
virtual auto accept(IDocumentVisitor& visitor) const
-> std::expected<void, std::error_code> = 0;
virtual auto accept(IDocumentVisitor& visitor) const -> std::expected<void, ErrorCode> = 0;

/**
* Returns the name of the component.
Expand Down
9 changes: 4 additions & 5 deletions source/base/lib/inc/tactile/base/document/document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#pragma once

#include <expected> // expected
#include <filesystem> // path
#include <system_error> // error_code
#include <expected> // expected
#include <filesystem> // path

#include "tactile/base/debug/error_code.hpp"
#include "tactile/base/io/save/save_format_id.hpp"
#include "tactile/base/numeric/extent_2d.hpp"
#include "tactile/base/numeric/vec.hpp"
Expand Down Expand Up @@ -34,8 +34,7 @@ class IDocument
* Nothing if successful; an error code otherwise.
*/
[[nodiscard]]
virtual auto accept(IDocumentVisitor& visitor) const
-> std::expected<void, std::error_code> = 0;
virtual auto accept(IDocumentVisitor& visitor) const -> std::expected<void, ErrorCode> = 0;

/**
* Updates the state of the document.
Expand Down
17 changes: 8 additions & 9 deletions source/base/lib/inc/tactile/base/document/document_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#pragma once

#include <expected> // expected
#include <system_error> // error_code
#include <expected> // expected

#include "tactile/base/debug/error_code.hpp"
#include "tactile/base/prelude.hpp"

namespace tactile {
Expand Down Expand Up @@ -43,8 +43,7 @@ class IDocumentVisitor
* Nothing if successful; an error code otherwise.
*/
[[nodiscard]]
virtual auto visit(const IComponentView& component)
-> std::expected<void, std::error_code> = 0;
virtual auto visit(const IComponentView& component) -> std::expected<void, ErrorCode> = 0;

/**
* Visits a map.
Expand All @@ -55,7 +54,7 @@ class IDocumentVisitor
* Nothing if successful; an error code otherwise.
*/
[[nodiscard]]
virtual auto visit(const IMapView& map) -> std::expected<void, std::error_code> = 0;
virtual auto visit(const IMapView& map) -> std::expected<void, ErrorCode> = 0;

/**
* Visits a layer.
Expand All @@ -66,7 +65,7 @@ class IDocumentVisitor
* Nothing if successful; an error code otherwise.
*/
[[nodiscard]]
virtual auto visit(const ILayerView& layer) -> std::expected<void, std::error_code> = 0;
virtual auto visit(const ILayerView& layer) -> std::expected<void, ErrorCode> = 0;

/**
* Visits an object.
Expand All @@ -77,7 +76,7 @@ class IDocumentVisitor
* Nothing if successful; an error code otherwise.
*/
[[nodiscard]]
virtual auto visit(const IObjectView& object) -> std::expected<void, std::error_code> = 0;
virtual auto visit(const IObjectView& object) -> std::expected<void, ErrorCode> = 0;

/**
* Visits a tileset.
Expand All @@ -88,7 +87,7 @@ class IDocumentVisitor
* Nothing if successful; an error code otherwise.
*/
[[nodiscard]]
virtual auto visit(const ITilesetView& tileset) -> std::expected<void, std::error_code> = 0;
virtual auto visit(const ITilesetView& tileset) -> std::expected<void, ErrorCode> = 0;

/**
* Visits a tile in a tileset.
Expand All @@ -99,7 +98,7 @@ class IDocumentVisitor
* Nothing if successful; an error code otherwise.
*/
[[nodiscard]]
virtual auto visit(const ITileView& tile) -> std::expected<void, std::error_code> = 0;
virtual auto visit(const ITileView& tile) -> std::expected<void, ErrorCode> = 0;
};

} // namespace tactile
9 changes: 4 additions & 5 deletions source/base/lib/inc/tactile/base/document/layer_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#pragma once

#include <expected> // expected
#include <optional> // optional
#include <system_error> // error_code
#include <expected> // expected
#include <optional> // optional

#include "tactile/base/debug/error_code.hpp"
#include "tactile/base/id.hpp"
#include "tactile/base/io/byte_stream.hpp"
#include "tactile/base/io/compress/compression_format.hpp"
Expand Down Expand Up @@ -37,8 +37,7 @@ class ILayerView
* Nothing if successful; an error code otherwise.
*/
[[nodiscard]]
virtual auto accept(IDocumentVisitor& visitor) const
-> std::expected<void, std::error_code> = 0;
virtual auto accept(IDocumentVisitor& visitor) const -> std::expected<void, ErrorCode> = 0;

virtual void write_tile_bytes(ByteStream& byte_stream) const = 0;

Expand Down
13 changes: 6 additions & 7 deletions source/base/lib/inc/tactile/base/document/map_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#pragma once

#include <cstddef> // size_t
#include <expected> // expected
#include <filesystem> // path
#include <optional> // optional
#include <system_error> // error_code
#include <cstddef> // size_t
#include <expected> // expected
#include <filesystem> // path
#include <optional> // optional

#include "tactile/base/debug/error_code.hpp"
#include "tactile/base/id.hpp"
#include "tactile/base/io/compress/compression_format.hpp"
#include "tactile/base/layer/tile_encoding.hpp"
Expand Down Expand Up @@ -36,8 +36,7 @@ class IMapView
* \return
* Nothing if successful; an error code otherwise.
*/
virtual auto accept(IDocumentVisitor& visitor) const
-> std::expected<void, std::error_code> = 0;
virtual auto accept(IDocumentVisitor& visitor) const -> std::expected<void, ErrorCode> = 0;

/**
* Returns the file path of the associated save file, if any.
Expand Down
9 changes: 4 additions & 5 deletions source/base/lib/inc/tactile/base/document/object_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#pragma once

#include <expected> // expected
#include <string_view> // string_view
#include <system_error> // error_code
#include <expected> // expected
#include <string_view> // string_view

#include "tactile/base/debug/error_code.hpp"
#include "tactile/base/id.hpp"
#include "tactile/base/layer/object_type.hpp"
#include "tactile/base/numeric/vec.hpp"
Expand Down Expand Up @@ -35,8 +35,7 @@ class IObjectView
* Nothing if successful; an error code otherwise.
*/
[[nodiscard]]
virtual auto accept(IDocumentVisitor& visitor) const
-> std::expected<void, std::error_code> = 0;
virtual auto accept(IDocumentVisitor& visitor) const -> std::expected<void, ErrorCode> = 0;

/**
* Returns a view of the parent object layer, if any.
Expand Down
9 changes: 4 additions & 5 deletions source/base/lib/inc/tactile/base/document/tile_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#pragma once

#include <expected> // expected
#include <system_error> // error_code
#include <utility> // pair
#include <expected> // expected
#include <utility> // pair

#include "tactile/base/debug/error_code.hpp"
#include "tactile/base/id.hpp"
#include "tactile/base/prelude.hpp"
#include "tactile/base/util/chrono.hpp"
Expand Down Expand Up @@ -33,8 +33,7 @@ class ITileView
* Nothing if successful; an error code otherwise.
*/
[[nodiscard]]
virtual auto accept(IDocumentVisitor& visitor) const
-> std::expected<void, std::error_code> = 0;
virtual auto accept(IDocumentVisitor& visitor) const -> std::expected<void, ErrorCode> = 0;

/**
* Returns the tileset that hosts the tile.
Expand Down
11 changes: 5 additions & 6 deletions source/base/lib/inc/tactile/base/document/tileset_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

#pragma once

#include <expected> // expected
#include <filesystem> // path
#include <string> // string
#include <system_error> // error_code
#include <expected> // expected
#include <filesystem> // path
#include <string> // string

#include "tactile/base/debug/error_code.hpp"
#include "tactile/base/id.hpp"
#include "tactile/base/numeric/vec.hpp"
#include "tactile/base/prelude.hpp"
Expand Down Expand Up @@ -34,8 +34,7 @@ class ITilesetView
* Nothing if successful; an error code otherwise.
*/
[[nodiscard]]
virtual auto accept(IDocumentVisitor& visitor) const
-> std::expected<void, std::error_code> = 0;
virtual auto accept(IDocumentVisitor& visitor) const -> std::expected<void, ErrorCode> = 0;

/**
* Returns the first global tile identifier associated with the tileset.
Expand Down
9 changes: 4 additions & 5 deletions source/base/lib/inc/tactile/base/io/compress/compressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#pragma once

#include <expected> // expected
#include <system_error> // error_code
#include <expected> // expected

#include "tactile/base/debug/error_code.hpp"
#include "tactile/base/io/byte_stream.hpp"
#include "tactile/base/prelude.hpp"

Expand All @@ -27,8 +27,7 @@ class ICompressor
* A compressed byte stream if successful; an error code otherwise.
*/
[[nodiscard]]
virtual auto compress(ByteSpan input_data) const
-> std::expected<ByteStream, std::error_code> = 0;
virtual auto compress(ByteSpan input_data) const -> std::expected<ByteStream, ErrorCode> = 0;

/**
* Attempts to decompress a compressed byte stream.
Expand All @@ -40,7 +39,7 @@ class ICompressor
*/
[[nodiscard]]
virtual auto decompress(ByteSpan input_data) const
-> std::expected<ByteStream, std::error_code> = 0;
-> std::expected<ByteStream, ErrorCode> = 0;
};

} // namespace tactile
13 changes: 6 additions & 7 deletions source/base/lib/inc/tactile/base/io/int_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

#pragma once

#include <charconv> // from_chars
#include <optional> // optional
#include <string> // string
#include <string_view> // string_view
#include <system_error> // errc
#include <charconv> // from_chars
#include <optional> // optional
#include <string> // string
#include <string_view> // string_view

#include "tactile/base/prelude.hpp"

Expand All @@ -24,8 +23,8 @@ namespace tactile {
* An integer if successful; an empty optional otherwise.
*/
template <std::integral T>
[[nodiscard]] constexpr auto parse(std::string_view str,
const int base = 10) noexcept -> std::optional<T>
[[nodiscard]] constexpr auto parse(std::string_view str, const int base = 10) noexcept
-> std::optional<T>
{
const auto* const begin = str.data();
const auto* const end = begin + str.size();
Expand Down
6 changes: 3 additions & 3 deletions source/base/lib/inc/tactile/base/io/save/save_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <expected> // expected
#include <filesystem> // path
#include <string_view> // string_view
#include <system_error> // error_code
#include <unordered_map> // unordered_map

#include "tactile/base/debug/error_code.hpp"
#include "tactile/base/io/save/ir.hpp"
#include "tactile/base/meta/attribute.hpp"
#include "tactile/base/prelude.hpp"
Expand Down Expand Up @@ -79,7 +79,7 @@ class ISaveFormat
[[nodiscard]]
virtual auto load_map(const std::filesystem::path& map_path,
const SaveFormatReadOptions& options) const
-> std::expected<ir::Map, std::error_code> = 0;
-> std::expected<ir::Map, ErrorCode> = 0;

/**
* Attempts to save a map.
Expand All @@ -92,7 +92,7 @@ class ISaveFormat
*/
[[nodiscard]]
virtual auto save_map(const IMapView& map, const SaveFormatWriteOptions& options) const
-> std::expected<void, std::error_code> = 0;
-> std::expected<void, ErrorCode> = 0;
};

} // namespace tactile
Loading

0 comments on commit 411c99c

Please sign in to comment.