Also use Objects as part of an operation but as a result don't generate Any operation...
[ACE_TAO.git] / ACE / ace / Based_Pointer_T.h
blob71432eb1e6077ea487fb38e80d08821e5774e0df
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 (void);
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 /// Copy constructor.
88 ACE_Based_Pointer_Basic (const ACE_Based_Pointer_Basic<CONCRETE> &);
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 /// Pseudo-assignment operator.
95 void operator = (CONCRETE *from);
97 /// Pseudo-assignment operator.
98 void operator = (const ACE_Based_Pointer_Basic<CONCRETE> &);
100 /// Dereference operator.
101 CONCRETE operator * (void) const;
103 /// Less than operator.
104 bool operator < (const ACE_Based_Pointer_Basic<CONCRETE> &) const;
106 /// Less than or equal operator.
107 bool operator <= (const ACE_Based_Pointer_Basic<CONCRETE> &) const;
109 /// Greater than operator.
110 bool operator > (const ACE_Based_Pointer_Basic<CONCRETE> &) const;
112 /// Greater than or equal operator.
113 bool operator >= (const ACE_Based_Pointer_Basic<CONCRETE> &) const;
115 /// Equality operator.
116 bool operator == (const ACE_Based_Pointer_Basic<CONCRETE> &) const;
118 /// Inequality operator.
119 bool operator != (const ACE_Based_Pointer_Basic<CONCRETE> &) const;
121 /// Subscript operator.
122 CONCRETE operator [](int index) const;
124 /// Increment operator.
125 void operator+= (int index);
127 /// Returns the underlying memory address of the smart pointer.
128 operator CONCRETE *() const;
130 /// Returns the underlying memory address of the smart pointer.
131 CONCRETE *addr (void) const;
133 /// Declare the dynamic allocation hooks.
134 ACE_ALLOC_HOOK_DECLARE;
136 /// Dump the state of the object.
137 void dump (void) const;
139 protected:
140 ptrdiff_t target_;
142 /// Keep track of our offset from the base pointer.
143 ptrdiff_t base_offset_;
147 * @class ACE_Based_Pointer
149 * @brief A smart proxy that keeps track of the relative offset of a
150 * "pointer" from its base address.
152 * This class makes it possible to transparently use "pointers" in
153 * shared memory as easily as programming with pointers to local
154 * memory by overloading the C++ delegation operator ->().
156 template <class CONCRETE>
157 class ACE_Based_Pointer : public ACE_Based_Pointer_Basic<CONCRETE>
159 public:
160 /// Constructor. See constructor for ACE_Based_Pointer_Basic for
161 /// details.
162 ACE_Based_Pointer (void);
164 /// Initialize this object using the <initial> pointer. See
165 /// constructor for ACE_Based_Pointer_Basic for details.
166 ACE_Based_Pointer (CONCRETE *initial);
168 /// Initialize this object with known @a base_addr. @a dummy is
169 /// a dummy value used to resolve overload ambiguity and it
170 /// otherwise ignored.
171 ACE_Based_Pointer (const void *base_addr, int dummy);
173 /// Copy constructor (not implemented yet).
174 ACE_Based_Pointer (const ACE_Based_Pointer<CONCRETE> &);
176 /// Assignment operator.
177 void operator = (const ACE_Based_Pointer<CONCRETE> &);
179 /// Pseudo-assignment operator.
180 void operator = (CONCRETE *from);
182 /// The C++ "delegation operator".
183 CONCRETE *operator-> (void);
186 ACE_END_VERSIONED_NAMESPACE_DECL
188 #if defined (__ACE_INLINE__)
189 #include "ace/Based_Pointer_T.inl"
190 #endif /* __ACE_INLINE__ */
192 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
193 #include "ace/Based_Pointer_T.cpp"
194 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
196 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
197 #pragma implementation ("Based_Pointer_T.cpp")
198 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
200 #include /**/ "ace/post.h"
202 #endif /* ACE_BASED_POINTER_T_H */