mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-17 07:50:04 +00:00
Everywhere: Hoist the Libraries folder to the top-level
This commit is contained in:
parent
950e819ee7
commit
93712b24bf
Notes:
github-actions[bot]
2024-11-10 11:51:52 +00:00
Author: https://github.com/trflynn89
Commit: 93712b24bf
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2256
Reviewed-by: https://github.com/sideshowbarker
4547 changed files with 104 additions and 113 deletions
94
Libraries/LibMedia/DecoderError.h
Normal file
94
Libraries/LibMedia/DecoderError.h
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Gregory Bertilson <zaggy1024@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/ByteString.h>
|
||||
#include <AK/Error.h>
|
||||
#include <AK/Format.h>
|
||||
#include <AK/SourceLocation.h>
|
||||
#include <LibMedia/Forward.h>
|
||||
#include <errno.h>
|
||||
|
||||
namespace Media {
|
||||
|
||||
template<typename T>
|
||||
using DecoderErrorOr = ErrorOr<T, DecoderError>;
|
||||
|
||||
enum class DecoderErrorCategory : u32 {
|
||||
Unknown,
|
||||
IO,
|
||||
NeedsMoreInput,
|
||||
EndOfStream,
|
||||
Memory,
|
||||
// The input is corrupted.
|
||||
Corrupted,
|
||||
// Invalid call.
|
||||
Invalid,
|
||||
// The input uses features that are not yet implemented.
|
||||
NotImplemented,
|
||||
};
|
||||
|
||||
class DecoderError {
|
||||
public:
|
||||
static DecoderError with_description(DecoderErrorCategory category, StringView description)
|
||||
{
|
||||
return DecoderError(category, description);
|
||||
}
|
||||
|
||||
template<typename... Parameters>
|
||||
static DecoderError format(DecoderErrorCategory category, CheckedFormatString<Parameters...>&& format_string, Parameters const&... parameters)
|
||||
{
|
||||
AK::VariadicFormatParams<AK::AllowDebugOnlyFormatters::No, Parameters...> variadic_format_params { parameters... };
|
||||
return DecoderError::with_description(category, ByteString::vformatted(format_string.view(), variadic_format_params));
|
||||
}
|
||||
|
||||
static DecoderError from_source_location(DecoderErrorCategory category, StringView description, SourceLocation location = SourceLocation::current())
|
||||
{
|
||||
return DecoderError::format(category, "[{} @ {}:{}]: {}", location.function_name(), location.filename(), location.line_number(), description);
|
||||
}
|
||||
|
||||
static DecoderError corrupted(StringView description, SourceLocation location = SourceLocation::current())
|
||||
{
|
||||
return DecoderError::from_source_location(DecoderErrorCategory::Corrupted, description, location);
|
||||
}
|
||||
|
||||
static DecoderError not_implemented(SourceLocation location = SourceLocation::current())
|
||||
{
|
||||
return DecoderError::format(DecoderErrorCategory::NotImplemented, "{} is not implemented", location.function_name());
|
||||
}
|
||||
|
||||
DecoderErrorCategory category() const { return m_category; }
|
||||
StringView description() const { return m_description; }
|
||||
StringView string_literal() const { return m_description; }
|
||||
|
||||
private:
|
||||
DecoderError(DecoderErrorCategory category, ByteString description)
|
||||
: m_category(category)
|
||||
, m_description(move(description))
|
||||
{
|
||||
}
|
||||
|
||||
DecoderErrorCategory m_category { DecoderErrorCategory::Unknown };
|
||||
ByteString m_description;
|
||||
};
|
||||
|
||||
#define DECODER_TRY(category, expression) \
|
||||
({ \
|
||||
auto&& _result = ((expression)); \
|
||||
if (_result.is_error()) [[unlikely]] { \
|
||||
auto _error_string = _result.release_error().string_literal(); \
|
||||
return DecoderError::from_source_location( \
|
||||
((category)), _error_string, SourceLocation::current()); \
|
||||
} \
|
||||
static_assert(!::AK::Detail::IsLvalueReference<decltype(_result.release_value())>, \
|
||||
"Do not return a reference from a fallible expression"); \
|
||||
_result.release_value(); \
|
||||
})
|
||||
|
||||
#define DECODER_TRY_ALLOC(expression) DECODER_TRY(DecoderErrorCategory::Memory, expression)
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue