Click here to Skip to main content
15,886,110 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++: singleton.h Source File</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>
<h1>singleton.h</h1><div class="fragment"><pre class="fragment">00001 <span class="preprocessor">#ifndef TEMPLATE_PATTERNS_SINGLETON</span>
00002 <span class="preprocessor"></span><span class="preprocessor">#define TEMPLATE_PATTERNS_SINGLETON</span>
00003 <span class="preprocessor"></span>
00005 
00006 <span class="keyword">namespace </span>template_patterns
00007 {
00009 
<a name="l00015"></a><a class="code" href="classtemplate__patterns_1_1singleton.html">00015</a>   <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt; <span class="keyword">class </span><a class="code" href="classtemplate__patterns_1_1singleton.html">singleton</a>
00016   {
00017   <span class="keyword">public</span>:
00019 
<a name="l00021"></a><a class="code" href="classtemplate__patterns_1_1singleton.html#a0">00021</a>     T &amp; <a class="code" href="classtemplate__patterns_1_1singleton.html#a0">instance</a>()
00022     {
00023       <span class="keyword">static</span> T object;
00024       <span class="keywordflow">return</span> object;
00025     }
00026 
00028 
<a name="l00031"></a><a class="code" href="classtemplate__patterns_1_1singleton.html#a1">00031</a>     T &amp; <a class="code" href="classtemplate__patterns_1_1singleton.html#a1">operator* </a>()
00032     {
00033       <span class="keywordflow">return</span> <a class="code" href="classtemplate__patterns_1_1singleton.html#a0">instance</a>();
00034     }
00035 
00037 
<a name="l00040"></a><a class="code" href="classtemplate__patterns_1_1singleton.html#a2">00040</a>     <span class="keyword">const</span> &amp; <a class="code" href="classtemplate__patterns_1_1singleton.html#a1">operator* </a>()<span class="keyword"> const</span>
00041 <span class="keyword">    </span>{
00042       <span class="keywordflow">return</span> &amp;<a class="code" href="classtemplate__patterns_1_1singleton.html#a0">instance</a>();
00043     }
00044   };
00045 
00046 
00047 };
00048 
00049 
00050 <span class="preprocessor">#endif // TEMPLATE_PATTERNS_SINGLETON</span>
</pre></div><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