2
0
mirror of https://github.com/boostorg/pool.git synced 2026-01-23 17:52:15 +00:00
Files
pool/doc/implementation/singleton.html
Stephen Cleary b7bc5bec08 Munged e-mail addresses
[SVN r20045]
2003-09-14 01:00:35 +00:00

94 lines
2.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>singleton - Singleton</TITLE>
<LINK HREF="../pool.css" REL="stylesheet" TYPE="text/css">
</HEAD>
<BODY>
<IMG SRC="../../../../c++boost.gif" WIDTH=276 HEIGHT=86 ALT="C++ Boost">
<H1 ALIGN=CENTER>singleton - Singleton</H1>
<P>
<H2>Introduction</H2>
<P>
detail/singleton.hpp provides a way to access a Singleton of a class type. This is <STRONG>not</STRONG> a general Singleton solution! It is restricted in that the class type must have a default constructor.
<P>
<H2>Synopsis</H2>
<PRE CLASS="code">namespace details {
namespace pool {
template &lt;typename T&gt;
class singleton_default
{
private:
singleton_default();
public:
typedef T object_type;
static object_type & instance();
};
} // namespace pool
} // namespace details</PRE>
<P>
<H2>Semantics</H2>
<P>
<TABLE BORDER ALIGN=CENTER>
<CAPTION><EM>Symbol Table</EM></CAPTION>
<TR><TH>Symbol<TH>Meaning
<TR><TD CLASS="code">T<TD>Any class with a non-throwing default constructor and non-throwing destructor
</TABLE>
<P>
<TABLE BORDER ALIGN=CENTER>
<CAPTION><EM>Requirements satisfied by <SPAN CLASS="code">singleton_default&lt;T&gt;</SPAN></EM></CAPTION>
<TR><TH>Expression<TH>Return Type<TH>Assertion/Note/Pre/Post-Condition
<TR><TD CLASS="code">singleton_default&lt;T&gt;::instance()<TD CLASS="code">T &amp;<TD>Returns a reference to the singleton instance
</TABLE>
<P>
<H2>Guarantees</H2>
<P>
The singleton instance is guaranteed to be constructed before <SPAN CLASS="code">main()</SPAN> begins, and destructed after <SPAN CLASS="code">main()</SPAN> ends. Furthermore, it is guaranteed to be constructed before the first call to <SPAN CLASS="code">singleton_default&lt;T&gt;::instance()</SPAN> is complete (even if called before <SPAN CLASS="code">main()</SPAN> begins). Thus, if there are not multiple threads running except within <SPAN CLASS="code">main()</SPAN>, and if all access to the singleton is restricted by mutexes, then this guarantee allows a thread-safe singleton.
<P>
<H2>Details</H2>
<P>
For details on how we provide the guarantees above, see the comments in the header file.
<P>
<H2>Dependencies</H2>
<P>
None.
<P>
<H2>Future Directions</H2>
<P>
This header may be replaced by a Boost singleton library.
<P>
<HR>
<P>
Copyright &copy; 2000, 2001 Stephen Cleary (scleary AT jerviswebb DOT com)
<P>
This file can be redistributed and/or modified under the terms found in <A HREF="../copyright.html">copyright.html</A>
<P>
This software and its documentation is provided &quot;as is&quot; without express or implied warranty, and with no claim as to its suitability for any purpose.
</BODY>
</HTML>