summaryrefslogtreecommitdiffhomepage
path: root/public/frameworks/CoreFoundation.fwrk/headers/Atom.h
blob: 4f1c811fcd77a7ca2f18ac802e12fde25c12c7a6 (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
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (see LICENSE file)
// Official repository: https://github.com/ne-foss-org/nekernel
#ifndef HEADERS_ATOM_H
#define HEADERS_ATOM_H

#include <CoreFoundation.fwrk/headers/Foundation.h>

namespace CF {
template <class T>
class CFAtom final {
 public:
  explicit CFAtom() = default;
  ~CFAtom()         = default;

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

 public:
  T operator[](SizeT bit) { return (fArrayOfAtoms & (1 << bit)); }

  void operator|(SizeT bit) { fArrayOfAtoms |= (1 << bit); }

  friend Boolean operator==(CFAtom<T>& atomic, const T& idx) { return atomic[idx] == idx; }

  friend Boolean operator!=(CFAtom<T>& atomic, const T& idx) { return atomic[idx] == idx; }

 private:
  T fArrayOfAtoms;
};
}  // namespace CF

#endif