summaryrefslogtreecommitdiffhomepage
path: root/CompilerKit/StdKit/ErrorOr.hpp
blob: 15a0a753c9e648212ab11593237abe47901930e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 *	========================================================
 *
 *	CompilerKit
 * 	Copyright Mahrouss Logic, all rights reserved.
 *
 * 	========================================================
 */

#pragma once

#include <CompilerKit/Defines.hpp>
#include <CompilerKit/StdKit/Ref.hpp>

namespace CompilerKit
{
using ErrorT = UInt32;

template <typename T> 
class ErrorOr final
{
  public:
    ErrorOr() = default;
    ~ErrorOr() = default;

  public:
    explicit ErrorOr(Int32 err) 
        : mId(err)
    {}

    explicit ErrorOr(nullPtr Null)
    {}

    explicit ErrorOr(T Class) 
        : mRef(Class)
    {}

    ErrorOr &operator=(const ErrorOr &) = default;
    ErrorOr(const ErrorOr &) = default;

    Ref<T> Leak()
    {
        return mRef;
    }
    
    operator bool()
    {
        return mRef;
    }

  private:
    Ref<T> mRef;
    Int32 mId{0};
};

using ErrorOrAny = ErrorOr<voidPtr>;

} // namespace CompilerKit