Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Based_Pointer_Basic Class Template Reference

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>

Inheritance diagram for ACE_Based_Pointer_Basic:

Inheritance graph
[legend]
List of all members.

Public Methods

 ACE_Based_Pointer_Basic (void)
 ACE_Based_Pointer_Basic (CONCRETE *initial)
 ACE_Based_Pointer_Basic (const ACE_Based_Pointer_Basic< CONCRETE > &)
 Copy constructor. More...

 ACE_Based_Pointer_Basic (const void *base_addr, int o)
 Constructor for know base address. <o> is only used to resolve overload ambiguity. More...

void operator= (CONCRETE *from)
 Pseudo-assignment operator. More...

void operator= (const ACE_Based_Pointer_Basic< CONCRETE > &)
 Pseudo-assignment operator. More...

CONCRETE operator * (void) const
 Dereference operator. More...

int operator< (const ACE_Based_Pointer_Basic< CONCRETE > &) const
 Less than operator. More...

int operator<= (const ACE_Based_Pointer_Basic< CONCRETE > &) const
 Less than or equal operator. More...

int operator> (const ACE_Based_Pointer_Basic< CONCRETE > &) const
 Greater than operator. More...

int operator>= (const ACE_Based_Pointer_Basic< CONCRETE > &) const
 Greater than or equal operator. More...

int operator== (const ACE_Based_Pointer_Basic< CONCRETE > &) const
 Equality operator. More...

int operator!= (const ACE_Based_Pointer_Basic< CONCRETE > &) const
 Inequality operator. More...

CONCRETE operator[] (int index) const
 Subscript operator. More...

void operator+= (int index)
 Increment operator. More...

 operator CONCRETE * () const
 Returns the underlying memory address of the smart pointer. More...

CONCRETE * addr (void) const
 Returns the underlying memory address of the smart pointer. More...

void dump (void) const
 Dump the state of the object. More...


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Protected Attributes

long target_
long base_offset_
 Keep track of our offset from the base pointer. More...


Detailed Description

template<class CONCRETE>
class ACE_Based_Pointer_Basic< CONCRETE >

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 42 of file Based_Pointer_T.h.


Constructor & Destructor Documentation

template<class CONCRETE>
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 49 of file Based_Pointer_T.cpp.

References ACE_TRACE, base_offset_, and ACE_Singleton::instance.

00050   : target_ (0),
00051     base_offset_ (0)
00052 {
00053   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::ACE_Based_Pointer_Basic");
00054   void *base_addr = 0;
00055 
00056   // Find the base address associated with our <this> pointer.  Note
00057   // that it's ok for <find> to return 0, which simply indicates that
00058   // the address is not in memory-mapped virtual address space.
00059   ACE_BASED_POINTER_REPOSITORY::instance ()->find (this,
00060                                                    base_addr);
00061   this->base_offset_ = (char *) this - (char *) base_addr;
00062 }

template<class CONCRETE>
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 74 of file Based_Pointer_T.cpp.

References ACE_TRACE, base_offset_, ACE_Singleton::instance, and target_.

00075   : target_ (0),
00076     base_offset_ (0)
00077 {
00078   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::ACE_Based_Pointer_Basic");
00079 
00080   if (rhs == 0)
00081     // Store a value of <target_> that indicate "NULL" pointer.
00082     this->target_ = -1;
00083   else
00084     {
00085       void *base_addr = 0;
00086 
00087       // Find the base address associated with the <addr> pointer.
00088       // Note that it's ok for <find> to return 0, which simply
00089       // indicates that the address is not in memory-mapped virtual
00090       // address space.
00091       ACE_BASED_POINTER_REPOSITORY::instance ()->find (this,
00092                                                        base_addr);
00093       this->base_offset_ = (char *) this - (char *) base_addr;
00094       this->target_ = ((char *) rhs - (char *) base_addr);
00095     }
00096 }

template<class CONCRETE>
ACE_Based_Pointer_Basic< CONCRETE >::ACE_Based_Pointer_Basic const ACE_Based_Pointer_Basic< CONCRETE > &   
 

Copy constructor.

Definition at line 99 of file Based_Pointer_T.cpp.

References ACE_ASSERT, and ACE_TRACE.

00100 {
00101   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::ACE_Based_Pointer_Basic");
00102 
00103   ACE_ASSERT (0); // not implemented.
00104 }

template<class CONCRETE>
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 65 of file Based_Pointer_T.cpp.

References ACE_TRACE, and base_offset_.

00066   : target_ (0),
00067     base_offset_ (0)
00068 {
00069   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::ACE_Based_Pointer_Basic");
00070   this->base_offset_ = (char *) this - (char *) base_addr;
00071 }


Member Function Documentation

template<class CONCRETE>
ACE_INLINE CONCRETE * ACE_Based_Pointer_Basic< CONCRETE >::addr void    const
 

Returns the underlying memory address of the smart pointer.

Definition at line 46 of file Based_Pointer_T.i.

References ACE_COMPUTE_BASED_POINTER, ACE_TRACE, and target_.

Referenced by operator CONCRETE *, ACE_Based_Pointer::operator=, and operator=.

00047 {
00048   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::addr");
00049 
00050   if (this->target_ == -1)
00051     return 0;
00052   else
00053     return ACE_reinterpret_cast (CONCRETE *,
00054                                  ACE_COMPUTE_BASED_POINTER (this));
00055 }

template<class CONCRETE>
void ACE_Based_Pointer_Basic< CONCRETE >::dump void    const
 

Dump the state of the object.

Definition at line 23 of file Based_Pointer_T.cpp.

References ACE_BEGIN_DUMP, ACE_COMPUTE_BASED_POINTER, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.

00024 {
00025   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::dump");
00026 
00027   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00028   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ntarget_ = %d\n"), this->target_));
00029   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("base_offset_ = %d\n"), this->base_offset_));
00030   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("computed pointer = %x\n"), (CONCRETE *)(ACE_COMPUTE_BASED_POINTER (this))));
00031   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00032 }

template<class CONCRETE>
ACE_INLINE CONCRETE ACE_Based_Pointer_Basic< CONCRETE >::operator * void    const
 

Dereference operator.

Definition at line 38 of file Based_Pointer_T.i.

References ACE_COMPUTE_BASED_POINTER, and ACE_TRACE.

00039 {
00040   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator *");
00041   return *ACE_reinterpret_cast (CONCRETE *,
00042                                 ACE_COMPUTE_BASED_POINTER (this));
00043 }

template<class CONCRETE>
ACE_INLINE ACE_Based_Pointer_Basic< CONCRETE >::operator CONCRETE *   const
 

Returns the underlying memory address of the smart pointer.

Definition at line 58 of file Based_Pointer_T.i.

References ACE_TRACE, and addr.

00059 {
00060   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator CONCRETE *()");
00061 
00062   return this->addr ();
00063 }

template<class CONCRETE>
ACE_INLINE int ACE_Based_Pointer_Basic< CONCRETE >::operator!= const ACE_Based_Pointer_Basic< CONCRETE > &    const
 

Inequality operator.

Definition at line 89 of file Based_Pointer_T.i.

References ACE_TRACE.

00090 {
00091   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator !=");
00092   return !(*this == rhs);
00093 }

template<class CONCRETE>
ACE_INLINE void ACE_Based_Pointer_Basic< CONCRETE >::operator+= int    index
 

Increment operator.

Definition at line 75 of file Based_Pointer_T.i.

References ACE_TRACE, and base_offset_.

00076 {
00077   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator +=");
00078   this->base_offset_ += (index * sizeof (CONCRETE));
00079 }

template<class CONCRETE>
ACE_INLINE int ACE_Based_Pointer_Basic< CONCRETE >::operator< const ACE_Based_Pointer_Basic< CONCRETE > &    const
 

Less than operator.

Definition at line 96 of file Based_Pointer_T.i.

References ACE_COMPUTE_BASED_POINTER, and ACE_TRACE.

00097 {
00098   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator <");
00099   return ACE_COMPUTE_BASED_POINTER (this) < ACE_COMPUTE_BASED_POINTER (&rhs);
00100 }

template<class CONCRETE>
ACE_INLINE int ACE_Based_Pointer_Basic< CONCRETE >::operator<= const ACE_Based_Pointer_Basic< CONCRETE > &    const
 

Less than or equal operator.

Definition at line 103 of file Based_Pointer_T.i.

References ACE_COMPUTE_BASED_POINTER, and ACE_TRACE.

00104 {
00105   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator <=");
00106   return ACE_COMPUTE_BASED_POINTER (this) <= ACE_COMPUTE_BASED_POINTER (&rhs);
00107 }

template<class CONCRETE>
ACE_INLINE void ACE_Based_Pointer_Basic< CONCRETE >::operator= const ACE_Based_Pointer_Basic< CONCRETE > &   
 

Pseudo-assignment operator.

Definition at line 124 of file Based_Pointer_T.i.

References ACE_TRACE, and addr.

00125 {
00126   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator=");
00127   *this = rhs.addr ();
00128 }

template<class CONCRETE>
ACE_INLINE void ACE_Based_Pointer_Basic< CONCRETE >::operator= CONCRETE *    from
 

Pseudo-assignment operator.

Reimplemented in ACE_Based_Pointer.

Definition at line 14 of file Based_Pointer_T.i.

References ACE_TRACE, base_offset_, and target_.

00015 {
00016   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator =");
00017   if (rhs == 0)
00018     // Store a value of <target_> that indicate "NULL" pointer.
00019     this->target_ = -1;
00020   else
00021     this->target_ = ((char *) rhs
00022                      - ((char *) this - this->base_offset_));
00023 }

template<class CONCRETE>
ACE_INLINE int ACE_Based_Pointer_Basic< CONCRETE >::operator== const ACE_Based_Pointer_Basic< CONCRETE > &    const
 

Equality operator.

Definition at line 82 of file Based_Pointer_T.i.

References ACE_COMPUTE_BASED_POINTER, and ACE_TRACE.

00083 {
00084   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator ==");
00085   return ACE_COMPUTE_BASED_POINTER (this) == ACE_COMPUTE_BASED_POINTER (&rhs);
00086 }

template<class CONCRETE>
ACE_INLINE int ACE_Based_Pointer_Basic< CONCRETE >::operator> const ACE_Based_Pointer_Basic< CONCRETE > &    const
 

Greater than operator.

Definition at line 110 of file Based_Pointer_T.i.

References ACE_COMPUTE_BASED_POINTER, and ACE_TRACE.

00111 {
00112   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator >");
00113   return ACE_COMPUTE_BASED_POINTER (this) > ACE_COMPUTE_BASED_POINTER (&rhs);
00114 }

template<class CONCRETE>
ACE_INLINE int ACE_Based_Pointer_Basic< CONCRETE >::operator>= const ACE_Based_Pointer_Basic< CONCRETE > &    const
 

Greater than or equal operator.

Definition at line 117 of file Based_Pointer_T.i.

References ACE_COMPUTE_BASED_POINTER, and ACE_TRACE.

00118 {
00119   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator >=");
00120   return ACE_COMPUTE_BASED_POINTER (this) >= ACE_COMPUTE_BASED_POINTER (&rhs);
00121 }

template<class CONCRETE>
ACE_INLINE CONCRETE ACE_Based_Pointer_Basic< CONCRETE >::operator[] int    index const
 

Subscript operator.

Definition at line 66 of file Based_Pointer_T.i.

References ACE_COMPUTE_BASED_POINTER, and ACE_TRACE.

00067 {
00068   ACE_TRACE ("ACE_Based_Pointer_Basic<CONCRETE>::operator []");
00069   CONCRETE *c = ACE_reinterpret_cast (CONCRETE *,
00070                                       ACE_COMPUTE_BASED_POINTER (this));
00071   return c[index];
00072 }


Member Data Documentation

template<class CONCRETE>
ACE_Based_Pointer_Basic::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 134 of file Based_Pointer_T.h.

template<class CONCRETE>
long ACE_Based_Pointer_Basic::base_offset_ [protected]
 

Keep track of our offset from the base pointer.

Definition at line 143 of file Based_Pointer_T.h.

Referenced by ACE_Based_Pointer_Basic, operator+=, ACE_Based_Pointer::operator=, and operator=.

template<class CONCRETE>
long ACE_Based_Pointer_Basic::target_ [protected]
 

Definition at line 140 of file Based_Pointer_T.h.

Referenced by ACE_Based_Pointer_Basic, addr, ACE_Based_Pointer::operator=, and operator=.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:46:06 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002