A proxy that keeps track of the relative offset of a "pointer" from its base address. This class makes it possible to transparently use "pointers" in shared memory as easily as programming with pointers to local memory. In particular, we don't need to ensure that the base addresses of all the pointers are mapped into separate processes at the same absolute memory base address. More...
#include <Based_Pointer_T.h>
Public Member Functions | |
ACE_Based_Pointer_Basic (void) | |
ACE_Based_Pointer_Basic (CONCRETE *initial) | |
ACE_Based_Pointer_Basic (const ACE_Based_Pointer_Basic< CONCRETE > &) | |
Copy constructor. | |
ACE_Based_Pointer_Basic (const void *base_addr, int o) | |
void | operator= (CONCRETE *from) |
Pseudo-assignment operator. | |
void | operator= (const ACE_Based_Pointer_Basic< CONCRETE > &) |
Pseudo-assignment operator. | |
CONCRETE | operator* (void) const |
Dereference operator. | |
bool | operator< (const ACE_Based_Pointer_Basic< CONCRETE > &) const |
Less than operator. | |
bool | operator<= (const ACE_Based_Pointer_Basic< CONCRETE > &) const |
Less than or equal operator. | |
bool | operator> (const ACE_Based_Pointer_Basic< CONCRETE > &) const |
Greater than operator. | |
bool | operator>= (const ACE_Based_Pointer_Basic< CONCRETE > &) const |
Greater than or equal operator. | |
bool | operator== (const ACE_Based_Pointer_Basic< CONCRETE > &) const |
Equality operator. | |
bool | operator!= (const ACE_Based_Pointer_Basic< CONCRETE > &) const |
Inequality operator. | |
CONCRETE | operator[] (int index) const |
Subscript operator. | |
void | operator+= (int index) |
Increment operator. | |
operator CONCRETE * () const | |
Returns the underlying memory address of the smart pointer. | |
CONCRETE * | addr (void) const |
Returns the underlying memory address of the smart pointer. | |
void | dump (void) const |
Dump the state of the object. | |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Protected Attributes | |
ptrdiff_t | target_ |
ptrdiff_t | base_offset_ |
Keep track of our offset from the base pointer. |
A proxy that keeps track of the relative offset of a "pointer" from its base address. This class makes it possible to transparently use "pointers" in shared memory as easily as programming with pointers to local memory. In particular, we don't need to ensure that the base addresses of all the pointers are mapped into separate processes at the same absolute memory base address.
Definition at line 44 of file Based_Pointer_T.h.
ACE_Based_Pointer_Basic< CONCRETE >::ACE_Based_Pointer_Basic | ( | void | ) |
This constructor initializes the <base_offset_> by asking the <ACE_BASED_POINTER_REPOSITORY> Singleton for the base address of the memory region within which it is instantiated. Two results are possible:
1. An <ACE_*_Memory_Pool> has stored a base address/size pair and the new based-pointer instance is located between the base address and the base address + size - 1. In this case, the repository returns the base address.
2. No suitable address/size pair was found. The repository assumes an address in the regular (not mapped) virtual address space of the process and returns 0. In this case, the based-pointer uses its address as an offset to it's base address 0.
Definition at line 54 of file Based_Pointer_T.cpp.
: target_ (0), base_offset_ (0) { ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::ACE_Based_Pointer_Basic"); void *base_addr = 0; // Find the base address associated with our <this> pointer. Note // that it's ok for <find> to return 0, which simply indicates that // the address is not in memory-mapped virtual address space. ACE_BASED_POINTER_REPOSITORY::instance ()->find (this, base_addr); this->base_offset_ = (char *) this - (char *) base_addr; }
ACE_Based_Pointer_Basic< CONCRETE >::ACE_Based_Pointer_Basic | ( | CONCRETE * | initial | ) |
Initialize this object using the initial pointer. This constructor initializes the <base_offset_> by asking the <ACE_BASED_POINTER_REPOSITORY> Singleton for the base address of the memory region within which it is instantiated. Three results are possible:
1. An <ACE_*_Memory_Pool> has stored a base address/size pair and the new based-pointer instance is located between the base address and the base address + size - 1. In this case, the repository returns the base address.
2. No suitable address/size pair was found. The repository assumes an address in the regular (not mapped) virtual address space of the process and returns 0. In this case, the based-pointer uses its address as an offset to its base address 0.
3. If initial is 0 then set the value of <target_> to -1, which indicates a "NULL" pointer.
Definition at line 79 of file Based_Pointer_T.cpp.
: target_ (0), base_offset_ (0) { ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::ACE_Based_Pointer_Basic"); if (rhs == 0) // Store a value of <target_> that indicate "NULL" pointer. this->target_ = -1; else { void *base_addr = 0; // Find the base address associated with the <addr> pointer. // Note that it's ok for <find> to return 0, which simply // indicates that the address is not in memory-mapped virtual // address space. ACE_BASED_POINTER_REPOSITORY::instance ()->find (this, base_addr); this->base_offset_ = (char *) this - (char *) base_addr; this->target_ = ((char *) rhs - (char *) base_addr); } }
ACE_Based_Pointer_Basic< CONCRETE >::ACE_Based_Pointer_Basic | ( | const ACE_Based_Pointer_Basic< CONCRETE > & | ) |
Copy constructor.
Definition at line 104 of file Based_Pointer_T.cpp.
{ ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::ACE_Based_Pointer_Basic"); ACE_ASSERT (0); // not implemented. }
ACE_Based_Pointer_Basic< CONCRETE >::ACE_Based_Pointer_Basic | ( | const void * | base_addr, | |
int | o | |||
) |
Constructor for know base address. o is only used to resolve overload ambiguity.
Definition at line 70 of file Based_Pointer_T.cpp.
: target_ (0), base_offset_ (0) { ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::ACE_Based_Pointer_Basic"); this->base_offset_ = (char *) this - (char *) base_addr; }
CONCRETE * ACE_Based_Pointer_Basic< CONCRETE >::addr | ( | void | ) | const [inline] |
Returns the underlying memory address of the smart pointer.
Definition at line 49 of file Based_Pointer_T.inl.
{ ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::addr"); if (this->target_ == -1) return 0; else return reinterpret_cast<CONCRETE *> (ACE_COMPUTE_BASED_POINTER (this)); }
void ACE_Based_Pointer_Basic< CONCRETE >::dump | ( | void | ) | const |
Dump the state of the object.
Definition at line 25 of file Based_Pointer_T.cpp.
{ #if defined (ACE_HAS_DUMP) ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::dump"); ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntarget_ = %d\n"), this->target_)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("base_offset_ = %d\n"), this->base_offset_)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("computed pointer = %x\n"), (CONCRETE *)(ACE_COMPUTE_BASED_POINTER (this)))); ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); #endif /* ACE_HAS_DUMP */ }
ACE_Based_Pointer_Basic< CONCRETE >::operator CONCRETE * | ( | ) | const [inline] |
Returns the underlying memory address of the smart pointer.
Definition at line 60 of file Based_Pointer_T.inl.
bool ACE_Based_Pointer_Basic< CONCRETE >::operator!= | ( | const ACE_Based_Pointer_Basic< CONCRETE > & | rhs | ) | const [inline] |
Inequality operator.
Definition at line 91 of file Based_Pointer_T.inl.
{ ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator !="); return !(*this == rhs); }
CONCRETE ACE_Based_Pointer_Basic< CONCRETE >::operator* | ( | void | ) | const [inline] |
Dereference operator.
Definition at line 42 of file Based_Pointer_T.inl.
{ ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator *"); return *reinterpret_cast<CONCRETE *> (ACE_COMPUTE_BASED_POINTER (this)); }
void ACE_Based_Pointer_Basic< CONCRETE >::operator+= | ( | int | index | ) | [inline] |
Increment operator.
Definition at line 77 of file Based_Pointer_T.inl.
{ ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator +="); this->base_offset_ += (index * sizeof (CONCRETE)); }
bool ACE_Based_Pointer_Basic< CONCRETE >::operator< | ( | const ACE_Based_Pointer_Basic< CONCRETE > & | rhs | ) | const [inline] |
Less than operator.
Definition at line 98 of file Based_Pointer_T.inl.
{ ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator <"); return ACE_COMPUTE_BASED_POINTER (this) < ACE_COMPUTE_BASED_POINTER (&rhs); }
bool ACE_Based_Pointer_Basic< CONCRETE >::operator<= | ( | const ACE_Based_Pointer_Basic< CONCRETE > & | rhs | ) | const [inline] |
Less than or equal operator.
Definition at line 105 of file Based_Pointer_T.inl.
{ ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator <="); return ACE_COMPUTE_BASED_POINTER (this) <= ACE_COMPUTE_BASED_POINTER (&rhs); }
void ACE_Based_Pointer_Basic< CONCRETE >::operator= | ( | const ACE_Based_Pointer_Basic< CONCRETE > & | rhs | ) | [inline] |
Pseudo-assignment operator.
Definition at line 126 of file Based_Pointer_T.inl.
void ACE_Based_Pointer_Basic< CONCRETE >::operator= | ( | CONCRETE * | from | ) | [inline] |
Pseudo-assignment operator.
Reimplemented in ACE_Based_Pointer< CONCRETE >.
Definition at line 18 of file Based_Pointer_T.inl.
{ ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator ="); if (rhs == 0) // Store a value of <target_> that indicate "NULL" pointer. this->target_ = -1; else this->target_ = ((char *) rhs - ((char *) this - this->base_offset_)); }
bool ACE_Based_Pointer_Basic< CONCRETE >::operator== | ( | const ACE_Based_Pointer_Basic< CONCRETE > & | rhs | ) | const [inline] |
Equality operator.
Definition at line 84 of file Based_Pointer_T.inl.
{ ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator =="); return ACE_COMPUTE_BASED_POINTER (this) == ACE_COMPUTE_BASED_POINTER (&rhs); }
bool ACE_Based_Pointer_Basic< CONCRETE >::operator> | ( | const ACE_Based_Pointer_Basic< CONCRETE > & | rhs | ) | const [inline] |
Greater than operator.
Definition at line 112 of file Based_Pointer_T.inl.
{ ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator >"); return ACE_COMPUTE_BASED_POINTER (this) > ACE_COMPUTE_BASED_POINTER (&rhs); }
bool ACE_Based_Pointer_Basic< CONCRETE >::operator>= | ( | const ACE_Based_Pointer_Basic< CONCRETE > & | rhs | ) | const [inline] |
Greater than or equal operator.
Definition at line 119 of file Based_Pointer_T.inl.
{ ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator >="); return ACE_COMPUTE_BASED_POINTER (this) >= ACE_COMPUTE_BASED_POINTER (&rhs); }
CONCRETE ACE_Based_Pointer_Basic< CONCRETE >::operator[] | ( | int | index | ) | const [inline] |
Subscript operator.
Definition at line 68 of file Based_Pointer_T.inl.
{ ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator []"); CONCRETE *c = reinterpret_cast<CONCRETE *> (ACE_COMPUTE_BASED_POINTER (this)); return c[index]; }
ACE_Based_Pointer_Basic< CONCRETE >::ACE_ALLOC_HOOK_DECLARE |
Declare the dynamic allocation hooks.
Definition at line 136 of file Based_Pointer_T.h.
ptrdiff_t ACE_Based_Pointer_Basic< CONCRETE >::base_offset_ [protected] |
Keep track of our offset from the base pointer.
Definition at line 145 of file Based_Pointer_T.h.
ptrdiff_t ACE_Based_Pointer_Basic< CONCRETE >::target_ [protected] |
Definition at line 142 of file Based_Pointer_T.h.