virtmem
virtual memory library for Arduino
virtmem::BaseVPtr Class Reference

This is the base class of VPtr and can be used for typeless pointers. More...

#include <base_vptr.h>

Inheritance diagram for virtmem::BaseVPtr:
virtmem::VPtr< T, TA >

Public Types

typedef private_utils::Conditional<(sizeof(intptr_t) > sizeof(VPtrNum)), intptr_t, VPtrNum >::type PtrNum
 Platform dependent numeric type to store raw (virtual/regular) pointer addresses.
 

Public Member Functions

 BaseVPtr (NILL_t)
 Construct from NILL/nullptr (C++11 only)
 
bool isWrapped (void) const
 Returns whether a virtual pointer has wrapped a regular pointer (non static version). More...
 
PtrNum getRawNum (void) const
 Returns a numeric representation of this virtual pointer. More...
 
void setRawNum (PtrNum p)
 Sets a virtual pointer from a numeric value. More...
 
void * unwrap (const BaseVPtr &p)
 Provide access to wrapped regular pointer. More...
 
void * unwrap (void)
 Provide access to wrapped regular pointer (non static version). More...
 
const void * unwrap (void) const
 Provide access to wrapped regular pointer (non static const version). More...
 
template<typename T , typename A >
VIRTMEM_EXPLICIT operator VPtr< T, A > (void) const
 Conversion operator to VPtr types.
 
Pointer comparison operators.

The following operators are used for comparing two virtual pointers. Comparing two wrapped regulared pointers is supported. Comparing wrapped and non wrapped pointers is undefined.

bool operator== (const BaseVPtr &pb) const
 
bool operator!= (const BaseVPtr &pb) const
 
bool operator< (const BaseVPtr &pb) const
 
bool operator<= (const BaseVPtr &pb) const
 
bool operator>= (const BaseVPtr &pb) const
 
bool operator> (const BaseVPtr &pb) const
 

Static Public Member Functions

static PtrNum getWrapped (PtrNum p)
 Returns raw address of regular pointer wrapped by a virtual pointer. More...
 
static bool isWrapped (PtrNum p)
 Returns whether a virtual pointer has wrapped a regular pointer. More...
 
static BaseVPtr wrap (const void *p)
 Wraps a regular pointer. More...
 

Protected Attributes

PtrNum ptr
 Numeric representation of this virtual pointer.
 

Friends

template<typename , typename >
class VPtr
 
template<typename >
class VPtrLock
 

Pointer validity checking operators.

The following operators can be used to see whether a virtual pointer is valid (i.e. is not NULL). Overloads exist to support checking for 0, NULL and NILL. The operators also work for wrapped regular pointers.

bool operator== (const NILL_t &, const BaseVPtr &pw)
 
bool operator!= (const NILL_t &, const BaseVPtr &pw)
 
bool operator== (const NILL_t &) const
 
bool operator!= (const NILL_t &) const
 
 operator TSafeBool (void) const
 Allows if (myvirtptr) ... expressions.
 

Detailed Description

This is the base class of VPtr and can be used for typeless pointers.

This base class contains all the functionality of virtual pointers which do not depend on any templated code to reduce code size. This class is designed in such a way that it can be treated mostly as 'plain old data' (POD) and can therefore be used in an union as well.

This class can be used for 'typeless' virtual pointers, similar as void* is used for 'regular' typeless pointers.

See also
Typeless virtual pointers (analog to void*)

Member Function Documentation

PtrNum virtmem::BaseVPtr::getRawNum ( void  ) const
inline

Returns a numeric representation of this virtual pointer.

This function can be used to convert virtual pointers to numeric values.

Note
The value returned by this function depends whether this virtual pointer wraps a regular pointer. If this is the case, the returned value contains the raw pointer address and a flag to indicate that this is not a virtual pointer. In this case getWrapped can be used to obtain the pointer address. If this virtual pointer does not wrap a regular pointer, the value returned by this function equals a virtual pointer address that can be used directly by an allocator for raw memory access.
See also
getWrapped, isWrapped
static PtrNum virtmem::BaseVPtr::getWrapped ( PtrNum  p)
inlinestatic

Returns raw address of regular pointer wrapped by a virtual pointer.

Parameters
pNumeric value of the virtual pointer
See also
getRawNum
Note
VIRTMEM_WRAP_CPOINTERS needs to be defined (e.g. in config.h) to enable this function.
static bool virtmem::BaseVPtr::isWrapped ( PtrNum  p)
inlinestatic

Returns whether a virtual pointer has wrapped a regular pointer.

Parameters
pNumeric value of the virtual pointer
See also
getRawNum
Note
VIRTMEM_WRAP_CPOINTERS needs to be defined (e.g. in config.h) to enable this function.
bool virtmem::BaseVPtr::isWrapped ( void  ) const
inline

Returns whether a virtual pointer has wrapped a regular pointer (non static version).

See also
getRawNum
Note
VIRTMEM_WRAP_CPOINTERS needs to be defined (e.g. in config.h) to enable this function.
void virtmem::BaseVPtr::setRawNum ( PtrNum  p)
inline

Sets a virtual pointer from a numeric value.

Parameters
pThe raw numeric representation of a virtual pointer.
See also
getRawNum
void* virtmem::BaseVPtr::unwrap ( const BaseVPtr p)
inline

Provide access to wrapped regular pointer.

Parameters
pvirtual pointer that wraps a regular pointer
Returns
regular pointer wrapped by specified virtual pointer.
See also
wrap
Note
VIRTMEM_WRAP_CPOINTERS needs to be defined (e.g. in config.h) to enable this function.
void* virtmem::BaseVPtr::unwrap ( void  )
inline

Provide access to wrapped regular pointer (non static version).

See also
VPtr::unwrap(const ThisVPtr &p), wrap
Note
VIRTMEM_WRAP_CPOINTERS needs to be defined (e.g. in config.h) to enable this function.
const void* virtmem::BaseVPtr::unwrap ( void  ) const
inline

Provide access to wrapped regular pointer (non static const version).

See also
VPtr::unwrap(const ThisVPtr &p), wrap
Note
VIRTMEM_WRAP_CPOINTERS needs to be defined (e.g. in config.h) to enable this function.
static BaseVPtr virtmem::BaseVPtr::wrap ( const void *  p)
inlinestatic

Wraps a regular pointer.

See also
VPtr::wrap
Note
VIRTMEM_WRAP_CPOINTERS needs to be defined (e.g. in config.h) to enable this function.

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