summaryrefslogtreecommitdiffhomepage
path: root/src/kernel/NeKit/Atom.h
blob: 7c5177fe4ce1974422f540de6bcd3f53eab95cb2 (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
/* ========================================

  Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.

======================================== */

#ifndef __NE_KIT_ATOM_H__
#define __NE_KIT_ATOM_H__

#include <NeKit/Config.h>

namespace Kernel {
template <class TypeAtomic>
class Atom final {
 public:
  explicit Atom() = default;
  ~Atom()         = default;

 public:
  Atom& operator=(const Atom&) = delete;
  Atom(const Atom&)            = delete;

 public:
  using Type = TypeAtomic;

  const TypeAtomic& operator[](const SizeT& bit) { return (fArrayOfAtoms & (1 << bit)); }

  void  operator|(const SizeT& bit) { fArrayOfAtoms |= (1 << bit); }
  Atom& operator|=(const SizeT& bit) {
    this->operator|(bit);
    return *this;
  }

  friend bool operator==(Atom<TypeAtomic>& atomic, const TypeAtomic& idx) {
    return atomic[idx] == idx;
  }
  friend bool operator!=(Atom<TypeAtomic>& atomic, const TypeAtomic& idx) {
    return atomic[idx] != idx;
  }

 private:
  TypeAtomic fArrayOfAtoms;
};
}  // namespace Kernel

#endif