3 //=============================================================================
5 * @file Managed_Object.h
7 * @author David L. Levine <levine@cs.wustl.edu>
9 //=============================================================================
11 #ifndef ACE_MANAGED_OBJECT_H
12 #define ACE_MANAGED_OBJECT_H
14 #include /**/ "ace/pre.h"
16 #include /**/ "ace/config-all.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "ace/Object_Manager.h"
23 #include "ace/Global_Macros.h"
25 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
28 * @class ACE_Cleanup_Adapter
30 * @brief Adapter for ACE_Cleanup objects that allows them to be readily
31 * managed by the ACE_Object_Manager.
33 * This template class adapts an object of any type to be an
34 * ACE_Cleanup object. The object can then be destroyed
35 * type-safely by the ACE_Object_Manager. This class is
36 * typically used to replace a cast; but, it's a bit cleaner and
37 * allows insertion of, say, run-time type identification
38 * internally if desired.
41 class ACE_Cleanup_Adapter
: public ACE_Cleanup
44 /// Default constructor.
45 ACE_Cleanup_Adapter (void);
47 /// Virtual destructor, needed by some compilers for vtable placement.
48 virtual ~ACE_Cleanup_Adapter (void);
50 /// Accessor for contained object.
54 ACE_UNIMPLEMENTED_FUNC (ACE_Cleanup_Adapter (const ACE_Cleanup_Adapter
<TYPE
> &))
55 ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Cleanup_Adapter
<TYPE
> &))
62 * @class ACE_Managed_Object
64 * @brief Wrapper for interface to allocate an object managed by the
67 * This template class wraps an interface that is used to
68 * allocate and access an object that is managed by the
69 * ACE_Object_Manager. Because static template member functions
70 * are not supported by some compilers, it is a separate
72 * This interface is typically used to replace a static object
73 * with one that is dynamically allocated. It helps to avoid
74 * problems with order of static object
75 * construction/destruction. Managed objects won't be allocated
76 * until needed, but should be allocated when first needed. And
77 * they are destroyed in the reverse order of construction.
78 * <get_preallocated_object> accesses a "preallocated" object,
79 * i.e., one that is identified by a value in the
80 * ACE_Object_Manager:: Preallocated_Object enum. These objects
81 * are used internally by the ACE library.
82 * Hooks are provided for the application to preallocate objects
83 * via the same mechanism.
84 * ACE_APPLICATION_PREALLOCATED_OBJECT_DECLARATIONS can be used
85 * to define enum values;
86 * ACE_APPLICATION_PREALLOCATED_OBJECT_DEFINITIONS can be used
87 * to define the corresponding objects. The format of the ACE
88 * internal library definitions should be followed. And
89 * similarly, ACE_APPLICATION_PREALLOCATED_ARRAY_DECLARATIONS
90 * and ACE_APPLICATION_PREALLOCATED_ARRAY_DEFINITIONS can be
91 * used to preallocate arrays.
92 * By default, preallocation uses dynamic allocation. The
93 * preallocated objects and arrays are allocated off the heap in
94 * the ACE_Object_Manager constructor. To statically place the
95 * preallocated objects in program global data instead of on the
96 * heap, #define ACE_HAS_STATIC_PREALLOCATION prior to building
100 class ACE_Managed_Object
103 static TYPE
*get_preallocated_object (ACE_Object_Manager::Preallocated_Object identifier
)
105 // The preallocated objects are in a separate, "read-only" array so
106 // that this function doesn't need a lock. Also, because it is
107 // intended _only_ for use with hard-code values, it performs no
108 // range checking on "id".
110 // Cast the return type of the the object pointer based
111 // on the type of the function template parameter.
112 return &((ACE_Cleanup_Adapter
<TYPE
> *)
113 ACE_Object_Manager::preallocated_object
[identifier
])->object ();
115 // Get the preallocated object identified by "id". Returns a
116 // pointer to the object. Beware: no error indication is provided,
117 // because it can _only_ be used for accessing preallocated objects.
118 // @note The function definition is inlined here so that it compiles
119 // on AIX 4.1 w/xlC v. 3.01.
121 static TYPE
*get_preallocated_array (ACE_Object_Manager::Preallocated_Array identifier
)
123 // The preallocated array are in a separate, "read-only" array so
124 // that this function doesn't need a lock. Also, because it is
125 // intended _only_ for use with hard-code values, it performs no
126 // range checking on "id".
128 // Cast the return type of the the object pointer based
129 // on the type of the function template parameter.
130 return &((ACE_Cleanup_Adapter
<TYPE
> *)
131 ACE_Object_Manager::preallocated_array
[identifier
])->object ();
133 // Get the preallocated array identified by "id". Returns a
134 // pointer to the array. Beware: no error indication is provided,
135 // because it can _only_ be used for accessing preallocated arrays.
136 // @note The function definition is inlined here so that it compiles
137 // on AIX 4.1 w/xlC v. 3.01.
140 // Disallow instantiation of this class.
141 ACE_UNIMPLEMENTED_FUNC (ACE_Managed_Object (void))
144 ACE_UNIMPLEMENTED_FUNC (ACE_Managed_Object (const ACE_Managed_Object
<TYPE
> &))
145 ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Managed_Object
<TYPE
> &))
148 ACE_END_VERSIONED_NAMESPACE_DECL
150 #if defined (__ACE_INLINE__)
151 #include "ace/Managed_Object.inl"
152 #endif /* __ACE_INLINE__ */
154 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
155 #include "ace/Managed_Object.cpp"
156 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
158 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
159 #pragma implementation ("Managed_Object.cpp")
160 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
162 #include /**/ "ace/post.h"
164 #endif /* ACE_MANAGED_OBJECT_H */