summaryrefslogtreecommitdiff
path: root/mmio/mmio.h
blob: a756c8fdf1e31c63890b8ae15ec127dc743875c3 (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
#pragma once

#include <cstdint>

template <typename T>
class mmio_ptr {
    private:
        const uintptr_t p;

    protected:
        T* ptr() const {
            return reinterpret_cast<T*>(p);
        }

    public:
        constexpr mmio_ptr(uintptr_t p) : p(p) {}

        T* operator->() const {
            return ptr();
        }

        T& operator*() const {
            return *ptr();
        }

        T& operator[](std::size_t idx) const {
            return ptr()[idx];
        }
};