blob: d84dd51de2b01f62f2283fbbaaaf01bfaec49f68 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<link href="../pool.css" rel="stylesheet" type="text/css">
<title>singleton - Singleton</title>
</head>
<body>
<img src="../../../../boost.png" width="276" height="86" alt="C++ Boost">
<h1 align="center">singleton - Singleton</h1>
<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 &amp; instance();
};
} // namespace pool
} // namespace details
</pre>
<h2>Semantics</h2>
<table border align="center" summary="">
<caption>
<em>Symbol Table</em>
</caption>
<tr>
<th>Symbol</th>
<th>Meaning</th>
</tr>
<tr>
<td class="code">T</td>
<td>Any class with a non-throwing default constructor and non-throwing
destructor</td>
</tr>
</table><br>
<table border align="center" summary="">
<caption>
<em>Requirements satisfied by <span class=
"code">singleton_default&lt;T&gt;</span></em>
</caption>
<tr>
<th>Expression</th>
<th>Return Type</th>
<th>Assertion/Note/Pre/Post-Condition</th>
</tr>
<tr>
<td class="code">singleton_default&lt;T&gt;::instance()</td>
<td class="code">T &amp;</td>
<td>Returns a reference to the singleton instance</td>
</tr>
</table>
<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><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
"../../../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
height="31" width="88"></a></p>
<p>Revised
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->05
December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38516" --></p>
<p><i>Copyright &copy; 2000, 2001 Stephen Cleary (scleary AT jerviswebb DOT
com)</i></p>
<p><i>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a>
or copy at <a href=
"http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
</body>
</html>