WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
wpi::memory::joint_ptr< T, RawAllocator > Class Template Reference

A pointer to an object where all allocations are joint. More...

#include <wpi/memory/joint_allocator.hpp>

Public Types

using element_type = T
 
using allocator_type = typename allocator_reference<RawAllocator>::allocator_type
 

Public Member Functions

 joint_ptr (joint_ptr &&other) noexcept
 
 ~joint_ptr () noexcept
 
joint_ptroperator= (joint_ptr &&other) noexcept
 
joint_ptroperator= (std::nullptr_t) noexcept
 
void reset () noexcept
 
 operator bool () const noexcept
 
element_typeoperator* () const noexcept
 
element_typeoperator-> () const noexcept
 
element_typeget () const noexcept
 
auto get_allocator () const noexcept -> decltype(std::declval< allocator_reference< allocator_type > >().get_allocator())
 
 joint_ptr (allocator_type &alloc) noexcept
 
 joint_ptr (const allocator_type &alloc) noexcept
 
template<typename... Args>
 joint_ptr (allocator_type &alloc, joint_size additional_size, Args &&... args)
 
template<typename... Args>
 joint_ptr (const allocator_type &alloc, joint_size additional_size, Args &&... args)
 

Friends

class joint_allocator
 
void swap (joint_ptr &a, joint_ptr &b) noexcept
 

Detailed Description

template<typename T, class RawAllocator>
class wpi::memory::joint_ptr< T, RawAllocator >

A pointer to an object where all allocations are joint.

It can either own an object or not (be nullptr). When it owns an object, it points to a memory block. This memory block contains both the actual object (of the type T) and space for allocations of Ts members.

The type T must be derived from joint_type and every constructor must take joint as first parameter. This prevents that you create joint objects yourself, without the additional storage. The default copy and move constructors are also deleted, you need to write them yourself.

You can only access the object through the pointer, use joint_allocator or joint_array as members of T, to enable the memory sharing. If you are using joint_allocator inside STL containers, make sure that you do not call their regular copy/move constructors, but instead the version where you pass an allocator.

The memory block will be managed by the given RawAllocator, it is stored in an allocator_reference and not owned by the pointer directly.

Member Typedef Documentation

◆ allocator_type

template<typename T , class RawAllocator >
using wpi::memory::joint_ptr< T, RawAllocator >::allocator_type = typename allocator_reference<RawAllocator>::allocator_type

◆ element_type

template<typename T , class RawAllocator >
using wpi::memory::joint_ptr< T, RawAllocator >::element_type = T

Constructor & Destructor Documentation

◆ joint_ptr() [1/5]

template<typename T , class RawAllocator >
wpi::memory::joint_ptr< T, RawAllocator >::joint_ptr ( allocator_type & alloc)
inlineexplicitnoexcept
Effects:
Creates it with a RawAllocator, but does not own a new object.

◆ joint_ptr() [2/5]

template<typename T , class RawAllocator >
wpi::memory::joint_ptr< T, RawAllocator >::joint_ptr ( const allocator_type & alloc)
inlineexplicitnoexcept

◆ joint_ptr() [3/5]

template<typename T , class RawAllocator >
template<typename... Args>
wpi::memory::joint_ptr< T, RawAllocator >::joint_ptr ( allocator_type & alloc,
joint_size additional_size,
Args &&... args )
inline
Effects:
Reserves memory for the object and the additional size, and creates the object by forwarding the arguments to its constructor. The RawAllocator will be used for the allocation.

◆ joint_ptr() [4/5]

template<typename T , class RawAllocator >
template<typename... Args>
wpi::memory::joint_ptr< T, RawAllocator >::joint_ptr ( const allocator_type & alloc,
joint_size additional_size,
Args &&... args )
inline

◆ joint_ptr() [5/5]

template<typename T , class RawAllocator >
wpi::memory::joint_ptr< T, RawAllocator >::joint_ptr ( joint_ptr< T, RawAllocator > && other)
inlinenoexcept
Effects:
Move-constructs the pointer. Ownership will be transferred from other to the new object.

◆ ~joint_ptr()

template<typename T , class RawAllocator >
wpi::memory::joint_ptr< T, RawAllocator >::~joint_ptr ( )
inlinenoexcept
Effects:
Destroys the object and deallocates its storage.

Member Function Documentation

◆ get()

template<typename T , class RawAllocator >
element_type * wpi::memory::joint_ptr< T, RawAllocator >::get ( ) const
inlinenoexcept
Returns:
A pointer to the object it owns or nullptr, if it does not own any object.

◆ get_allocator()

template<typename T , class RawAllocator >
auto wpi::memory::joint_ptr< T, RawAllocator >::get_allocator ( ) const -> decltype(std::declval<allocator_reference<allocator_type>>().get_allocator())
inlinenoexcept
Returns:
A reference to the allocator it will use for the deallocation.

◆ operator bool()

template<typename T , class RawAllocator >
wpi::memory::joint_ptr< T, RawAllocator >::operator bool ( ) const
inlineexplicitnoexcept
Returns:
true if the pointer does own an object, false otherwise.

◆ operator*()

template<typename T , class RawAllocator >
element_type & wpi::memory::joint_ptr< T, RawAllocator >::operator* ( ) const
inlinenoexcept
Returns:
A reference to the object it owns.
Requires:
The pointer must own an object, i.e. operator bool() must return true.

◆ operator->()

template<typename T , class RawAllocator >
element_type * wpi::memory::joint_ptr< T, RawAllocator >::operator-> ( ) const
inlinenoexcept
Returns:
A pointer to the object it owns.
Requires:
The pointer must own an object, i.e. operator bool() must return true.

◆ operator=() [1/2]

template<typename T , class RawAllocator >
joint_ptr & wpi::memory::joint_ptr< T, RawAllocator >::operator= ( joint_ptr< T, RawAllocator > && other)
inlinenoexcept
Effects:
Move-assings the pointer. The previously owned object will be destroyed, and ownership of other transferred.

◆ operator=() [2/2]

template<typename T , class RawAllocator >
joint_ptr & wpi::memory::joint_ptr< T, RawAllocator >::operator= ( std::nullptr_t )
inlinenoexcept
Effects:
Same as reset().

◆ reset()

template<typename T , class RawAllocator >
void wpi::memory::joint_ptr< T, RawAllocator >::reset ( )
inlinenoexcept
Effects:
Destroys the object it refers to, if there is any.

Friends And Related Symbol Documentation

◆ joint_allocator

template<typename T , class RawAllocator >
friend class joint_allocator
friend

◆ swap

template<typename T , class RawAllocator >
void swap ( joint_ptr< T, RawAllocator > & a,
joint_ptr< T, RawAllocator > & b )
friend
Effects:
Swaps to pointers and their ownership and allocator.

The documentation for this class was generated from the following file: