Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > bfea28f33e7373c31a33dc7387b2a0be > files > 37

loki-lib-doc-0.1.7-2.fc12.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Loki: Loki::ContractChecker&lt; Host, ExceptionPolicy &gt; Class Template Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</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>
    <li>
      <form action="search.php" method="get">
        <table cellspacing="0" cellpadding="0" border="0">
          <tr>
            <td><label>&nbsp;<u>S</u>earch&nbsp;for&nbsp;</label></td>
            <td><input type="text" name="query" value="" size="20" accesskey="s"/></td>
          </tr>
        </table>
      </form>
    </li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
      <li><a href="classes.html"><span>Class&nbsp;Index</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="a00192.html">Loki</a>::<a class="el" href="a00029.html">ContractChecker</a>
  </div>
</div>
<div class="contents">
<h1>Loki::ContractChecker&lt; Host, ExceptionPolicy &gt; Class Template Reference</h1><!-- doxytag: class="Loki::ContractChecker" --><code>#include &lt;Checker.h&gt;</code>
<p>

<p>
<a href="a00301.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Types</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="041784de821e2ca4fa00aef169acc18b"></a><!-- doxytag: member="Loki::ContractChecker::Validator" ref="041784de821e2ca4fa00aef169acc18b" args=")(void) const " -->
typedef bool(Host::*&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00029.html#041784de821e2ca4fa00aef169acc18b">Validator</a> )(void) const </td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Signature for the validation function. <br></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="a00029.html#47a88a788d4099204e3a49593e4ff2a2">ContractChecker</a> (const Host *host, <a class="el" href="a00029.html#041784de821e2ca4fa00aef169acc18b">Validator</a> validator, <a class="el" href="a00029.html#041784de821e2ca4fa00aef169acc18b">Validator</a> pre=0, <a class="el" href="a00029.html#041784de821e2ca4fa00aef169acc18b">Validator</a> post=0)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00029.html#ac668398deabba5291b9025b4ac4eafd">~ContractChecker</a> (void)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00029.html#812565f4dccc8d50be8f7b9c91841a51">Check</a> (void) const </td></tr>

</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
<h3>template&lt;class Host, template&lt; class &gt; class ExceptionPolicy&gt;<br>
 class Loki::ContractChecker&lt; Host, ExceptionPolicy &gt;</h3>

This class determines if a function violated any class invariant, but it also determines if a function fulfills its contract with client code. In the "Design by Contract" paradigm, each function has certain pre-conditions and post-conditions which may differ from the class invariants. This asserts if a check for an invariant fails as well as if any pre- or post-condition fails. It also demonstrate which exception safety level a function provides.<p>
<dl class="user" compact><dt><b>Usage</b></dt><dd><ol type=1>
<li>Implement a function that checks each class invariant. The function must have the signature similar to the Validator type. Something like: "bool Host::IsValid( void ) const;"<ul>
<li>The function should return true if everything is okay, but false if something is wrong.</li><li>Or it could assert if anything is wrong.</li><li>Ideally, it should be private.</li></ul>
</li><li>Implement similar functions to check for pre-conditions and post-conditions. Functions which verify pre-conditions and post-conditions do not need to check all class invariants, just conditions specific to certain public functions in the host class.</li><li>Declare some typedef's inside the class declaration like these. Make one typedef for each exception policy you use. I typedef'ed the <a class="el" href="a00020.html">CheckForNothing</a> policy as CheckInvariants because even if a function can't provide either the no-throw nor the no-change policies, it should still make sure the object remains in a valid state.<ul>
<li>typedef Loki::ContractChecker&lt; Host, ::Loki::CheckForNoThrow  &gt; <a class="el" href="a00021.html">CheckForNoThrow</a>;</li><li>typedef Loki::ContractChecker&lt; Host, ::Loki::CheckForNoChange &gt; <a class="el" href="a00018.html">CheckForNoChange</a>;</li><li>typedef Loki::ContractChecker&lt; Host, ::Loki::CheckForEquality &gt; <a class="el" href="a00017.html">CheckForEquality</a>;</li><li>typedef Loki::ContractChecker&lt; Host, ::Loki::CheckForNothing  &gt; CheckInvariants;</li></ul>
</li><li>Construct a checker near the top of each member function - except in the validator member function. Pass the this pointer and the address of your validator function into the checker's constructor. You may also pass in pointers to function which check pre- and post-conditions.<ul>
<li>If the function never throws, then use the <a class="el" href="a00021.html">CheckForNoThrow</a> policy.</li><li>If the function never changes any data members, then use <a class="el" href="a00017.html">CheckForEquality</a> policy.</li><li>If the function's normal execution flow changes data, but must make sure data remains unchanged when any exceptions occur, then use the <a class="el" href="a00018.html">CheckForNoChange</a> policy.</li><li>Otherwise use the CheckInvariants policy.</li></ul>
</li><li>Recompile a debug version of your program, run the program and all the unit tests, and look for which assertions failed. </li></ol>
</dd></dl>
<hr><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" name="47a88a788d4099204e3a49593e4ff2a2"></a><!-- doxytag: member="Loki::ContractChecker::ContractChecker" ref="47a88a788d4099204e3a49593e4ff2a2" args="(const Host *host, Validator validator, Validator pre=0, Validator post=0)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;class Host , template&lt; class &gt; class ExceptionPolicy&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="a00029.html">Loki::ContractChecker</a>&lt; Host, ExceptionPolicy &gt;::<a class="el" href="a00029.html">ContractChecker</a>           </td>
          <td>(</td>
          <td class="paramtype">const Host *&nbsp;</td>
          <td class="paramname"> <em>host</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="a00029.html#041784de821e2ca4fa00aef169acc18b">Validator</a>&nbsp;</td>
          <td class="paramname"> <em>validator</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="a00029.html#041784de821e2ca4fa00aef169acc18b">Validator</a>&nbsp;</td>
          <td class="paramname"> <em>pre</em> = <code>0</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="a00029.html#041784de821e2ca4fa00aef169acc18b">Validator</a>&nbsp;</td>
          <td class="paramname"> <em>post</em> = <code>0</code></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
The constructor makes sure the host is valid at the time the checker was created, thus insuring the host object was not corrupt from the start. <dl class="user" compact><dt><b>host Pointer to host object.</b></dt><dd></dd></dl>
<dl class="user" compact><dt><b>validator Pointer to function that checks class invariants.</b></dt><dd></dd></dl>
<dl class="user" compact><dt><b>pre Optional pointer to function that checks pre-conditions.</b></dt><dd></dd></dl>
<dl class="user" compact><dt><b>post Optional pointer to function that checks post-conditions.</b></dt><dd></dd></dl>

<p>References <a class="el" href="a00232.html#l00328">Loki::ContractChecker&lt; Host, ExceptionPolicy &gt;::Check()</a>.</p>

<p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dynsection">
</div>

</div>
</div><p>
<a class="anchor" name="ac668398deabba5291b9025b4ac4eafd"></a><!-- doxytag: member="Loki::ContractChecker::~ContractChecker" ref="ac668398deabba5291b9025b4ac4eafd" args="(void)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;class Host , template&lt; class &gt; class ExceptionPolicy&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="a00029.html">Loki::ContractChecker</a>&lt; Host, ExceptionPolicy &gt;::~<a class="el" href="a00029.html">ContractChecker</a>           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
The destructor checks if any Host invariants failed, and then calls the ExceptionPolicy's Check function to determine what to do in case of an exception. 
<p>References <a class="el" href="a00232.html#l00328">Loki::ContractChecker&lt; Host, ExceptionPolicy &gt;::Check()</a>.</p>

<p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dynsection">
</div>

</div>
</div><p>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="812565f4dccc8d50be8f7b9c91841a51"></a><!-- doxytag: member="Loki::ContractChecker::Check" ref="812565f4dccc8d50be8f7b9c91841a51" args="(void) const " -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;class Host , template&lt; class &gt; class ExceptionPolicy&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">bool <a class="el" href="a00029.html">Loki::ContractChecker</a>&lt; Host, ExceptionPolicy &gt;::Check           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td> const<code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
This first checks the invariants for <a class="el" href="a00029.html">ContractChecker</a>, and then calls the validator function for the host to make sure no class invariants were broken by the host within the Host's member function body. The host member function can call Check directly to verify the object remains valid at any time. This does not care if the pre- and post-condition validator pointers are null since a host class may pass in NULL pointers for either to indicate the pre-conditions or post-conditions are the same as the overall class invariants. 
<p>Referenced by <a class="el" href="a00232.html#l00294">Loki::ContractChecker&lt; Host, ExceptionPolicy &gt;::ContractChecker()</a>, and <a class="el" href="a00232.html#l00311">Loki::ContractChecker&lt; Host, ExceptionPolicy &gt;::~ContractChecker()</a>.</p>

</div>
</div><p>
<hr>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="a00147.html">Checker.h</a></ul>
</div>
<hr size="1"><address style="text-align: right;"><small>Generated on Thu Jan 29 18:51:42 2009 for Loki by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
</body>
</html>