From 2a2c3d58388579d19a7310684521dc57299969d2 Mon Sep 17 00:00:00 2001 From: Amlal Date: Mon, 17 Feb 2025 08:11:16 +0100 Subject: ADD: Atom.h in LibCF, Atom.h in NewKit and LibCF stores the value as a bit. Signed-off-by: Amlal --- dev/Kernel/NewKit/Atom.h | 8 ++++---- dev/Usr/LibCF/Atom.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 dev/Usr/LibCF/Atom.h (limited to 'dev') diff --git a/dev/Kernel/NewKit/Atom.h b/dev/Kernel/NewKit/Atom.h index a90ef003..6845aee8 100644 --- a/dev/Kernel/NewKit/Atom.h +++ b/dev/Kernel/NewKit/Atom.h @@ -21,13 +21,13 @@ namespace Kernel Atom(const Atom&) = delete; public: - T operator[](Size sz) + T operator[](Size bit) { - return (fArrayOfAtoms & sz); + return (fArrayOfAtoms & (1 << bit)); } - void operator|(Size sz) + void operator|(Size bit) { - fArrayOfAtoms |= sz; + fArrayOfAtoms |= (1 << bit); } friend Boolean operator==(Atom& atomic, const T& idx) diff --git a/dev/Usr/LibCF/Atom.h b/dev/Usr/LibCF/Atom.h new file mode 100644 index 00000000..9dde247e --- /dev/null +++ b/dev/Usr/LibCF/Atom.h @@ -0,0 +1,47 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ +#pragma once + +#include + +namespace LibCF +{ + template + 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& atomic, const T& idx) + { + return atomic[idx] == idx; + } + + friend Boolean operator!=(CFAtom& atomic, const T& idx) + { + return atomic[idx] == idx; + } + + private: + T fArrayOfAtoms; + }; +} // namespace LibCF -- cgit v1.2.3