summaryrefslogtreecommitdiffhomepage
path: root/dev/LibCompiler/ErrorOr.h
blob: ca93dd2cd84dfe1cb5f02a9c0bf8b6bc3ca0928e (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
/*
 *	========================================================
 *
 *	LibCompiler
 * 	Copyright (C) 2024-2025 Amlal El Mahrouss, all rights reserved.
 *
 * 	========================================================
 */

#pragma once

#include <LibCompiler/Defines.h>
#include <LibCompiler/Ref.h>

namespace LibCompiler {
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 LibCompiler