blob: c23508f6132d4a30c2ea8f08a49e06a43a974005 (
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
|
// 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 NEKIT_ATOM_H
#define NEKIT_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;
using Ref = TypeAtomic&;
using ConstRef = const TypeAtomic&;
const TypeAtomic& operator[](const TypeAtomic& bit) {
return (fArrayOfAtoms & (TypeAtomic{} << bit));
}
void operator|(const TypeAtomic& bit) { fArrayOfAtoms |= (TypeAtomic{1} << bit); }
Atom& operator|=(const TypeAtomic& 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
|