Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
FileSystemIteratorError.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "../Common/Result.h"
5
6namespace SC
7{
10
12enum class FileSystemIteratorError : uint32_t
13{
14 NotInitialized = 1,
15 InvalidRecursionState,
16 UnsupportedPathEncoding,
17 PathTooLong,
18 RecursionLimitExceeded,
19 PathResolutionFailed,
20 OpenDirectoryFailed,
21 DirectoryEnumerationFailed,
22};
23
25enum class FileSystemIteratorErrorDetail : uint16_t
26{
27 None = 0,
28 WindowsResolveLogicalPath,
29 BuildPath,
30 PosixOpen,
31 PosixFdOpenDir,
32 WindowsFindFirstFile,
33 PushRecursionState,
34 PosixReadDir,
35 WindowsFindNextFile,
36};
37
39static constexpr ResultCategory FileSystemIteratorResultCategory = ResultCategory(4);
40
47struct [[nodiscard]] ResultFileSystemIterator
48{
49 Result result;
50
51 uint32_t nativeError = 0;
52 uint16_t depth = 0;
53 FileSystemIteratorErrorDetail detail = FileSystemIteratorErrorDetail::None;
54
55 explicit constexpr ResultFileSystemIterator(bool valid = true) : result(valid) {}
57 FileSystemIteratorErrorDetail detail = FileSystemIteratorErrorDetail::None,
58 uint32_t nativeError = 0, uint32_t depth = 0)
59 : result(Result::Error(FileSystemIteratorResultCategory, error)), nativeError(nativeError),
60 depth(static_cast<uint16_t>(depth)), detail(detail)
61 {}
62 constexpr ResultFileSystemIterator(Result result) : result(result) {}
63
64 template <typename ResultLike>
65 constexpr ResultFileSystemIterator(const ResultLike& other) : result(other.toResult())
66 {}
67
68 explicit constexpr operator bool() const { return static_cast<bool>(result); }
69
70 constexpr operator Result() const { return result; }
71
72 constexpr Result toResult() const { return result; }
73 constexpr bool isError(FileSystemIteratorError error) const
74 {
75 return result.isError(FileSystemIteratorResultCategory, error);
76 }
77};
78
80} // namespace SC
FileSystemIteratorError
Stable error codes returned by the FileSystemIterator library.
Definition FileSystemIteratorError.h:13
FileSystemIteratorErrorDetail
Stable detail identifying the backend stage of a FileSystemIterator failure.
Definition FileSystemIteratorError.h:26
FileSystemIterator result retaining optional native, backend-stage, and directory-depth details.
Definition FileSystemIteratorError.h:48