Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Based_Pointer_T.h
blob254371f305e8781da857f417d4a28fc3beb0cbd0
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Based_Pointer_T.h
7 * @author Dietrich Quehl <Dietrich.Quehl@med.siemens.de>
8 * @author Douglas C. Schmidt <schmidt@.cs.wustl.edu>
9 */
10 //=============================================================================
12 #ifndef ACE_BASED_POINTER_T_H
13 #define ACE_BASED_POINTER_T_H
15 #include /**/ "ace/pre.h"
17 #include /**/ "ace/config-all.h"
18 #include "ace/Basic_Types.h"
20 #if defined (_MSC_VER)
21 // Suppress warning e.g. "return type for
22 // 'ACE_Based_Pointer<long>::operator ->' is 'long *' (i.e., not a UDT
23 // or reference to a UDT. Will produce errors if applied using infix
24 // notation)"
25 #pragma warning(disable: 4284)
26 #endif /* _MSC_VER */
28 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 /**
31 * @class ACE_Based_Pointer_Basic
33 * @brief A proxy that keeps track of the relative offset of a "pointer"
34 * from its base address.
35 * This class makes it possible to transparently use "pointers" in
36 * shared memory as easily as programming with pointers to local
37 * memory. In particular, we don't need to ensure that the base
38 * addresses of all the pointers are mapped into separate
39 * processes at the same absolute memory base address.
41 template <class CONCRETE>
42 class ACE_Based_Pointer_Basic
44 public:
45 /**
46 * This constructor initializes the <base_offset_> by asking the
47 * <ACE_BASED_POINTER_REPOSITORY> Singleton for the base address of
48 * the memory region within which it is instantiated. Two results
49 * are possible:
51 * 1. An <ACE_*_Memory_Pool> has stored a base address/size pair and the
52 * new based-pointer instance is located between the base address and
53 * the base address + size - 1. In this case, the repository
54 * returns the base address.
56 * 2. No suitable address/size pair was found. The repository
57 * assumes an address in the regular (not mapped) virtual address
58 * space of the process and returns 0. In this case, the
59 * based-pointer uses its address as an offset to it's base
60 * address 0.
62 ACE_Based_Pointer_Basic ();
64 /**
65 * Initialize this object using the @a initial pointer. This
66 * constructor initializes the <base_offset_> by asking the
67 * <ACE_BASED_POINTER_REPOSITORY> Singleton for the base address of
68 * the memory region within which it is instantiated. Three results
69 * are possible:
71 * 1. An <ACE_*_Memory_Pool> has stored a base address/size pair and the
72 * new based-pointer instance is located between the base address and
73 * the base address + size - 1. In this case, the repository
74 * returns the base address.
76 * 2. No suitable address/size pair was found. The repository
77 * assumes an address in the regular (not mapped) virtual address
78 * space of the process and returns 0. In this case, the
79 * based-pointer uses its address as an offset to its base
80 * address 0.
82 * 3. If @a initial is 0 then set the value of <target_> to -1, which
83 * indicates a "NULL" pointer.
85 ACE_Based_Pointer_Basic (CONCRETE *initial);
87 ACE_Based_Pointer_Basic (const ACE_Based_Pointer_Basic &) = delete;
88 ACE_Based_Pointer_Basic (ACE_Based_Pointer_Basic &&) = delete;
90 /// Constructor for know base address. @a o is only used to
91 /// resolve overload ambiguity.
92 ACE_Based_Pointer_Basic (const void *base_addr, int o);
94 void operator= (CONCRETE *from);
96 void operator= (const ACE_Based_Pointer_Basic &);
98 CONCRETE operator * () const;
100 bool operator< (const ACE_Based_Pointer_Basic &) const;
102 bool operator<= (const ACE_Based_Pointer_Basic &) const;
104 bool operator> (const ACE_Based_Pointer_Basic &) const;
106 bool operator>= (const ACE_Based_Pointer_Basic &) const;
108 bool operator== (const ACE_Based_Pointer_Basic &) const;
110 bool operator!= (const ACE_Based_Pointer_Basic &) const;
112 CONCRETE operator[] (int index) const;
114 void operator+= (int index);
116 /// Returns the underlying memory address of the smart pointer.
117 operator CONCRETE * () const;
119 /// Returns the underlying memory address of the smart pointer.
120 CONCRETE *addr () const;
122 /// Declare the dynamic allocation hooks.
123 ACE_ALLOC_HOOK_DECLARE;
125 /// Dump the state of the object.
126 void dump () const;
128 protected:
129 ptrdiff_t target_;
131 /// Keep track of our offset from the base pointer.
132 ptrdiff_t base_offset_;
136 * @class ACE_Based_Pointer
138 * @brief A smart proxy that keeps track of the relative offset of a
139 * "pointer" from its base address.
141 * This class makes it possible to transparently use "pointers" in
142 * shared memory as easily as programming with pointers to local
143 * memory by overloading the C++ delegation operator ->().
145 template <class CONCRETE>
146 class ACE_Based_Pointer : public ACE_Based_Pointer_Basic<CONCRETE>
148 public:
149 /// Constructor. See constructor for ACE_Based_Pointer_Basic for
150 /// details.
151 ACE_Based_Pointer ();
153 /// Initialize this object using the <initial> pointer. See
154 /// constructor for ACE_Based_Pointer_Basic for details.
155 ACE_Based_Pointer (CONCRETE *initial);
157 /// Initialize this object with known @a base_addr. @a dummy is
158 /// a dummy value used to resolve overload ambiguity and it
159 /// otherwise ignored.
160 ACE_Based_Pointer (const void *base_addr, int dummy);
162 ACE_Based_Pointer (const ACE_Based_Pointer &) = delete;
163 ACE_Based_Pointer (ACE_Based_Pointer &&) = delete;
165 void operator= (const ACE_Based_Pointer &);
167 /// Pseudo-assignment operator.
168 void operator = (CONCRETE *from);
170 CONCRETE *operator-> ();
173 ACE_END_VERSIONED_NAMESPACE_DECL
175 #if defined (__ACE_INLINE__)
176 #include "ace/Based_Pointer_T.inl"
177 #endif /* __ACE_INLINE__ */
179 #include "ace/Based_Pointer_T.cpp"
181 #include /**/ "ace/post.h"
183 #endif /* ACE_BASED_POINTER_T_H */