File: ACE_Singleton.3

package info (click to toggle)
ace 5.2.1-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 26,856 kB
  • ctags: 18,677
  • sloc: cpp: 171,831; makefile: 48,840; sh: 10,192; perl: 8,582; exp: 787; yacc: 387; lex: 140; csh: 20
file content (133 lines) | stat: -rw-r--r-- 4,705 bytes parent folder | download
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
.TH ACE_Singleton 3 "1 Dec 2001" "ACE" \" -*- nroff -*-
.ad l
.nh
.SH NAME
ACE_Singleton \- A Singleton Adapter uses the Adapter pattern to turn ordinary classes into Singletons optimized with the Double-Checked Locking optimization pattern. 
.SH SYNOPSIS
.br
.PP
\fC#include <Singleton.h>\fR
.PP
Inherits \fBACE_Cleanup\fR.
.PP
Inherited by \fBACE_Unmanaged_Singleton\fR.
.PP
.SS Public Methods

.in +1c
.ti -1c
.RI "virtual void \fBcleanup\fR (void *param = 0)"
.br
.RI "\fICleanup method, used by  to destroy the .\fR"
.in -1c
.SS Static Public Methods

.in +1c
.ti -1c
.RI "TYPE* \fBinstance\fR (void)"
.br
.RI "\fIGlobal access point to the Singleton.\fR"
.ti -1c
.RI "void \fBdump\fR (void)"
.br
.RI "\fIDump the state of the object.\fR"
.in -1c
.SS Protected Methods

.in +1c
.ti -1c
.RI "\fBACE_Singleton\fR (void)"
.br
.RI "\fIDefault constructor.\fR"
.in -1c
.SS Protected Attributes

.in +1c
.ti -1c
.RI "TYPE \fBinstance_\fR"
.br
.RI "\fIContained instance.\fR"
.in -1c
.SS Static Protected Methods

.in +1c
.ti -1c
.RI "ACE_Singleton<TYPE, ACE_LOCK>*& \fBinstance_i\fR (void)"
.br
.RI "\fIGet pointer to the Singleton instance.\fR"
.in -1c
.SS Static Protected Attributes

.in +1c
.ti -1c
.RI "ACE_Singleton<TYPE, ACE_LOCK>* \fBsingleton_\fR"
.br
.RI "\fIPointer to the Singleton (\fBACE_Cleanup\fR) instance.\fR"
.in -1c
.SH DETAILED DESCRIPTION
.PP 

.SS template<class TYPE, class ACE_LOCK>  template class ACE_Singleton
A Singleton Adapter uses the Adapter pattern to turn ordinary classes into Singletons optimized with the Double-Checked Locking optimization pattern.
.PP
.PP
 This implementation is a slight variation on the GoF Singleton pattern. In particular, a single  > instance is allocated here, not a <TYPE> instance. The reason for this is to allow registration with the , so that the Singleton can be cleaned up when the process exits. For this scheme to work, a (static) <cleanup> function must be provided.  provides one so that TYPE doesn't need to. If you want to make sure that only the singleton instance of <T> is created, and that users cannot create their own instances of <T>, do the following to class <T>: (a) Make the constructor of <T> private (or protected) (b) Make Singleton a friend of <T> Here is an example: 
.PP
.nf

 * class foo
 * {
 * friend class ACE_Singleton<foo, ACE_Null_Mutex>;
 * private:
 * foo () { cout << "foo constructed" << endl; }
 * ~foo () { cout << "foo destroyed" << endl; }
 * };
 * typedef ACE_Singleton<foo, ACE_Null_Mutex> FOO;
 * 
.fi
.PP
NOTE: the best types to use for ACE_LOCK are \fBACE_Recursive_Thread_Mutex\fR and \fBACE_Null_Mutex\fR. \fBACE_Recursive_Thread_Mutex\fR should be used in multi-threaded programs in which it is possible for more than one thread to access the > instance. \fBACE_Null_Mutex\fR can be used otherwise. The reason that these types of locks are best has to do with their allocation by the \fBACE_Object_Manager\fR. Single \fBACE_Recursive_Thread_Mutex\fR and \fBACE_Null_Mutex\fR instances are used for all ACE_Singleton instantiations. However, other types of locks are allocated per ACE_Singleton instantiation. 
.PP
.SH CONSTRUCTOR & DESTRUCTOR DOCUMENTATION
.PP 
.SS template<classTYPE, classACE_LOCK> ACE_Singleton<TYPE, ACE_LOCK>::ACE_Singleton<TYPE, ACE_LOCK> (void)\fC [protected]\fR
.PP
Default constructor.
.PP
.SH MEMBER FUNCTION DOCUMENTATION
.PP 
.SS template<classTYPE, classACE_LOCK> void ACE_Singleton<TYPE, ACE_LOCK>::cleanup (void * param = 0)\fC [virtual]\fR
.PP
Cleanup method, used by  to destroy the .
.PP
Reimplemented from \fBACE_Cleanup\fR.
.SS template<classTYPE, classACE_LOCK> void ACE_Singleton<TYPE, ACE_LOCK>::dump (void)\fC [static]\fR
.PP
Dump the state of the object.
.PP
Reimplemented in \fBACE_Unmanaged_Singleton\fR.
.SS template<classTYPE, classACE_LOCK> TYPE * ACE_Singleton<TYPE, ACE_LOCK>::instance (void)\fC [static]\fR
.PP
Global access point to the Singleton.
.PP
Reimplemented in \fBACE_Unmanaged_Singleton\fR.
.SS template<classTYPE, classACE_LOCK> ACE_Singleton< TYPE,ACE_LOCK >*& ACE_Singleton<TYPE, ACE_LOCK>::instance_i (void)\fC [static, protected]\fR
.PP
Get pointer to the Singleton instance.
.PP
Reimplemented in \fBACE_Unmanaged_Singleton\fR.
.SH MEMBER DATA DOCUMENTATION
.PP 
.SS template<classTYPE, classACE_LOCK> TYPE ACE_Singleton<TYPE, ACE_LOCK>::instance_\fC [protected]\fR
.PP
Contained instance.
.PP
.SS template<classTYPE, classACE_LOCK> ACE_Singleton< TYPE,ACE_LOCK >* ACE_Singleton<TYPE, ACE_LOCK>::singleton_\fC [static, protected]\fR
.PP
Pointer to the Singleton (\fBACE_Cleanup\fR) instance.
.PP
Reimplemented in \fBACE_Unmanaged_Singleton\fR.

.SH AUTHOR
.PP 
Generated automatically by Doxygen for ACE from the source code.