Cbeam
Loading...
Searching...
No Matches
cbeam::memory::pointer Class Reference

The pointer class is one of the types supported by container::xpod::type. More...

#include <pointer.hpp>

Public Member Functions

 pointer ()=default
 
 pointer (void *ptr)
 Construct from the given raw pointer. Checks if this ptr is managed by stable_reference_buffer.
 
 pointer (const std::string &str_ptr)
 Construct from the given pointer in string representation (e.g. "0x...").
 
 pointer (const container::stable_reference_buffer &mem)
 Construct from an existing stable_reference_buffer, incrementing its reference counter.
 
template<typename T>
 pointer (const std::shared_ptr< T > &ptr)
 
bool is_managed () const
 Checks whether the pointer is managed by stable_reference_buffer (or a std::shared_ptr) or not.
 
 operator void * () const
 Converts the pointer to a raw void*.
 
pointeroperator= (const pointer &other)
 Copy assignment operator. Increments the reference counter if the other pointer is managed.
 
 operator container::stable_reference_buffer () const
 Converts the pointer to a stable_reference_buffer if it is managed, otherwise throws a runtime_error.
 
 operator std::string () const
 Converts the pointer to a hex string with leading "0x".
 

Detailed Description

The pointer class is one of the types supported by container::xpod::type.

It provides an optional reference-counted mechanism (via stable_reference_buffer or an internal std::shared_ptr) to manage the underlying memory. Otherwise, it simply stores a raw pointer.

Constructor & Destructor Documentation

◆ pointer() [1/5]

cbeam::memory::pointer::pointer ( )
default

◆ pointer() [2/5]

cbeam::memory::pointer::pointer ( void * ptr)
inline

Construct from the given raw pointer. Checks if this ptr is managed by stable_reference_buffer.

Parameters
ptrA raw pointer that may or may not be managed by stable_reference_buffer. If it is managed, a reference to it is kept in _mem.

◆ pointer() [3/5]

cbeam::memory::pointer::pointer ( const std::string & str_ptr)
inline

Construct from the given pointer in string representation (e.g. "0x...").

Internally calls convert::from_string<void*>(str_ptr).

Parameters
str_ptrThe string representation of the pointer.

◆ pointer() [4/5]

cbeam::memory::pointer::pointer ( const container::stable_reference_buffer & mem)
inlineexplicit

Construct from an existing stable_reference_buffer, incrementing its reference counter.

Parameters
memA stable_reference_buffer object referencing some memory.

◆ pointer() [5/5]

template<typename T>
cbeam::memory::pointer::pointer ( const std::shared_ptr< T > & ptr)
inline

Member Function Documentation

◆ is_managed()

bool cbeam::memory::pointer::is_managed ( ) const
inline

Checks whether the pointer is managed by stable_reference_buffer (or a std::shared_ptr) or not.

Returns
true if the pointer is managed, false otherwise.

◆ operator container::stable_reference_buffer()

cbeam::memory::pointer::operator container::stable_reference_buffer ( ) const
inlineexplicit

Converts the pointer to a stable_reference_buffer if it is managed, otherwise throws a runtime_error.

Exceptions
cbeam::error::runtime_errorIf the pointer is not managed by a stable_reference_buffer.
Returns
A copy of the underlying stable_reference_buffer.

◆ operator std::string()

cbeam::memory::pointer::operator std::string ( ) const
inlineexplicit

Converts the pointer to a hex string with leading "0x".

Returns
A string representation of the pointer value in hexadecimal format.

◆ operator void *()

cbeam::memory::pointer::operator void * ( ) const
inline

Converts the pointer to a raw void*.

Returns
A void* pointing to the underlying memory (or nullptr if empty).

◆ operator=()

pointer & cbeam::memory::pointer::operator= ( const pointer & other)
inline

Copy assignment operator. Increments the reference counter if the other pointer is managed.

Parameters
otherThe pointer object to copy from.
Returns
A reference to this object.

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