SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_lockBase.h
1#ifndef SDL3PP_LOCK_BASE_H_
2#define SDL3PP_LOCK_BASE_H_
3
4#include <SDL3/SDL_assert.h>
5#include "SDL3pp_error.h"
6
7namespace SDL {
8
17template<class RESOURCE>
19{
20 RESOURCE m_resource;
21
22protected:
24 constexpr LockBase(RESOURCE&& resource)
25 : m_resource(std::move(resource))
26 {
27 }
28
29public:
31 constexpr LockBase() = default;
32
33 LockBase(const LockBase& other) = delete;
34
37 : LockBase(std::move(other.m_resource))
38 {
39 }
40
42 constexpr ~LockBase() { SDL_assert_paranoid(!m_resource); }
43
44 LockBase& operator=(const LockBase& other) = delete;
45
48 {
49 std::swap(m_resource, other.m_resource);
50 return *this;
51 }
52
54 RESOURCE release() { return m_resource.release(); }
55};
56
57} // namespace SDL
58
59#endif /* SDL3PP_LOCK_BASE_H_ */
Base class for locks.
Definition SDL3pp_lockBase.h:19
LockBase & operator=(LockBase &&other)
Move assignment.
Definition SDL3pp_lockBase.h:47
RESOURCE release()
Release locked resource without unlocking it.
Definition SDL3pp_lockBase.h:54
LockBase(LockBase &&other)
Move ctor.
Definition SDL3pp_lockBase.h:36
constexpr LockBase(RESOURCE &&resource)
Constructs initializing member.
Definition SDL3pp_lockBase.h:24
constexpr LockBase()=default
Default ctor.
constexpr ~LockBase()
Dtor.
Definition SDL3pp_lockBase.h:42
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition SDL3pp_assert.h:374
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7