1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:28:12 +00:00
serenity/Userland/Libraries/LibWeb/DOM/ExceptionOr.h
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00

90 lines
1.6 KiB
C++

/*
* Copyright (c) 2021, Linus Groh <mail@linusgroh.de>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/NonnullRefPtr.h>
#include <AK/Optional.h>
#include <AK/RefPtr.h>
#include <LibWeb/DOM/DOMException.h>
namespace Web::DOM {
template<typename ValueType>
class ExceptionOr {
public:
ExceptionOr(const ValueType& result)
: m_result(result)
{
}
ExceptionOr(ValueType&& result)
: m_result(move(result))
{
}
ExceptionOr(const NonnullRefPtr<DOMException> exception)
: m_exception(exception)
{
}
ExceptionOr(ExceptionOr&& other) = default;
ExceptionOr(const ExceptionOr& other) = default;
~ExceptionOr() = default;
ValueType& value()
{
return m_result.value();
}
ValueType release_value()
{
return m_result.release_value();
}
const DOMException& exception() const
{
return *m_exception;
}
bool is_exception() const
{
return m_exception;
}
private:
Optional<ValueType> m_result;
RefPtr<DOMException> m_exception;
};
template<>
class ExceptionOr<void> {
public:
ExceptionOr(const NonnullRefPtr<DOMException> exception)
: m_exception(exception)
{
}
ExceptionOr() = default;
ExceptionOr(ExceptionOr&& other) = default;
ExceptionOr(const ExceptionOr& other) = default;
~ExceptionOr() = default;
const DOMException& exception() const
{
return *m_exception;
}
bool is_exception() const
{
return m_exception;
}
private:
RefPtr<DOMException> m_exception;
};
}