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

Based_Pointer_T.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Based_Pointer_T.h
00006  *
00007  *  $Id: Based_Pointer_T.h,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Dietrich Quehl <Dietrich.Quehl@med.siemens.de>
00010  *  @author Douglas C. Schmidt <schmidt@.cs.wustl.edu>
00011  */
00012 //=============================================================================
00013 
00014 #ifndef ACE_BASED_POINTER_T_H
00015 #define ACE_BASED_POINTER_T_H
00016 
00017 #include "ace/pre.h"
00018 
00019 #include "ace/config-all.h"
00020 #include "ace/Trace.h"
00021 
00022 #if defined (_MSC_VER)
00023 // Suppress warning e.g. "return type for
00024 // 'ACE_Based_Pointer<long>::operator ->' is 'long *' (i.e., not a UDT
00025 // or reference to a UDT.  Will produce errors if applied using infix
00026 // notation)"
00027 #pragma warning(disable: 4284)
00028 #endif /* _MSC_VER */
00029 
00030 /**
00031  * @class ACE_Based_Pointer_Basic
00032  *
00033  * @brief A proxy that keeps track of the relative offset of a "pointer"
00034  * from its base address.
00035  * This class makes it possible to transparently use "pointers" in
00036  * shared memory as easily as programming with pointers to local
00037  * memory.  In particular, we don't need to ensure that the base
00038  * addresses of all the pointers are mapped into separate
00039  * processes at the same absolute memory base address.
00040  */
00041 template <class CONCRETE>
00042 class ACE_Based_Pointer_Basic
00043 {
00044 public:
00045   /**
00046    * This constructor initializes the <base_offset_> by asking the
00047    * <ACE_BASED_POINTER_REPOSITORY> Singleton for the base address of
00048    * the memory region within which it is instantiated.  Two results
00049    * are possible:
00050    *
00051    * 1. An <ACE_*_Memory_Pool> has stored a base address/size pair and the
00052    *    new based-pointer instance is located between the base address and
00053    *    the base address + size - 1.  In this case, the repository
00054    *    returns the base address.
00055    *
00056    * 2. No suitable address/size pair was found.  The repository
00057    *    assumes an address in the regular (not mapped) virtual address
00058    *    space of the process and returns 0.  In this case, the
00059    *    based-pointer uses its address as an offset to it's base
00060    *    address 0.
00061    */
00062   ACE_Based_Pointer_Basic (void);
00063 
00064   /**
00065    * Initialize this object using the <initial> pointer.  This
00066    * constructor initializes the <base_offset_> by asking the
00067    * <ACE_BASED_POINTER_REPOSITORY> Singleton for the base address of
00068    * the memory region within which it is instantiated.  Three results
00069    * are possible:
00070    *
00071    * 1. An <ACE_*_Memory_Pool> has stored a base address/size pair and the
00072    *    new based-pointer instance is located between the base address and
00073    *    the base address + size - 1.  In this case, the repository
00074    *    returns the base address.
00075    *
00076    * 2. No suitable address/size pair was found.  The repository
00077    *    assumes an address in the regular (not mapped) virtual address
00078    *    space of the process and returns 0.  In this case, the
00079    *    based-pointer uses its address as an offset to its base
00080    *    address 0.
00081    *
00082    * 3. If <initial> is 0 then set the value of <target_> to -1, which
00083    *    indicates a "NULL" pointer.
00084    */
00085   ACE_Based_Pointer_Basic (CONCRETE *initial);
00086 
00087   /// Copy constructor.
00088   ACE_Based_Pointer_Basic (const ACE_Based_Pointer_Basic<CONCRETE> &);
00089 
00090   /// Constructor for know base address. <o> is only used to
00091   /// resolve overload ambiguity.
00092   ACE_Based_Pointer_Basic (const void *base_addr, int o);
00093 
00094   /// Pseudo-assignment operator.
00095   void operator = (CONCRETE *from);
00096 
00097   /// Pseudo-assignment operator.
00098   void operator = (const ACE_Based_Pointer_Basic<CONCRETE> &);
00099 
00100   /// Dereference operator.
00101   CONCRETE operator * (void) const;
00102 
00103   /// Less than operator.
00104   int operator < (const ACE_Based_Pointer_Basic<CONCRETE> &) const;
00105 
00106   /// Less than or equal operator.
00107   int operator <= (const ACE_Based_Pointer_Basic<CONCRETE> &) const;
00108 
00109   /// Greater than operator.
00110   int operator > (const ACE_Based_Pointer_Basic<CONCRETE> &) const;
00111 
00112   /// Greater than or equal operator.
00113   int operator >= (const ACE_Based_Pointer_Basic<CONCRETE> &) const;
00114 
00115   /// Equality operator.
00116   int operator == (const ACE_Based_Pointer_Basic<CONCRETE> &) const;
00117 
00118   /// Inequality operator.
00119   int operator != (const ACE_Based_Pointer_Basic<CONCRETE> &) const;
00120 
00121   /// Subscript operator.
00122   CONCRETE operator [](int index) const;
00123 
00124   /// Increment operator.
00125   void operator+= (int index);
00126 
00127   /// Returns the underlying memory address of the smart pointer.
00128   operator CONCRETE *() const;
00129 
00130   /// Returns the underlying memory address of the smart pointer.
00131   CONCRETE *addr (void) const;
00132 
00133   /// Declare the dynamic allocation hooks.
00134   ACE_ALLOC_HOOK_DECLARE;
00135 
00136   /// Dump the state of the object.
00137   void dump (void) const;
00138 
00139 protected:
00140   long target_;
00141 
00142   /// Keep track of our offset from the base pointer.
00143   long base_offset_;
00144 };
00145 
00146 /**
00147  * @class ACE_Based_Pointer
00148  *
00149  * @brief A smart proxy that keeps track of the relative offset of a
00150  * "pointer" from its base address.
00151  *
00152  * This class makes it possible to transparently use "pointers" in
00153  * shared memory as easily as programming with pointers to local
00154  * memory by overloading the C++ delegation operator ->().
00155  */
00156 template <class CONCRETE>
00157 class ACE_Based_Pointer : public ACE_Based_Pointer_Basic<CONCRETE>
00158 {
00159 public:
00160   // = Initialization method.
00161   /// Constructor.  See constructor for <ACE_Based_Pointer_Basic> for
00162   /// details.
00163   ACE_Based_Pointer (void);
00164 
00165   /// Initialize this object using the <initial> pointer.  See
00166   /// constructor for <ACE_Based_Pointer_Basic> for details.
00167   ACE_Based_Pointer (CONCRETE *initial);
00168 
00169   /// Initialize this object with known <base_addr>.  <dummy> is
00170   /// a dummy value used to resolve overload ambiguity and it
00171   /// otherwise ignored.
00172   ACE_Based_Pointer (const void *base_addr, int dummy);
00173 
00174   /// Copy constructor (not implemented yet).
00175   ACE_Based_Pointer (const ACE_Based_Pointer<CONCRETE> &);
00176 
00177   /// Assignment operator.
00178   void operator = (const ACE_Based_Pointer<CONCRETE> &);
00179 
00180   /// Pseudo-assignment operator.
00181   void operator = (CONCRETE *from);
00182 
00183   /// The C++ "delegation operator".
00184   CONCRETE *operator-> (void);
00185 };
00186 
00187 #if defined (__ACE_INLINE__)
00188 #include "ace/Based_Pointer_T.i"
00189 #endif /* __ACE_INLINE__ */
00190 
00191 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00192 #include "ace/Based_Pointer_T.cpp"
00193 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00194 
00195 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00196 #pragma implementation ("Based_Pointer_T.cpp")
00197 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00198 
00199 #include "ace/post.h"
00200 
00201 #endif /* ACE_BASED_POINTER_T_H */

Generated on Mon Jun 16 11:19:12 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002