mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
Add clang-format file
Also run it across the whole tree to get everything using the One True Style. We don't yet run this in an automated fashion as it's a little slow, but there is a snippet to do so in makeall.sh.
This commit is contained in:
parent
c11351ac50
commit
0dc9af5f7e
286 changed files with 3244 additions and 2424 deletions
|
@ -3,20 +3,31 @@
|
|||
#include <AK/Assertions.h>
|
||||
#include <LibC/errno_numbers.h>
|
||||
|
||||
enum KSuccessTag { KSuccess };
|
||||
enum KSuccessTag
|
||||
{
|
||||
KSuccess
|
||||
};
|
||||
|
||||
class KResult {
|
||||
public:
|
||||
explicit KResult(int negative_e) : m_error(negative_e) { ASSERT(negative_e <= 0); }
|
||||
KResult(KSuccessTag) : m_error(0) { }
|
||||
explicit KResult(int negative_e)
|
||||
: m_error(negative_e)
|
||||
{
|
||||
ASSERT(negative_e <= 0);
|
||||
}
|
||||
KResult(KSuccessTag)
|
||||
: m_error(0)
|
||||
{
|
||||
}
|
||||
operator int() const { return m_error; }
|
||||
|
||||
bool is_success() const { return m_error == ESUCCESS; }
|
||||
bool is_error() const { return !is_success(); }
|
||||
|
||||
private:
|
||||
template<typename T> friend class KResultOr;
|
||||
KResult() { }
|
||||
template<typename T>
|
||||
friend class KResultOr;
|
||||
KResult() {}
|
||||
|
||||
int m_error { 0 };
|
||||
};
|
||||
|
@ -27,7 +38,8 @@ public:
|
|||
KResultOr(KResult error)
|
||||
: m_error(error)
|
||||
, m_is_error(true)
|
||||
{ }
|
||||
{
|
||||
}
|
||||
|
||||
KResultOr(T&& value)
|
||||
{
|
||||
|
@ -54,9 +66,21 @@ public:
|
|||
}
|
||||
|
||||
bool is_error() const { return m_is_error; }
|
||||
KResult error() const { ASSERT(m_is_error); return m_error; }
|
||||
T& value() { ASSERT(!m_is_error); return *reinterpret_cast<T*>(&m_storage); }
|
||||
const T& value() const { ASSERT(!m_is_error); return *reinterpret_cast<T*>(&m_storage); }
|
||||
KResult error() const
|
||||
{
|
||||
ASSERT(m_is_error);
|
||||
return m_error;
|
||||
}
|
||||
T& value()
|
||||
{
|
||||
ASSERT(!m_is_error);
|
||||
return *reinterpret_cast<T*>(&m_storage);
|
||||
}
|
||||
const T& value() const
|
||||
{
|
||||
ASSERT(!m_is_error);
|
||||
return *reinterpret_cast<T*>(&m_storage);
|
||||
}
|
||||
|
||||
T release_value()
|
||||
{
|
||||
|
@ -71,4 +95,3 @@ private:
|
|||
KResult m_error;
|
||||
bool m_is_error { false };
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue