virtmem
virtual memory library for Arduino
virtmem::VPtr< T, TA > Class Template Reference

Virtual pointer class that provides an interface to access virtual much like 'regular pointers'. More...

#include <vptr.h>

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

Classes

class  MemberWrapper
 Proxy class used when member access is requested on a virtual pointer. More...
 
class  ValueWrapper
 Proxy class returned when dereferencing virtual pointers. More...
 

Public Types

typedef T * TPtr
 (non virtual) pointer type to the base type of this virtual pointer.
 
typedef TA Allocator
 Allocator type used by this virtual pointer class. More...
 
- Public Types inherited from virtmem::BaseVPtr
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

 VPtr (NILL_t)
 Construct from NILL/nullptr (C++11 only)
 
Dereference operators

The following operators are used for accessing the data pointed to by this virtual pointer. The returned value is a proxy class, which mostly acts as the data itself.

See also
aAccess
ValueWrapper operator* (void)
 
MemberWrapper operator-> (void)
 
const MemberWrapper operator-> (void) const
 
const ValueWrapper operator[] (int i) const
 
ValueWrapper operator[] (int i)
 
Const conversion operators
 operator VPtr< const T, Allocator > (void)
 
template<typename T2 >
VIRTMEM_EXPLICIT operator VPtr< T2, Allocator > (void)
 
Pointer arithmetic

These operators can be used for pointer arithmetics.

ThisVPtroperator+= (int n)
 
ThisVPtroperator++ (void)
 
ThisVPtr operator++ (int)
 
ThisVPtroperator-= (int n)
 
ThisVPtroperator-- (void)
 
ThisVPtr operator-- (int)
 
ThisVPtr operator+ (int n) const
 
ThisVPtr operator- (int n) const
 
int operator- (const ThisVPtr &other) const
 
- Public Member Functions inherited from virtmem::BaseVPtr
 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.
 
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
 
bool operator== (const NILL_t &) const
 
bool operator!= (const NILL_t &) const
 
 operator TSafeBool (void) const
 Allows if (myvirtptr) ... expressions.
 

Static Public Member Functions

static AllocatorgetAlloc (void)
 Returns instance of allocator bound to this virtual pointer. More...
 
- Static Public Member Functions inherited from virtmem::BaseVPtr
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...
 

Friends

template<typename >
class VPtrLock
 

Members related to regular pointer wrapping

The following functions / operators are only defined when VIRTMEM_WRAP_CPOINTERS is set.

T * unwrap (void)
 Provide access to wrapped regular pointer (non static version). More...
 
const T * unwrap (void) const
 Provide access to wrapped regular pointer (non static const version). More...
 
VPtr< ThisVPtr, Allocatoroperator& (void)
 Returns a virtual pointer that has the memory address of this virtual pointer wrapped. More...
 
const VPtraddressOf (void) const
 Returns a regular pointer to the address of this virtual pointer. More...
 
VPtraddressOf (void)
 Returns a regular pointer to the address of this virtual pointer. More...
 
static ThisVPtr wrap (const T *p)
 Wraps a regular pointer. More...
 
static T * unwrap (const ThisVPtr &p)
 Provide access to wrapped regular pointer. More...
 

Additional Inherited Members

- Protected Attributes inherited from virtmem::BaseVPtr
PtrNum ptr
 Numeric representation of this virtual pointer.
 

Detailed Description

template<typename T, typename TA>
class virtmem::VPtr< T, TA >

Virtual pointer class that provides an interface to access virtual much like 'regular pointers'.

This class provides an easy to use interface to access from virtual memory. The class provides functionality such as dereferencing data, array access, memory (de)allocation and pointer arithmetic. 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.

Template Parameters
TThe type of the data this pointer points to (e.g. char, int, a struct etc...)
TAThe allocator type that contains the virtual memory pool where the pointed data resides.
See also
BaseVPtr, TSPIRAMVirtPtr, TSDVirtPtr, TSerRAMVirtPtr, TStaticVPtr and TStdioVirtPtr
Examples:
alloc_properties.ino, locking.ino, multispiram_simple.ino, sd_simple.ino, serial_simple.ino, and spiram_simple.ino.

Member Typedef Documentation

template<typename T, typename TA>
typedef TA virtmem::VPtr< T, TA >::Allocator

Allocator type used by this virtual pointer class.

See also
getAlloc

Member Function Documentation

template<typename T, typename TA>
const VPtr* virtmem::VPtr< T, TA >::addressOf ( void  ) const
inline

Returns a regular pointer to the address of this virtual pointer.

Note
This function is only defined when VIRTMEM_WRAP_CPOINTERS and VIRTMEM_VIRT_ADDRESS_OPERATOR are defined (e.g. in config.h).
See also
VIRTMEM_VIRT_ADDRESS_OPERATOR
template<typename T, typename TA>
VPtr* virtmem::VPtr< T, TA >::addressOf ( void  )
inline

Returns a regular pointer to the address of this virtual pointer.

Note
This function is only defined when VIRTMEM_WRAP_CPOINTERS and VIRTMEM_VIRT_ADDRESS_OPERATOR are defined (e.g. in config.h).
See also
VIRTMEM_VIRT_ADDRESS_OPERATOR
template<typename T, typename TA>
static Allocator* virtmem::VPtr< T, TA >::getAlloc ( void  )
inlinestatic

Returns instance of allocator bound to this virtual pointer.

See also
VAlloc::getInstance
template<typename T, typename TA>
VPtr<ThisVPtr, Allocator> virtmem::VPtr< T, TA >::operator& ( void  )
inline

Returns a virtual pointer that has the memory address of this virtual pointer wrapped.

Note
This operator is only overloaded when VIRTMEM_WRAP_CPOINTERS and VIRTMEM_VIRT_ADDRESS_OPERATOR are defined (e.g. in config.h).
See also
VIRTMEM_VIRT_ADDRESS_OPERATOR
template<typename T, typename TA>
static T* virtmem::VPtr< T, TA >::unwrap ( const ThisVPtr< T, TA > &  p)
inlinestatic

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.
template<typename T, typename TA>
T* virtmem::VPtr< T, TA >::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.
template<typename T, typename TA>
const T* virtmem::VPtr< T, TA >::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.
template<typename T, typename TA>
static ThisVPtr virtmem::VPtr< T, TA >::wrap ( const T *  p)
inlinestatic

Wraps a regular pointer.

Regular (non virtual) pointers can be stored inside a virtual pointer (wrapping). In this situation, arithmetic, access, etc. will be proxied to the regular pointer. This is useful when using code that mixes both virtual and non-virtual pointers.

Example:

int data[] = { 1, 2, 3, 4 };
vptrType vptr = vptrType::wrap(data);
vptr += 2;
Serial.println(*vptr); // prints "3"
Parameters
pregular pointer to wrap
Returns
A virtual pointer wrapping the specified pointer.
See also
unwrap
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 files: