Loki::StaticChecker< ExceptionPolicy > Class Template Reference

#include <Checker.h>

List of all members.

Public Types

typedef bool(* Validator )(void)
 Signature for the validation function.

Public Member Functions

 StaticChecker (Validator validator, Validator pre=0, Validator post=0)
 ~StaticChecker (void)
bool Check (void) const


Detailed Description

template<class ExceptionPolicy>
class Loki::StaticChecker< ExceptionPolicy >

This class checks if a function provides the no-throw exception safety level and if the function violated any invariants. Invariants for stand-alone and static functions act as pre-conditions and post-conditions.

Usage
  1. Implement a function that checks the invariants associated with a function, or with the static data for a class. The function must have the signature similar to the Validator type. Something like: "static bool Host::StaticIsValid( void );" or "bool IsOkay( void );"
    • The function should return true if everything is okay, but false if something is wrong.
    • Or it could assert if anything is wrong.
  2. If the checker is for static functions within a class, declare typedef's inside the class declaration like these. Make one typedef for each policy you use. I typedef'ed the CheckForNothing policy as CheckInvariants because even if a function can't provide the no-throw guarantee, it should still make sure that static data remains in a valid state.
    • typedef Loki::StaticChecker< ::Loki::CheckForNoThrow > CheckStaticForNoThrow;
    • typedef Loki::StaticChecker< ::Loki::CheckForNothing > CheckStaticInvariants;
  3. Construct a checker near the top of each member function - except in the validator member function. Pass the address of your validator function into the checker's constructor.
    • If the function never throws, then use the CheckForNoThrow policy.
    • Otherwise use the CheckInvariants policy.
  4. Recompile a debug version of your program, run it, and see if an assertion fails.

Constructor & Destructor Documentation

template<class ExceptionPolicy >
Loki::StaticChecker< ExceptionPolicy >::StaticChecker ( Validator  validator,
Validator  pre = 0,
Validator  post = 0 
) [inline, explicit]

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.

validator Pointer to function that checks class invariants.
pre Optional pointer to function that checks pre-conditions.
post Optional pointer to function that checks post-conditions.

References Loki::StaticChecker< ExceptionPolicy >::Check().

Here is the call graph for this function:

template<class ExceptionPolicy >
Loki::StaticChecker< ExceptionPolicy >::~StaticChecker ( void   )  [inline]

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.

References Loki::StaticChecker< ExceptionPolicy >::Check().

Here is the call graph for this function:


Member Function Documentation

template<class ExceptionPolicy >
bool Loki::StaticChecker< ExceptionPolicy >::Check ( void   )  const [inline]

This first checks its own invariants, and then calls the validator function to make sure no invariants were broken by the function which created this checker. That function can call Check directly to verify the data 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.

Referenced by Loki::StaticChecker< ExceptionPolicy >::StaticChecker(), and Loki::StaticChecker< ExceptionPolicy >::~StaticChecker().


The documentation for this class was generated from the following file:

Generated on Thu Jan 29 18:51:42 2009 for Loki by  doxygen 1.5.8