view.hpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#pragma once


#include <utility>

#include <vulkan/vulkan.h>


namespace planet::vk {


    class device;

View

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
    template<typename Underlying>
    class view {
        Underlying *pd = nullptr;

      public:
        view() noexcept {}
        view(Underlying &d) noexcept : pd{&d} {}

        view(view &&v) : pd{std::exchange(v.pd, nullptr)} {}
        view(view const &) noexcept = default;
        view &operator=(view &&v) noexcept {
            pd = std::exchange(v.pd, nullptr);
            return *this;
        }
        view &operator=(view const &) noexcept = default;

        auto get() const noexcept { return pd->get(); }
        operator Underlying &() noexcept { return *pd; }
        operator Underlying const &() const noexcept { return *pd; }

        Underlying *operator->() noexcept { return pd; }
        Underlying &operator()() noexcept { return *pd; }
    };

    using device_view = view<device>;


}