tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
pointer_int_pair< PointerT, IntBits, IntType, PtrTraits, Info > Struct Template Reference

This struct implements a pair of a pointer and small integer. It is designed to represent this in the space required by one pointer by bitmangling the integer into the low part of the pointer. This can only be done for small integers: typically up to 3 bits, but it depends on the number of bits available according to pointer_like_traits for the type. More...

#include <pointer_int_pair.hpp>

Public Types

using int_type = IntType
 
using pointer_info = Info
 
using pointer_traits = PtrTraits
 
using pointer_type = PointerT
 

Public Member Functions

constexpr pointer_int_pair ()=default
 
 pointer_int_pair (pointer_type pointerValue)
 
 pointer_int_pair (pointer_type pointerValue, int_type intValue)
 
auto get_addr_of_pointer () -> pointer_type *
 
auto get_addr_of_pointer () const -> pointer_type const *
 
auto get_int () const -> int_type
 
auto get_opaque_value () const -> void *
 
auto get_pointer () const -> pointer_type
 
void set_from_opaque_value (void *val)
 
void set_int (int_type intValue)
 
void set_pointer (pointer_type pointerValue)
 
void set_ptr_and_int (pointer_type pointerValue, int_type intValue)
 

Static Public Member Functions

static auto get_from_opaque_value (void *v) -> pointer_int_pair
 
static auto get_from_opaque_value (void const *v) -> pointer_int_pair
 Allow pointer_int_pairs to be created from const void * if and only if the pointer type could be created from a const void *.
 

Static Public Attributes

static constexpr auto int_bits = IntBits
 

Friends

auto operator!= (pointer_int_pair const &lhs, pointer_int_pair const &rhs) -> bool
 
auto operator< (pointer_int_pair const &lhs, pointer_int_pair const &rhs) -> bool
 
auto operator<= (pointer_int_pair const &lhs, pointer_int_pair const &rhs) -> bool
 
auto operator== (pointer_int_pair const &lhs, pointer_int_pair const &rhs) -> bool
 
auto operator> (pointer_int_pair const &lhs, pointer_int_pair const &rhs) -> bool
 
auto operator>= (pointer_int_pair const &lhs, pointer_int_pair const &rhs) -> bool
 

Detailed Description

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
struct etl::pointer_int_pair< PointerT, IntBits, IntType, PtrTraits, Info >

This struct implements a pair of a pointer and small integer. It is designed to represent this in the space required by one pointer by bitmangling the integer into the low part of the pointer. This can only be done for small integers: typically up to 3 bits, but it depends on the number of bits available according to pointer_like_traits for the type.

Note that pointer_int_pair always puts the IntVal part in the highest bits possible. For example, pointer_int_pair<void*, 1, bool> will put the bit for the bool into bit #2, not bit #0, which allows the low two bits to be used for something else. For example, this allows: pointer_int_pair<pointer_int_pair<void*, 1, bool>, 1, bool> ... and the two bools will land in different bits.

// SPDX-License-Identifier: BSL-1.0
#undef NDEBUG
#include <etl/cassert.hpp> // for assert
#include <etl/memory.hpp> // for pointer_int_pair
auto main() -> int
{
#if not defined(TETL_WORKAROUND_AVR_BROKEN_TESTS)
auto ptr = etl::pointer_int_pair<double*, 2>{new double(42.0), 1U};
assert(*ptr.get_pointer() == 42.0);
assert(ptr.get_int() == 1U);
delete ptr.get_pointer();
#endif
return 0;
}
#define assert(...)
Definition cassert.hpp:19
This struct implements a pair of a pointer and small integer. It is designed to represent this in the...
Definition pointer_int_pair.hpp:33
Examples
memory.cpp.

Member Typedef Documentation

◆ int_type

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
using int_type = IntType

◆ pointer_info

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
using pointer_info = Info

◆ pointer_traits

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
using pointer_traits = PtrTraits

◆ pointer_type

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
using pointer_type = PointerT

Constructor & Destructor Documentation

◆ pointer_int_pair() [1/3]

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
pointer_int_pair ( )
constexprdefault

◆ pointer_int_pair() [2/3]

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
pointer_int_pair ( pointer_type pointerValue,
int_type intValue )
inline

◆ pointer_int_pair() [3/3]

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
pointer_int_pair ( pointer_type pointerValue)
inlineexplicit

Member Function Documentation

◆ get_addr_of_pointer() [1/2]

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
auto get_addr_of_pointer ( ) -> pointer_type*
inline

◆ get_addr_of_pointer() [2/2]

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
auto get_addr_of_pointer ( ) const -> pointer_type const*
inlinenodiscard

◆ get_from_opaque_value() [1/2]

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
auto get_from_opaque_value ( void * v) -> pointer_int_pair
inlinestatic

◆ get_from_opaque_value() [2/2]

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
auto get_from_opaque_value ( void const * v) -> pointer_int_pair
inlinestatic

Allow pointer_int_pairs to be created from const void * if and only if the pointer type could be created from a const void *.

◆ get_int()

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
auto get_int ( ) const -> int_type
inlinenodiscard

◆ get_opaque_value()

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
auto get_opaque_value ( ) const -> void*
inlinenodiscard

◆ get_pointer()

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
auto get_pointer ( ) const -> pointer_type
inlinenodiscard

◆ set_from_opaque_value()

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
void set_from_opaque_value ( void * val)
inline

◆ set_int()

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
void set_int ( int_type intValue)
inline

◆ set_pointer()

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
void set_pointer ( pointer_type pointerValue)
inline

◆ set_ptr_and_int()

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
void set_ptr_and_int ( pointer_type pointerValue,
int_type intValue )
inline

Friends And Related Symbol Documentation

◆ operator!=

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
auto operator!= ( pointer_int_pair< PointerT, IntBits, IntType, PtrTraits, Info > const & lhs,
pointer_int_pair< PointerT, IntBits, IntType, PtrTraits, Info > const & rhs ) -> bool
friend

◆ operator<

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
auto operator< ( pointer_int_pair< PointerT, IntBits, IntType, PtrTraits, Info > const & lhs,
pointer_int_pair< PointerT, IntBits, IntType, PtrTraits, Info > const & rhs ) -> bool
friend

◆ operator<=

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
auto operator<= ( pointer_int_pair< PointerT, IntBits, IntType, PtrTraits, Info > const & lhs,
pointer_int_pair< PointerT, IntBits, IntType, PtrTraits, Info > const & rhs ) -> bool
friend

◆ operator==

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
auto operator== ( pointer_int_pair< PointerT, IntBits, IntType, PtrTraits, Info > const & lhs,
pointer_int_pair< PointerT, IntBits, IntType, PtrTraits, Info > const & rhs ) -> bool
friend

◆ operator>

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
auto operator> ( pointer_int_pair< PointerT, IntBits, IntType, PtrTraits, Info > const & lhs,
pointer_int_pair< PointerT, IntBits, IntType, PtrTraits, Info > const & rhs ) -> bool
friend

◆ operator>=

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
auto operator>= ( pointer_int_pair< PointerT, IntBits, IntType, PtrTraits, Info > const & lhs,
pointer_int_pair< PointerT, IntBits, IntType, PtrTraits, Info > const & rhs ) -> bool
friend

Member Data Documentation

◆ int_bits

template<typename PointerT, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = pointer_like_traits<PointerT>, typename Info = pointer_int_pair_info<PointerT, IntBits, PtrTraits>>
auto int_bits = IntBits
staticconstexpr

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