1#ifndef SDL3PP_OWN_PTR_H_
2#define SDL3PP_OWN_PTR_H_
20 void operator()(
void* ptr)
const;
33using OwnPtr = std::unique_ptr<T, PtrDeleter>;
50 constexpr OwnArray(std::nullptr_t =
nullptr) {}
65 while (*endPtr) ++endPtr;
66 m_size = endPtr - ptr;
71 constexpr explicit operator bool()
const {
return bool(m_ptr); }
74 constexpr bool empty()
const {
return !m_ptr; }
77 constexpr T*
data() {
return m_ptr.get(); }
80 constexpr const T*
data()
const {
return m_ptr.get(); }
83 constexpr size_t size()
const {
return m_size; }
99 void reset(T* newValue =
nullptr)
101 m_ptr.reset(newValue);
103 auto endPtr = newValue;
104 while (*endPtr) ++endPtr;
105 m_size = endPtr - newValue;
117 m_ptr.reset(newValue);
125 constexpr const T&
operator[](
size_t i)
const {
return m_ptr.get()[i]; }
Base class for SDL memory allocated array wrap.
Definition: SDL3pp_ownPtr.h:44
constexpr T & operator[](size_t i)
Access index.
Definition: SDL3pp_ownPtr.h:122
void reset(T *newValue, size_t size)
Reset object.
Definition: SDL3pp_ownPtr.h:115
constexpr bool empty() const
True if size() == 0.
Definition: SDL3pp_ownPtr.h:74
T * begin()
Get iterator to first element.
Definition: SDL3pp_ownPtr.h:128
const T * cend() const
Get iterator to one past end element.
Definition: SDL3pp_ownPtr.h:143
T * release()
Release control on object.
Definition: SDL3pp_ownPtr.h:91
constexpr const T * data() const
Data.
Definition: SDL3pp_ownPtr.h:80
const T * begin() const
Get iterator to first element.
Definition: SDL3pp_ownPtr.h:131
constexpr OwnArray(std::nullptr_t=nullptr)
Constructor.
Definition: SDL3pp_ownPtr.h:50
constexpr OwnArray(T *ptr)
Constructor.
Definition: SDL3pp_ownPtr.h:60
T & front()
Return first element.
Definition: SDL3pp_ownPtr.h:146
const T * cbegin() const
Get iterator to first element.
Definition: SDL3pp_ownPtr.h:134
T * end()
Get iterator to one past end element.
Definition: SDL3pp_ownPtr.h:137
constexpr const T & operator[](size_t i) const
Access index.
Definition: SDL3pp_ownPtr.h:125
void reset(T *newValue=nullptr)
Reset object.
Definition: SDL3pp_ownPtr.h:99
constexpr size_t size() const
Size.
Definition: SDL3pp_ownPtr.h:83
const T * end() const
Get iterator to one past end element.
Definition: SDL3pp_ownPtr.h:140
T & back()
Return last element.
Definition: SDL3pp_ownPtr.h:149
constexpr T * data()
Data.
Definition: SDL3pp_ownPtr.h:77
constexpr OwnArray(T *ptr, size_t size)
Constructor.
Definition: SDL3pp_ownPtr.h:53
std::span< T > RefArray
Handle to an owned SDL memory allocated array.
Definition: SDL3pp_ownPtr.h:165
std::unique_ptr< T, PtrDeleter > OwnPtr
Handle to an owned SDL memory allocated pointer.
Definition: SDL3pp_ownPtr.h:33
Main include header for the SDL3pp library.
Calls SDL_free()
Definition: SDL3pp_ownPtr.h:18