Based_Pointer_T.h

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

Generated on Thu Nov 9 09:41:47 2006 for ACE by doxygen 1.3.6