Enforce.h File Reference

Enforcer class declarations and macros. More...

#include "FountainErrors.h"
#include <bamboo/define.h>
#include <string>
#include <sstream>
#include <stdexcept>

Go to the source code of this file.

Classes

struct  DefaultPredicate
 Default predicate tester for the Enforcer class, tests values against 0 using the ! operator. More...
struct  DefaultRaiser
 Default raiser for the Enforcer class, throws a FountainException using the message and locus as the descriptive text. More...
struct  ErrorPredicate
 Predicate tester for the Enforcer class, tests values against FAILURE using the equality operator. More...
class  Enforcer< Ref, P, R >
 This class is intended to be used as a runtime version of the assert macro. More...

Defines

#define STRINGIZE(expr)   STRINGIZE_HELPER(expr)
#define STRINGIZE_HELPER(expr)   #expr
#define ENFORCE(exp)   *MakeEnforcer<DefaultPredicate, DefaultRaiser>((exp), "Expression '" #exp "' failed in '" __FILE__ "', line: " STRINGIZE(__LINE__))
#define ENFORCE_SUCCESS(exp)   *MakeEnforcer<ErrorPredicate, DefaultRaiser>((exp), "Expression '" #exp "' failed in '" __FILE__ "', line: " STRINGIZE(__LINE__))

Functions

template<class P, class R, typename T>
Enforcer< const T &, P, R > MakeEnforcer (const T &t, const char *locus)
 Inline function to create an Enforcer object.
template<class P, class R, typename T>
Enforcer< T &, P, R > MakeEnforcer (T &t, const char *locus)
 Overloaded version of MakeEnforcer for non-const objects.


Detailed Description

Enforcer class declarations and macros.

This Code was originally written by Andrei Alexandrescu and Petru Marginean in their C/C++ Users Journal article "Enforcements", June 2003. I have modified it slightly to work with g++ 4.0 and Fountain concepts

Header
/afs/scl/project/cvsroot/fountain/source/common/Enforce.h,v 1.5 2006/02/19 21:59:36 samm Exp

Define Documentation

#define ENFORCE exp   )     *MakeEnforcer<DefaultPredicate, DefaultRaiser>((exp), "Expression '" #exp "' failed in '" __FILE__ "', line: " STRINGIZE(__LINE__))
 

Shorthand to create an Enforcer object and test the expression using the DefaultPredicate and DefaultRaiser

#define ENFORCE_SUCCESS exp   )     *MakeEnforcer<ErrorPredicate, DefaultRaiser>((exp), "Expression '" #exp "' failed in '" __FILE__ "', line: " STRINGIZE(__LINE__))
 

Shorthand to create an Enforcer object and test the expression using the ErrorPredicate and DefaultRaiser

#define STRINGIZE expr   )     STRINGIZE_HELPER(expr)
 

concatenates the expression to form a string

#define STRINGIZE_HELPER expr   )     #expr
 

this is C macro-land voodoo, I don't know what it does


Function Documentation

template<class P, class R, typename T>
Enforcer< const T &, P, R > MakeEnforcer const T &  t,
const char *  locus
[inline]
 

Inline function to create an Enforcer object.

Parameters:
[in] t Reference to a T object
[in] locus The locus (file and line number) where this function was called


Generated on Wed Mar 8 14:43:31 2006 for Fountain by  doxygen 1.4.6