CbmRoot
Loading...
Searching...
No Matches
PaddedValue.h
Go to the documentation of this file.
1/* Copyright (C) 2024 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Felix Weiglhofer [committer] */
4
5#pragma once
6
7#include <cstddef>
8
9#include <xpu/defines.h>
10
16namespace cbm::algo
17{
18
26 template<typename T, size_t N>
28 static_assert(N % alignof(T) == 0, "N must be a multiple of alignof(T)");
29
30 public:
31 XPU_D PaddedValue() = default;
32 XPU_D PaddedValue(const T& value) : fValue(value) {}
33
34 XPU_D PaddedValue(const PaddedValue& other) : fValue(other.fValue) {}
35 XPU_D PaddedValue& operator=(const PaddedValue& other)
36 {
37 fValue = other.fValue;
38 return *this;
39 }
40
41 XPU_D PaddedValue(PaddedValue&& other) : fValue(std::move(other.fValue)) {}
43 {
44 fValue = std::move(other.fValue);
45 return *this;
46 }
47
48 XPU_D T& operator=(const T& value)
49 {
50 fValue = value;
51 return fValue;
52 }
53
54 XPU_D T& Get() { return fValue; }
55 XPU_D const T& Get() const { return fValue; }
56
57 XPU_D T* operator&() { return &fValue; }
58 XPU_D const T* operator&() const { return &fValue; }
59
60 XPU_D T& operator*() { return fValue; }
61 XPU_D const T& operator*() const { return fValue; }
62
63 XPU_D operator T&() { return fValue; }
64 XPU_D operator const T&() const { return fValue; }
65
66 XPU_D operator T*() { return &fValue; }
67 XPU_D operator const T*() const { return &fValue; }
68
69 XPU_D T* operator->() { return &fValue; }
70 XPU_D const T* operator->() const { return &fValue; }
71
72 private:
74 unsigned char fPadding[N - sizeof(T)];
75 };
76
77 inline constexpr size_t SizeOfCacheLine = 64;
78
79 template<typename T>
81
82} // namespace cbm::algo
A class that represents a value with padding to a certain size.
Definition PaddedValue.h:27
XPU_D PaddedValue(const PaddedValue &other)
Definition PaddedValue.h:34
XPU_D const T & operator*() const
Definition PaddedValue.h:61
XPU_D const T * operator->() const
Definition PaddedValue.h:70
XPU_D PaddedValue & operator=(const PaddedValue &other)
Definition PaddedValue.h:35
XPU_D T & operator=(const T &value)
Definition PaddedValue.h:48
unsigned char fPadding[N - sizeof(T)]
Definition PaddedValue.h:74
XPU_D PaddedValue()=default
XPU_D PaddedValue(PaddedValue &&other)
Definition PaddedValue.h:41
XPU_D const T & Get() const
Definition PaddedValue.h:55
XPU_D const T * operator&() const
Definition PaddedValue.h:58
XPU_D PaddedValue & operator=(PaddedValue &&other)
Definition PaddedValue.h:42
XPU_D PaddedValue(const T &value)
Definition PaddedValue.h:32
constexpr size_t SizeOfCacheLine
Definition PaddedValue.h:77
Hash for CbmL1LinkKey.