Tatooine
idholder.h
Go to the documentation of this file.
1#ifndef TATOOINE_GL_ID_HOLDER_H
2#define TATOOINE_GL_ID_HOLDER_H
3//==============================================================================
4#include <utility>
5#include "glincludes.h"
6//==============================================================================
7namespace tatooine::gl {
8//==============================================================================
9template <typename ID>
11
12//==============================================================================
13template <>
15 constexpr static GLuint value = 0;
16};
17
18//==============================================================================
19template <>
21 constexpr static GLint value = GLint(-1);
22};
23
24//==============================================================================
25template <typename ID>
26static constexpr auto id_holder_default_param_v =
28
29//==============================================================================
30template <typename ID>
31struct id_holder {
32 static constexpr auto default_val = id_holder_default_param_v<ID>;
33
34 private:
35 //----------------------------------------------------------------------------
36 ID m_id;
37
38 public:
39 //----------------------------------------------------------------------------
41 //----------------------------------------------------------------------------
42 explicit id_holder(ID _id) : m_id{_id} {}
43 //----------------------------------------------------------------------------
44 id_holder(id_holder const& other) = delete;
45 id_holder(id_holder&& other) noexcept
46 : m_id{std::exchange(other.m_id, default_val)} {}
47 //----------------------------------------------------------------------------
48 auto operator=(id_holder const& other) -> id_holder& = delete;
49 auto operator=(id_holder&& other) noexcept -> id_holder& {
50 swap(other);
51 return *this;
52 }
53 //----------------------------------------------------------------------------
54 ~id_holder() = default;
55 //----------------------------------------------------------------------------
56 [[nodiscard]] auto id() const { return m_id; }
57 //----------------------------------------------------------------------------
58 protected:
59 void set_id(ID id) { m_id = id; }
60 //----------------------------------------------------------------------------
61 auto id_ptr() { return &m_id; }
62 auto id_ref() -> auto& { return m_id; }
63 //----------------------------------------------------------------------------
64 public:
65 void swap(id_holder& other) { std::swap(m_id, other.m_id); }
66};
67//==============================================================================
68template <typename ID>
70 i0.swap(i1);
71}
72//==============================================================================
73} // namespace tatooine::gl
74//==============================================================================
75#endif
Definition: ansiformat.h:6
static constexpr auto id_holder_default_param_v
Definition: idholder.h:26
void swap(id_holder< ID > &i0, id_holder< ID > &i1)
Definition: idholder.h:69
Definition: idholder.h:10
Definition: idholder.h:31
auto id_ref() -> auto &
Definition: idholder.h:62
id_holder(id_holder const &other)=delete
void set_id(ID id)
Definition: idholder.h:59
id_holder(id_holder &&other) noexcept
Definition: idholder.h:45
ID m_id
Definition: idholder.h:36
auto id_ptr()
Definition: idholder.h:61
auto operator=(id_holder &&other) noexcept -> id_holder &
Definition: idholder.h:49
id_holder()
Definition: idholder.h:40
id_holder(ID _id)
Definition: idholder.h:42
static constexpr auto default_val
Definition: idholder.h:32
auto id() const
Definition: idholder.h:56
void swap(id_holder &other)
Definition: idholder.h:65
auto operator=(id_holder const &other) -> id_holder &=delete