Click here to Skip to main content
15,884,739 members
Articles / Programming Languages / C++

Templates for Design Patterns

Rate me:
Please Sign up or sign in to vote.
2.47/5 (6 votes)
31 Jan 2006CPOL4 min read 54.3K   131   28  
A fly weight implementation of a C++ template library for applying Design Patterns easily in any application.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Templated design pattern implementation for C++: template_patterns::singleton&lt; T &gt; Class Template Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.2 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a></div>
<div class="nav">
<a class="el" href="namespacetemplate__patterns.html">template_patterns</a>::<a class="el" href="classtemplate__patterns_1_1singleton.html">singleton</a></div>
<h1>template_patterns::singleton&lt; T &gt; Class Template Reference</h1>Singleton template class.  
<a href="#_details">More...</a>
<p>
<code>#include &lt;<a class="el" href="singleton_8h-source.html">singleton.h</a>&gt;</code>
<p>
<a href="classtemplate__patterns_1_1singleton-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">T &amp;&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtemplate__patterns_1_1singleton.html#a0">instance</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Retrieve the instance.  <a href="#a0"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">T &amp;&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtemplate__patterns_1_1singleton.html#a1">operator *</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Retrieve the instance.  <a href="#a1"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">const &amp;&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtemplate__patterns_1_1singleton.html#a2">operator *</a> () const </td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Retrieve the const instance.  <a href="#a2"></a><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
<h3>template&lt;class T&gt;<br>
 class template_patterns::singleton&lt; T &gt;</h3>

Singleton template class. 
<p>
The singleton creates a singleton instance from a given class, T, and allows it to be reached globally and uniquely within the application. Say you have class C and want to turn it into a singleton, simply add the following code: <em>typedef singleton&lt;C&gt; c_singleton;</em>. Whenever you need to hook up with the singleton just write <em>c_singleton.instance().my_function(params);</em>. <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>T</em>&nbsp;</td><td>class to allow singleton behaviour </td></tr>
  </table>
</dl>

<p>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="a0" doxytag="template_patterns::singleton::instance"></a><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="mdPrefix" colspan="4">
template&lt;class T&gt; </td>
        </tr>
        <tr>
          <td class="md" nowrap valign="top">T&amp; <a class="el" href="classtemplate__patterns_1_1singleton.html">template_patterns::singleton</a>&lt; T &gt;::instance           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="mdname1" valign="top" nowrap>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap><code> [inline]</code></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Retrieve the instance. 
<p>
<dl compact><dt><b>Returns:</b></dt><dd>the instance of type T </dd></dl>
    </td>
  </tr>
</table>
<a class="anchor" name="a2" doxytag="template_patterns::singleton::operator *"></a><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="mdPrefix" colspan="4">
template&lt;class T&gt; </td>
        </tr>
        <tr>
          <td class="md" nowrap valign="top">const&amp; <a class="el" href="classtemplate__patterns_1_1singleton.html">template_patterns::singleton</a>&lt; T &gt;::operator *           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="mdname1" valign="top" nowrap>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap> const<code> [inline]</code></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Retrieve the const instance. 
<p>
<dl compact><dt><b>See also:</b></dt><dd><a class="el" href="classtemplate__patterns_1_1singleton.html#a0">instance</a> </dd></dl>
<dl compact><dt><b>Returns:</b></dt><dd>the const instance of type T </dd></dl>
    </td>
  </tr>
</table>
<a class="anchor" name="a1" doxytag="template_patterns::singleton::operator *"></a><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
  <tr>
    <td class="mdRow">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="mdPrefix" colspan="4">
template&lt;class T&gt; </td>
        </tr>
        <tr>
          <td class="md" nowrap valign="top">T&amp; <a class="el" href="classtemplate__patterns_1_1singleton.html">template_patterns::singleton</a>&lt; T &gt;::operator *           </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="mdname1" valign="top" nowrap>          </td>
          <td class="md" valign="top">&nbsp;)&nbsp;</td>
          <td class="md" nowrap><code> [inline]</code></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Retrieve the instance. 
<p>
<dl compact><dt><b>See also:</b></dt><dd><a class="el" href="classtemplate__patterns_1_1singleton.html#a0">instance</a> </dd></dl>
<dl compact><dt><b>Returns:</b></dt><dd>the instance of type T </dd></dl>
    </td>
  </tr>
</table>
<hr>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="singleton_8h-source.html">singleton.h</a></ul>
<hr size="1"><address style="align: right;"><small>Generated on Wed Feb 1 08:22:32 2006 for Templated design pattern implementation for C++ by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Denmark Denmark
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions