libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
rarg.h
1#pragma once
2
3#include "libmicroemu/register_id.h"
4#include "libmicroemu/types.h"
5#include <cstddef>
6#include <cstdint>
7#include <type_traits>
8
12template <libmicroemu::RegisterId Rid> class RArgConst {
13public:
14 static constexpr auto kRegId = Rid;
15 constexpr libmicroemu::RegisterId Get() const { return kRegId; }
16
20 constexpr RArgConst() = default;
21
25 ~RArgConst() = default;
26
31 constexpr RArgConst(const RArgConst &r_src) = default;
32
37 constexpr RArgConst &operator=(const RArgConst &r_src) = default;
38
43 constexpr RArgConst(RArgConst &&r_src) = default;
44
49 constexpr RArgConst &operator=(RArgConst &&r_src) = default;
50
51 // Equality operator
52 template <typename R> bool operator==(const R &other) const { return Get() == other.Get(); }
53
54 // Inequality operator
55 template <typename R> bool operator!=(const R &other) const { return !(Get() == other.Get()); }
56
57private:
58 // Deleting the addition operator
59 RArgConst operator+(const RArgConst &) = delete;
60
61 // Deleting the subtraction operator
62 RArgConst operator-(const RArgConst &) = delete;
63
64 // Deleting the multiplication operator
65 RArgConst operator*(const RArgConst &) = delete;
66
67 // Deleting the division operator
68 RArgConst operator/(const RArgConst &) = delete;
69};
70
75template <typename T> class RArg {
76public:
80 RArg(T reg_id) : val_(reg_id) {
81 static_assert(std::is_integral<T>::value, "T must be an integral type");
82 static_assert(std::is_unsigned<T>::value, "T must be an unsigned type");
83 static_assert(std::is_same_v<T, std::underlying_type_t<libmicroemu::RegisterId>>,
84 "RArg only allows underlying type of RegisterId");
85 }
86
90 ~RArg() = default;
91
96 RArg(const RArg &r_src) = default;
97
102 RArg &operator=(const RArg &r_src) = default;
103
108 RArg(RArg &&r_src) = default;
109
114 RArg &operator=(RArg &&r_src) = default;
115
116 inline libmicroemu::RegisterId Get() const { return static_cast<libmicroemu::RegisterId>(val_); }
117
118 // Equality operator
119 template <typename R> bool operator==(const R &other) const { return Get() == other.Get(); }
120
121 // Inequality operator
122 template <typename R> bool operator!=(const R &other) const { return !(Get() == other.Get()); }
123
124private:
125 T val_;
126
127 // Deleting the addition operator
128 RArg operator+(const RArg &) = delete;
129
130 // Deleting the subtraction operator
131 RArg operator-(const RArg &) = delete;
132
133 // Deleting the multiplication operator
134 RArg operator*(const RArg &) = delete;
135
136 // Deleting the division operator
137 RArg operator/(const RArg &) = delete;
138};
constexpr RArgConst & operator=(const RArgConst &r_src)=default
Copy assignment operator for ArgConst.
constexpr RArgConst(RArgConst &&r_src)=default
Move constructor for ArgConst.
~RArgConst()=default
Destructor.
constexpr RArgConst & operator=(RArgConst &&r_src)=default
Move assignment operator for ArgConst.
constexpr RArgConst()=default
Constructor.
constexpr RArgConst(const RArgConst &r_src)=default
Copy constructor for ArgConst.
~RArg()=default
Destructor.
RArg(RArg &&r_src)=default
Move constructor for Arg.
RArg(T reg_id)
Constructor.
Definition rarg.h:80
RArg & operator=(const RArg &r_src)=default
Copy assignment operator for Arg.
RArg(const RArg &r_src)=default
Copy constructor for Arg.
RArg & operator=(RArg &&r_src)=default
Move assignment operator for Arg.
RegisterId
Enumeration of register IDs.
Definition register_id.h:13