virtmem
virtual memory library for Arduino
|
Virtual pointer class that provides an interface to access virtual much like 'regular pointers'. More...
#include <vptr.h>
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.
| |
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. | |
ThisVPtr & | operator+= (int n) |
ThisVPtr & | operator++ (void) |
ThisVPtr | operator++ (int) |
ThisVPtr & | operator-= (int n) |
ThisVPtr & | operator-- (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 Allocator * | getAlloc (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, Allocator > | operator& (void) |
Returns a virtual pointer that has the memory address of this virtual pointer wrapped. More... | |
const VPtr * | addressOf (void) const |
Returns a regular pointer to the address of this virtual pointer. More... | |
VPtr * | addressOf (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. | |
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.
T | The type of the data this pointer points to (e.g. char, int, a struct etc...) |
TA | The allocator type that contains the virtual memory pool where the pointed data resides. |
typedef TA virtmem::VPtr< T, TA >::Allocator |
Allocator type used by this virtual pointer class.
|
inline |
Returns a regular pointer to the address of this virtual pointer.
|
inline |
Returns a regular pointer to the address of this virtual pointer.
|
inlinestatic |
Returns instance of allocator bound to this virtual pointer.
|
inline |
Returns a virtual pointer that has the memory address of this virtual pointer wrapped.
|
inlinestatic |
Provide access to wrapped regular pointer.
p | virtual pointer that wraps a regular pointer |
|
inline |
Provide access to wrapped regular pointer (non static version).
|
inline |
Provide access to wrapped regular pointer (non static const version).
|
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:
p | regular pointer to wrap |