Click here to Skip to main content
15,886,110 members
Articles / Desktop Programming / MFC

Genetic Algorithm Library

Rate me:
Please Sign up or sign in to vote.
4.93/5 (175 votes)
7 Apr 2012GPL358 min read 437.8K   34.7K   555  
A framework for genetic algorithms
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Genetic Algorithm Library: Common::GaSmartStorage&lt; T &gt; Class Template Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.5 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
      <li><a href="hierarchy.html"><span>Class&nbsp;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="namespace_common.html">Common</a>::<a class="el" href="class_common_1_1_ga_smart_storage.html">GaSmartStorage</a>
  </div>
</div>
<div class="contents">
<h1>Common::GaSmartStorage&lt; T &gt; Class Template Reference</h1><!-- doxytag: class="Common::GaSmartStorage" --><code><a class="el" href="class_common_1_1_ga_smart_storage.html" title="GaSmartStorage template class provides reference-counting for smart pointers. GaSmartStorage...">GaSmartStorage</a></code> template class provides reference-counting for smart pointers. <code><a class="el" href="class_common_1_1_ga_smart_storage.html" title="GaSmartStorage template class provides reference-counting for smart pointers. GaSmartStorage...">GaSmartStorage</a></code> objects holds address of used data and number of references (smart pointers) which point to the data. Object of this class as well as the data are destroyed and memory is freed when there are no more references which points to the data. Arrays cannot be used with this class. This class has no built-in synchronizator, so <code>LOCK_OBJECT</code> and <code>LOCK_THIS_OBJECT</code> macros cannot be used with instances of this class, but all public method and operators are thread-safe.  
<a href="#_details">More...</a>
<p>
<code>#include &lt;source/SmartPtr.h&gt;</code>
<p>

<p>
<a href="class_common_1_1_ga_smart_storage-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">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_common_1_1_ga_smart_storage.html#adc5ed375938d824b1edd60495241a47">GaSmartStorage</a> (T *data)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Initializes object for counting references to data located at <code>data</code> address.  <a href="#adc5ed375938d824b1edd60495241a47"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_common_1_1_ga_smart_storage.html#52020cc0e6e92355eddc567caacecd3a">~GaSmartStorage</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Destructor is called when there are no more references which points to the data. Destructor frees memory used by the data.  <a href="#52020cc0e6e92355eddc567caacecd3a"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">T *GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_common_1_1_ga_smart_storage.html#53315ecfb3be73312c32a8747484869f">GetData</a> () const </td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method is thread-safe.  <a href="#53315ecfb3be73312c32a8747484869f"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_common_1_1_ga_smart_storage.html#7f8e58f49b20d58596416aef1bab76f5">GetCount</a> () const </td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method is thread-safe.  <a href="#7f8e58f49b20d58596416aef1bab76f5"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Static Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">static <a class="el" href="class_common_1_1_ga_smart_ptr.html">GaSmartPtr</a>&lt; T &gt; GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_common_1_1_ga_smart_storage.html#2998507ace4200c69b3ccc8fa3966122">MakeInstance</a> (T *data)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><code>MakeInstance</code> makes new reference-counting object for data at address data. This method is thread-safe.  <a href="#2998507ace4200c69b3ccc8fa3966122"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">static <a class="el" href="class_common_1_1_ga_smart_storage.html">GaSmartStorage</a>&lt; T &gt; *GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_common_1_1_ga_smart_storage.html#50c3e3b1aed2c4dc23c00b80e6927259">MakeInstanceDirect</a> (T *data)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><code>MakeInstance</code> makes new reference-counting object for data at address data. This method is thread-safe.  <a href="#50c3e3b1aed2c4dc23c00b80e6927259"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">static int GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_common_1_1_ga_smart_storage.html#a47ac4ad4bb10f4689771d6d1a8c240d">AddReference</a> (<a class="el" href="class_common_1_1_ga_smart_storage.html">GaSmartStorage</a>&lt; T &gt; *location)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method increments number of references to the data. <code>AddReference</code> method is called when smart pointer is set to point to the location. This method is thread-safe.  <a href="#a47ac4ad4bb10f4689771d6d1a8c240d"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">static int GACALL&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_common_1_1_ga_smart_storage.html#dd0362e251c1e8cdbc504d9082881886">RemoveReference</a> (<a class="el" href="class_common_1_1_ga_smart_storage.html">GaSmartStorage</a>&lt; T &gt; *location)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method decrements number of references, if that number reaches 0, the data is destroyed and memory is freed. <code>RemoveReference</code> method is called when smart pointers are destructed or when set to point to new location. This method is thread-safe.  <a href="#dd0362e251c1e8cdbc504d9082881886"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Private Attributes</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_common_1_1_ga_smart_storage.html#e12502cecc40b9f90c2ccd8ef43e8c73">_count</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Holds number of references (smart pointers) to data guarded by this object.  <a href="#e12502cecc40b9f90c2ccd8ef43e8c73"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">T *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_common_1_1_ga_smart_storage.html#e48d4280760f5b6a4ea74ba044046011">_data</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Pointer to user data.  <a href="#e48d4280760f5b6a4ea74ba044046011"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Friends</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">class&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_common_1_1_ga_smart_storage.html#4df342cdacccec59296ee568b61a8845">GaSmartPtr&lt; T &gt;</a></td></tr>

</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
<h3>template&lt;typename T&gt;<br>
 class Common::GaSmartStorage&lt; T &gt;</h3>

<code><a class="el" href="class_common_1_1_ga_smart_storage.html" title="GaSmartStorage template class provides reference-counting for smart pointers. GaSmartStorage...">GaSmartStorage</a></code> template class provides reference-counting for smart pointers. <code><a class="el" href="class_common_1_1_ga_smart_storage.html" title="GaSmartStorage template class provides reference-counting for smart pointers. GaSmartStorage...">GaSmartStorage</a></code> objects holds address of used data and number of references (smart pointers) which point to the data. Object of this class as well as the data are destroyed and memory is freed when there are no more references which points to the data. Arrays cannot be used with this class. This class has no built-in synchronizator, so <code>LOCK_OBJECT</code> and <code>LOCK_THIS_OBJECT</code> macros cannot be used with instances of this class, but all public method and operators are thread-safe. 
<p>
<hr><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" name="adc5ed375938d824b1edd60495241a47"></a><!-- doxytag: member="Common::GaSmartStorage::GaSmartStorage" ref="adc5ed375938d824b1edd60495241a47" args="(T *data)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_common_1_1_ga_smart_storage.html">Common::GaSmartStorage</a>&lt; T &gt;::<a class="el" href="class_common_1_1_ga_smart_storage.html">GaSmartStorage</a>           </td>
          <td>(</td>
          <td class="paramtype">T *&nbsp;</td>
          <td class="paramname"> <em>data</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Initializes object for counting references to data located at <code>data</code> address. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>data</em>&nbsp;</td><td>pointer to user data. <code>data</code> cannot be an array.</td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="52020cc0e6e92355eddc567caacecd3a"></a><!-- doxytag: member="Common::GaSmartStorage::~GaSmartStorage" ref="52020cc0e6e92355eddc567caacecd3a" args="()" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_common_1_1_ga_smart_storage.html">Common::GaSmartStorage</a>&lt; T &gt;::~<a class="el" href="class_common_1_1_ga_smart_storage.html">GaSmartStorage</a>           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Destructor is called when there are no more references which points to the data. Destructor frees memory used by the data. 
<p>

</div>
</div><p>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="2998507ace4200c69b3ccc8fa3966122"></a><!-- doxytag: member="Common::GaSmartStorage::MakeInstance" ref="2998507ace4200c69b3ccc8fa3966122" args="(T *data)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">static <a class="el" href="class_common_1_1_ga_smart_ptr.html">GaSmartPtr</a>&lt;T&gt; GACALL <a class="el" href="class_common_1_1_ga_smart_storage.html">Common::GaSmartStorage</a>&lt; T &gt;::MakeInstance           </td>
          <td>(</td>
          <td class="paramtype">T *&nbsp;</td>
          <td class="paramname"> <em>data</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline, static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
<code>MakeInstance</code> makes new reference-counting object for data at address data. This method is thread-safe. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>data</em>&nbsp;</td><td>pointer to data. <code>data</code> cannot be an array.</td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Method returns smart pointer which points to data and use newly created object for reference-counting.</dd></dl>

</div>
</div><p>
<a class="anchor" name="50c3e3b1aed2c4dc23c00b80e6927259"></a><!-- doxytag: member="Common::GaSmartStorage::MakeInstanceDirect" ref="50c3e3b1aed2c4dc23c00b80e6927259" args="(T *data)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">static <a class="el" href="class_common_1_1_ga_smart_storage.html">GaSmartStorage</a>&lt;T&gt;* GACALL <a class="el" href="class_common_1_1_ga_smart_storage.html">Common::GaSmartStorage</a>&lt; T &gt;::MakeInstanceDirect           </td>
          <td>(</td>
          <td class="paramtype">T *&nbsp;</td>
          <td class="paramname"> <em>data</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline, static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
<code>MakeInstance</code> makes new reference-counting object for data at address data. This method is thread-safe. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>data</em>&nbsp;</td><td>pointer to data. <code>data</code> cannot be an array.</td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Method returns reference to newly created object for reference-counting.</dd></dl>

</div>
</div><p>
<a class="anchor" name="a47ac4ad4bb10f4689771d6d1a8c240d"></a><!-- doxytag: member="Common::GaSmartStorage::AddReference" ref="a47ac4ad4bb10f4689771d6d1a8c240d" args="(GaSmartStorage&lt; T &gt; *location)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">static int GACALL <a class="el" href="class_common_1_1_ga_smart_storage.html">Common::GaSmartStorage</a>&lt; T &gt;::AddReference           </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="class_common_1_1_ga_smart_storage.html">GaSmartStorage</a>&lt; T &gt; *&nbsp;</td>
          <td class="paramname"> <em>location</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline, static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This method increments number of references to the data. <code>AddReference</code> method is called when smart pointer is set to point to the location. This method is thread-safe. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>location</em>&nbsp;</td><td>pointer to location which is incremented.</td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Method returns new number of references which still points to the data.</dd></dl>

</div>
</div><p>
<a class="anchor" name="dd0362e251c1e8cdbc504d9082881886"></a><!-- doxytag: member="Common::GaSmartStorage::RemoveReference" ref="dd0362e251c1e8cdbc504d9082881886" args="(GaSmartStorage&lt; T &gt; *location)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">static int GACALL <a class="el" href="class_common_1_1_ga_smart_storage.html">Common::GaSmartStorage</a>&lt; T &gt;::RemoveReference           </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="class_common_1_1_ga_smart_storage.html">GaSmartStorage</a>&lt; T &gt; *&nbsp;</td>
          <td class="paramname"> <em>location</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline, static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This method decrements number of references, if that number reaches 0, the data is destroyed and memory is freed. <code>RemoveReference</code> method is called when smart pointers are destructed or when set to point to new location. This method is thread-safe. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>location</em>&nbsp;</td><td>pointer to location which is decremented.</td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Method returns new number of references which still points to the data.</dd></dl>

</div>
</div><p>
<a class="anchor" name="53315ecfb3be73312c32a8747484869f"></a><!-- doxytag: member="Common::GaSmartStorage::GetData" ref="53315ecfb3be73312c32a8747484869f" args="() const " -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">T* GACALL <a class="el" href="class_common_1_1_ga_smart_storage.html">Common::GaSmartStorage</a>&lt; T &gt;::GetData           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"> const<code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This method is thread-safe. 
<p>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Method returns pointer to user data.</dd></dl>

</div>
</div><p>
<a class="anchor" name="7f8e58f49b20d58596416aef1bab76f5"></a><!-- doxytag: member="Common::GaSmartStorage::GetCount" ref="7f8e58f49b20d58596416aef1bab76f5" args="() const " -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">int GACALL <a class="el" href="class_common_1_1_ga_smart_storage.html">Common::GaSmartStorage</a>&lt; T &gt;::GetCount           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"> const<code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This method is thread-safe. 
<p>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Method returns number of references (smart pointers) which points to this location.</dd></dl>

</div>
</div><p>
<hr><h2>Friends And Related Function Documentation</h2>
<a class="anchor" name="4df342cdacccec59296ee568b61a8845"></a><!-- doxytag: member="Common::GaSmartStorage::GaSmartPtr&lt; T &gt;" ref="4df342cdacccec59296ee568b61a8845" args="" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">friend class <a class="el" href="class_common_1_1_ga_smart_ptr.html">GaSmartPtr</a>&lt; T &gt;<code> [friend]</code>          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
<hr><h2>Member Data Documentation</h2>
<a class="anchor" name="e12502cecc40b9f90c2ccd8ef43e8c73"></a><!-- doxytag: member="Common::GaSmartStorage::_count" ref="e12502cecc40b9f90c2ccd8ef43e8c73" args="" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">int <a class="el" href="class_common_1_1_ga_smart_storage.html">Common::GaSmartStorage</a>&lt; T &gt;::<a class="el" href="class_common_1_1_ga_smart_storage.html#e12502cecc40b9f90c2ccd8ef43e8c73">_count</a><code> [mutable, private]</code>          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Holds number of references (smart pointers) to data guarded by this object. 
<p>

</div>
</div><p>
<a class="anchor" name="e48d4280760f5b6a4ea74ba044046011"></a><!-- doxytag: member="Common::GaSmartStorage::_data" ref="e48d4280760f5b6a4ea74ba044046011" args="" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">T* <a class="el" href="class_common_1_1_ga_smart_storage.html">Common::GaSmartStorage</a>&lt; T &gt;::<a class="el" href="class_common_1_1_ga_smart_storage.html#e48d4280760f5b6a4ea74ba044046011">_data</a><code> [private]</code>          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Pointer to user data. 
<p>

</div>
</div><p>
<hr>The documentation for this class was generated from the following file:<ul>
<li>source/<a class="el" href="_smart_ptr_8h.html">SmartPtr.h</a></ul>
</div>
<br/><a href="http://www.coolsoft-sd.com/ProductVersion.aspx?vid=9">Genetic Algorithm Library</a><br/><a href="http://www.coolsoft-sd.com/">Coolsoft Software Development</a>
</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 GNU General Public License (GPLv3)


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

Comments and Discussions