xentara-utils v2.0.4
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::windows::LocalFreePointer< Element > Class Template Reference

A smart pointer that frees its object using LocalFree(). More...

#include <xentara/utils/windows/LocalFree.hpp>

+ Inheritance diagram for xentara::utils::windows::LocalFreePointer< Element >:

Classes

class  Setter
 Helper class for calling functions that take an output parameter. More...
 

Public Types

using pointer = Element *
 The stored pointer type.
 
using element_type = Element
 The type of stored element.
 

Public Member Functions

constexpr LocalFreePointer () noexcept=default
 Default constructor.
 
constexpr LocalFreePointer (std::nullptr_t) noexcept
 Creates an empty object that does not contain an element.
 
constexpr LocalFreePointer (std::type_identity_t< pointer > rawPointer) noexcept
 Conversion from a raw pointer.
 
constexpr LocalFreePointer (LocalFreePointer &&other) noexcept
 Move constructor.
 
template<class OtherElement >
requires (!std::is_array_v<OtherElement>)
constexpr LocalFreePointer (LocalFreePointer< OtherElement > &&other) noexcept
 Move constructor for a related type.
 
 ~LocalFreePointer ()
 Destructor. Frees the element.
 
auto operator= (LocalFreePointer &&rhs) noexcept -> LocalFreePointer &
 Move assignment operator.
 
template<class OtherElement >
requires (!std::is_array_v<OtherElement>)
auto operator= (LocalFreePointer< OtherElement > &&rhs) noexcept -> LocalFreePointer &
 Move assignment operator for a related type.
 
auto operator= (std::nullptr_t) noexcept -> LocalFreePointer &
 Assignment operator for a null pointer.
 
constexpr operator bool () const noexcept
 Checks whether the object contains an element.
 
constexpr auto operator* () const noexcept -> element_type &
 Access to the element.
 
constexpr auto operator-> () const noexcept -> pointer
 Access to the element.
 
constexpr auto get () const noexcept -> pointer
 Gets the element.
 
constexpr auto release () noexcept -> pointer
 Removes the element and passes ownership to the caller.
 
auto reset (pointer rawPointer) noexcept -> void
 Resets the pointer to point to a diffrerent element.
 
auto swap (LocalFreePointer &other) noexcept -> void
 Swaps the element with that of another pointer.
 
auto setter () noexcept -> Setter
 Gets a setter for use as an output parameter for C functions.
 

Detailed Description

template<typename Element>
requires (!std::is_array_v<Element>)
class xentara::utils::windows::LocalFreePointer< Element >

A smart pointer that frees its object using LocalFree().

Note
This class is only available under Windows

Member Typedef Documentation

◆ element_type

template<typename Element >
using xentara::utils::windows::LocalFreePointer< Element >::element_type = Element

The type of stored element.

◆ pointer

template<typename Element >
using xentara::utils::windows::LocalFreePointer< Element >::pointer = Element *

The stored pointer type.

Constructor & Destructor Documentation

◆ LocalFreePointer() [1/5]

template<typename Element >
constexpr xentara::utils::windows::LocalFreePointer< Element >::LocalFreePointer ( )
constexprdefaultnoexcept

Default constructor.

Creates an empty object that does not contain an element.

◆ LocalFreePointer() [2/5]

template<typename Element >
constexpr xentara::utils::windows::LocalFreePointer< Element >::LocalFreePointer ( std::nullptr_t  )
constexprnoexcept

Creates an empty object that does not contain an element.

◆ LocalFreePointer() [3/5]

template<typename Element >
constexpr xentara::utils::windows::LocalFreePointer< Element >::LocalFreePointer ( std::type_identity_t< pointer rawPointer)
explicitconstexprnoexcept

Conversion from a raw pointer.

Parameters
rawPointerA pointer to the element to store, or nullptr for none. The object takes ownership of the element, if any.

◆ LocalFreePointer() [4/5]

template<typename Element >
constexpr xentara::utils::windows::LocalFreePointer< Element >::LocalFreePointer ( LocalFreePointer< Element > &&  other)
constexprnoexcept

Move constructor.

Takes ownership of the other object’s element, if any.

Parameters
otherThe object to move. Will be reset and no longer contain an element afterwards.

◆ LocalFreePointer() [5/5]

template<typename Element >
template<class OtherElement >
requires (!std::is_array_v<OtherElement>)
constexpr xentara::utils::windows::LocalFreePointer< Element >::LocalFreePointer ( LocalFreePointer< OtherElement > &&  other)
constexprnoexcept

Move constructor for a related type.

Takes ownership of the other object’s element, if any.

Parameters
otherThe object to move. Will be reset and no longer contain an element afterwards.

◆ ~LocalFreePointer()

template<typename Element >
xentara::utils::windows::LocalFreePointer< Element >::~LocalFreePointer ( )

Destructor. Frees the element.

Member Function Documentation

◆ get()

template<typename Element >
constexpr auto xentara::utils::windows::LocalFreePointer< Element >::get ( ) const -> pointer
constexprnoexcept

Gets the element.

Returns
The element, or nullptr for none.

◆ operator bool()

template<typename Element >
constexpr xentara::utils::windows::LocalFreePointer< Element >::operator bool ( ) const
explicitconstexprnoexcept

Checks whether the object contains an element.

◆ operator*()

template<typename Element >
constexpr auto xentara::utils::windows::LocalFreePointer< Element >::operator* ( ) const -> element_type &
constexprnoexcept

Access to the element.

◆ operator->()

template<typename Element >
constexpr auto xentara::utils::windows::LocalFreePointer< Element >::operator-> ( ) const -> pointer
constexprnoexcept

Access to the element.

◆ operator=() [1/3]

template<typename Element >
auto xentara::utils::windows::LocalFreePointer< Element >::operator= ( LocalFreePointer< Element > &&  rhs) -> LocalFreePointer &
noexcept

Move assignment operator.

Takes ownership of the other objects’s element, if any. Any existing element is freed.

Parameters
rhsThe object to move. Will be reset and no longer contain an element afterwards.
Returns
A reference to this object

◆ operator=() [2/3]

template<typename Element >
template<class OtherElement >
requires (!std::is_array_v<OtherElement>)
auto xentara::utils::windows::LocalFreePointer< Element >::operator= ( LocalFreePointer< OtherElement > &&  rhs) -> LocalFreePointer &
noexcept

Move assignment operator for a related type.

Takes ownership of the other objects’s element, if any. Any existing element is freed.

Parameters
rhsThe object to move. Will be reset and no longer contain an element afterwards.
Returns
A reference to this object

◆ operator=() [3/3]

template<typename Element >
auto xentara::utils::windows::LocalFreePointer< Element >::operator= ( std::nullptr_t  ) -> LocalFreePointer &
noexcept

Assignment operator for a null pointer.

Frees any object this pointer may contain.

Returns
A reference to this object

◆ release()

template<typename Element >
constexpr auto xentara::utils::windows::LocalFreePointer< Element >::release ( ) -> pointer
constexprnoexcept

Removes the element and passes ownership to the caller.

After this call, this object will no longer contain an element.

Returns
The native pointer, or nullptr for none. The caller must assume ownership of the object and free it when it is no longer needed.

◆ reset()

template<typename Element >
auto xentara::utils::windows::LocalFreePointer< Element >::reset ( pointer  rawPointer) -> void
noexcept

Resets the pointer to point to a diffrerent element.

Takes ownership of the element, if any. Any existing element is freed.

Parameters
rawPointerA pointer to the element to store, or nullptr for none. The object takes ownership of the element, if any.

◆ setter()

template<typename Element >
requires (!std::is_array_v<Element>)
auto xentara::utils::windows::LocalFreePointer< Element >::setter ( ) -> Setter
noexcept

Gets a setter for use as an output parameter for C functions.

This function returns a helper object that can be passed to a function that takes an Element ** as output parameter. This provides a safe way of creating elements using such a function without running the risk of leaking the created element.

◆ swap()

template<typename Element >
auto xentara::utils::windows::LocalFreePointer< Element >::swap ( LocalFreePointer< Element > &  other) -> void
noexcept

Swaps the element with that of another pointer.

Parameters
otherThe pointer to swap with.