1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
/* -*- C++ -*- */
// $Id$
// ============================================================================
//
// = LIBRARY
// ace
//
// = FILENAME
// Managed_Object.h
//
// = AUTHORS
// David L. Levine
//
// ============================================================================
#if !defined (ACE_MANAGED_OBJECT_H)
#define ACE_MANAGED_OBJECT_H
#include "ace/OS.h"
template <class TYPE>
class ACE_Managed_Cleanup : public ACE_Cleanup
// = TITLE
// Adapter for ACE_Cleanup objects that allows them to be readily
// managed by the ACE_Object_Manager.
//
// = DESCRIPTION
// This template class wraps adapts an object of any type to be
// an ACE_Cleanup object. It can then be destroyed type-safely
// by the ACE_Object_Manager.
{
public:
ACE_Managed_Cleanup (void);
TYPE &object (void);
private:
TYPE object_;
};
template <class TYPE>
class ACE_Managed_Object
// = TITLE
// Wrapper for interface to allocate an object managed by the
// ACE_Object_Manager.
//
// = DESCRIPTION
// This template class wraps an interface that is used to
// allocate and access an object that is managed by the
// ACE_Object_Manager. Because static template member functions
// are not supported by most compilers, it is a separate
// (template) class.
//
// This interface is typically used to replace a static object
// with one that is dynamically allocated. It helps to avoid
// problems with order of static object construction/destruction.
// Managed objects won't be allocated until needed, but should
// be allocated when first needed. And they are destroyed in
// the reverse order of construction.
//
// To use the get_object () interface, the caller must provide
// an identifier and an object pointer. The identifer (usually)
// has a value of 0 the first time get_object () is called, in
// which case a new instance of the object is allocated on the
// heap. (See the description of get_object () for return
// values.)
//
// Subsequent calls to get_object (), with that identifier, will
// return the pointer to the identified object. The caller is
// responsible for ensuring type safety by not casting the pointer
// that it holds in calls to get_object ().
//
// get_preallocated_object () accesses a "preallocated" object,
// i.e., one that is identified by a value in the
// ACE_Object_Manager:: Preallocated_Object enum. These
// objects are used internally by the ACE library.
//
// Hooks are provided for the application to preallocate objects
// via the same mechanism.
// ACE_APPLICATION_PREALLOCATED_OBJECT_DECLARATIONS can be used
// to define enum values;
// ACE_APPLICATION_PREALLOCATED_OBJECT_DEFINITIONS can be used
// to define the corresponding objects. The format of the ACE
// internal library definitions should be followed. And similarly,
// ACE_APPLICATION_PREALLOCATED_ARRAY_DECLARATIONS and
// ACE_APPLICATION_PREALLOCATED_ARRAY_DEFINITIONS can be used to
// preallocate arrays.
//
// By default, preallocation uses dynamic allocation. The
// preallocated objects and arrays are allocated off the heap in
// the ACE_Object_Manager constructor. The statically place the
// preallocated objects in program global data instead of on the
// heap, #define ACE_HAS_STATIC_PREALLOCATION prior to building
// the ACE library.
{
public:
static int get_object (int &id, TYPE *&object);
// Get the object identified by "id". If "id" is 0, allocates a new
// instance, and sets "id" to the new identifier for that instance.
// Returns 0 on success. On failure, returns -1 and sets errno to:
// ENOENT if the id is non-zero and unknown,
// ENOMEM if insufficient virtual memory to allocate a new instance, or
// ENOSPC if no more table slots are available: see the
// ACE_MAX_MANAGED_OBJECTS config variable.
static
TYPE *get_preallocated_object (ACE_Object_Manager::Preallocated_Object id);
// Get the preallocated object identified by "id". Returns a
// pointer to the object. Beware: no error indication is provided,
// because it can _only_ be used for accessing preallocated objects.
static
TYPE *get_preallocated_array (ACE_Object_Manager::Preallocated_Array id);
// Get the preallocated array identified by "id". Returns a
// pointer to the array. Beware: no error indication is provided,
// because it can _only_ be used for accessing preallocated arrays.
private:
// Disallow instantiation of this class.
ACE_UNIMPLEMENTED_FUNC (ACE_Managed_Object ())
ACE_UNIMPLEMENTED_FUNC (ACE_Managed_Object (const ACE_Managed_Object &))
ACE_UNIMPLEMENTED_FUNC (ACE_Managed_Object &operator=
(const ACE_Managed_Object &))
friend class this_prevents_compiler_warning_about_only_private_constructors;
};
#if defined (__ACE_INLINE__)
#include "ace/Managed_Object.i"
#endif /* __ACE_INLINE__ */
#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "ace/Managed_Object.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
#pragma implementation ("Managed_Object.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
#endif /* ACE_MANAGED_OBJECT_H */
|